Skip to content

Commit

Permalink
fix: Check for network state on resume. (#95)
Browse files Browse the repository at this point in the history
Description in the comments inside the changes.
  • Loading branch information
kinyoklion committed Jan 25, 2024
1 parent 588ae01 commit c1cb489
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/flutter_client_sdk/lib/src/flutter_state_detector.dart
Expand Up @@ -74,6 +74,21 @@ final class FlutterStateDetector implements StateDetector {
case AppLifecycleState.detached:
break;
case AppLifecycleState.resumed:
// From connectivity_plus:
//
// "Connectivity changes are no longer communicated to Android apps in
// the background starting with Android O (8.0). You should always check
// for connectivity status when your app is resumed. The broadcast is
// only useful when your application is in the foreground."
// https://github.com/fluttercommunity/plus_plugins/tree/main/packages/connectivity_plus/connectivity_plus
//
// So, when we detect an that we have been resumed, we query the current
// connectivity state and emit an event.
// There is some excess checking here, especially during app load, but
// our reaction to the state depends on it being different, so reporting
// the same state, in excess, has minimal impact and is better than
// missing an active state transition.
Connectivity().checkConnectivity().then(_setConnectivity);
_applicationStateController.sink.add(ApplicationState.foreground);
case AppLifecycleState.inactive:
break;
Expand Down

0 comments on commit c1cb489

Please sign in to comment.