didChangeAppLifecycleState method
Called when the system puts the app in the background or returns the app to the foreground.
An example of implementing this method is provided in the class-level documentation for the WidgetsBindingObserver class.
This method exposes notifications from SystemChannels.lifecycle.
See also:
- AppLifecycleListener, an alternative API for responding to application lifecycle changes.
Implementation
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
switch (state) {
case AppLifecycleState.resumed:
_lifecycleState = LifecycleState.resumed;
_notifyLifecycleChange(lifecycleState);
onResumed();
break;
case AppLifecycleState.inactive:
_lifecycleState = LifecycleState.inactive;
_notifyLifecycleChange(lifecycleState);
onInactive();
break;
case AppLifecycleState
.paused: //AppLifecycleState.paused is used as stopped state because deactivate() works more as a pause for lifecycle
_lifecycleState = LifecycleState.stopped;
_notifyLifecycleChange(lifecycleState);
onStopped();
break;
case AppLifecycleState.detached:
_lifecycleState = LifecycleState.detached;
_notifyLifecycleChange(lifecycleState);
onDetached();
break;
default:
break;
}
}