didChangeAppLifecycleState method
detached -> resumed -| ^ v | inactive paused <- hidden <--|
Implementation
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
final AppLifecycleState? previousState = _lifecycleState;
if (state == previousState) {
// Transitioning to the same state twice doesn't produce any notifications (but also won't actually occur).
return;
}
_lifecycleState = state;
switch (state) {
case AppLifecycleState.resumed:
onResumed();
break;
case AppLifecycleState.inactive:
if (previousState == AppLifecycleState.hidden) {
onShow();
} else if (previousState == null ||
previousState == AppLifecycleState.resumed) {
onInactive();
}
break;
case AppLifecycleState.hidden:
if (previousState == AppLifecycleState.paused) {
onRestart();
} else if (previousState == null ||
previousState == AppLifecycleState.inactive) {
onHidden();
}
break;
case AppLifecycleState.paused:
if (previousState == null ||
previousState == AppLifecycleState.hidden) {
onPaused();
}
break;
case AppLifecycleState.detached:
onDetached();
break;
default:
}
// At this point, it can't be null anymore.
if (_lifecycleState != null) {
onStateChange(_lifecycleState!);
}
}