Skip to content

Commit

Permalink
hamed/minor_refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
hamed-rezaee committed Jun 28, 2023
1 parent 11eb764 commit 178b471
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions lib/state/connection/connection_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ class ConnectionCubit extends Cubit<ConnectionState> {
onError: (String error) => emit(ConnectionErrorState(error)),
);

_handleConnectionStatus(_api);
await _handleConnectionStatus(_api);
} on Exception catch (e) {
emit(ConnectionErrorState('$e'));
}
}

void _handleConnectionStatus(BaseAPI api) {
_cancelConnectionStatusSubscription();
Future<void> _handleConnectionStatus(BaseAPI api) async {
await _cancelConnectionStatusSubscription();

_connectionStatusSubscription = api.connectionStatus.listen(
(APIStatus status) {
Expand All @@ -101,15 +101,12 @@ class ConnectionCubit extends Cubit<ConnectionState> {
);
}

void _cancelConnectionStatusSubscription() {
if (_connectionStatusSubscription != null) {
_connectionStatusSubscription!.cancel();
}
}
Future<void> _cancelConnectionStatusSubscription() async =>
_connectionStatusSubscription?.cancel();

@override
Future<void> close() {
_cancelConnectionStatusSubscription();
Future<void> close() async {
await _cancelConnectionStatusSubscription();

return super.close();
}
Expand Down

0 comments on commit 178b471

Please sign in to comment.