Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(flutter_deriv_api): deprecating_connection_state_class #295

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions example/lib/sample_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import 'package:flutter_deriv_api/services/connection/api_manager/connection_information.dart';
import 'package:flutter_deriv_api/state/connection/connection_cubit.dart'
as api_connection;
import 'package:flutter_deriv_api/state/connection/connection_cubit.dart';
import 'package:flutter_deriv_api_example/pages/main_page.dart';

/// Sample App main widget
Expand All @@ -13,13 +12,13 @@ class SampleApp extends StatefulWidget {
}

class _SampleAppState extends State<SampleApp> {
late api_connection.ConnectionCubit _connectionCubit;
late ConnectionCubit _connectionCubit;

@override
void initState() {
super.initState();

_connectionCubit = api_connection.ConnectionCubit(
_connectionCubit = ConnectionCubit(
ConnectionInformation(
appId: '1089',
brand: 'binary',
Expand All @@ -39,28 +38,27 @@ class _SampleAppState extends State<SampleApp> {
@override
Widget build(BuildContext context) => MultiBlocProvider(
providers: <BlocProvider<dynamic>>[
BlocProvider<api_connection.ConnectionCubit>.value(
BlocProvider<ConnectionCubit>.value(
value: _connectionCubit,
),
],
child: Scaffold(
appBar: AppBar(
title: const Text('API Sample App'),
),
body: BlocBuilder<api_connection.ConnectionCubit,
api_connection.ConnectionState>(
body: BlocBuilder<ConnectionCubit, DerivConnectionState>(
builder: (
BuildContext context,
api_connection.ConnectionState state,
DerivConnectionState state,
) {
if (state is api_connection.ConnectionConnectedState) {
if (state is ConnectionConnectedState) {
return MainPage();
} else if (state is api_connection.ConnectionInitialState ||
state is api_connection.ConnectionConnectingState) {
} else if (state is ConnectionInitialState ||
state is ConnectionConnectingState) {
return _buildCenterText('Connecting...');
} else if (state is api_connection.ConnectionErrorState) {
} else if (state is ConnectionErrorState) {
return _buildCenterText('Connection Error\n${state.error}');
} else if (state is api_connection.ConnectionDisconnectedState) {
} else if (state is ConnectionDisconnectedState) {
return _buildCenterText(
'Connection is down, trying to reconnect...',
);
Expand Down
2 changes: 1 addition & 1 deletion lib/state/connection/connection_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import 'package:deriv_dependency_injector/dependency_injector.dart';
part 'connection_state.dart';

/// Bringing [ConnectionCubit] to flutter-deriv-api to simplify the usage of api.
class ConnectionCubit extends Cubit<ConnectionState> {
class ConnectionCubit extends Cubit<DerivConnectionState> {
/// Initializes [ConnectionCubit].
ConnectionCubit(
ConnectionInformation connectionInformation, {
Expand Down
23 changes: 18 additions & 5 deletions lib/state/connection/connection_state.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
part of 'connection_cubit.dart';

/// Connection states base class.
@Deprecated('Use DerivConnectionState instead')
abstract class ConnectionState extends Equatable {
/// Initializes [ConnectionState].
const ConnectionState();
Expand All @@ -12,26 +13,38 @@ abstract class ConnectionState extends Equatable {
List<Object> get props => <Object>[];
}

/// Connection states base class.
abstract class DerivConnectionState extends ConnectionState {
/// Initializes [DerivConnectionState].
const DerivConnectionState();

@override
String toString() => 'DerivConnectionState: $runtimeType';

@override
List<Object> get props => <Object>[];
}

/// Connection initial state.
class ConnectionInitialState extends ConnectionState {
class ConnectionInitialState extends DerivConnectionState {
/// Initializes [ConnectionInitialState].
const ConnectionInitialState();
}

/// Shows that we are in the process of connecting.
class ConnectionConnectingState extends ConnectionState {
class ConnectionConnectingState extends DerivConnectionState {
/// Initializes [ConnectionConnectingState].
const ConnectionConnectingState();
}

/// Connection connected state.
class ConnectionConnectedState extends ConnectionState {
class ConnectionConnectedState extends DerivConnectionState {
/// Initializes [ConnectionConnectedState].
const ConnectionConnectedState();
}

/// Connection disconnected state.
class ConnectionDisconnectedState extends ConnectionState {
class ConnectionDisconnectedState extends DerivConnectionState {
/// Initializes [ConnectionDisconnectedState].
const ConnectionDisconnectedState({this.isChangingLanguage = false});

Expand All @@ -40,7 +53,7 @@ class ConnectionDisconnectedState extends ConnectionState {
}

/// Connection error state.
class ConnectionErrorState extends ConnectionState {
class ConnectionErrorState extends DerivConnectionState {
/// Initializes with the this [error] message.
const ConnectionErrorState(this.error);

Expand Down
Loading