In my application, I want to show the user local auth screen to identify itself after closing or putting the application in inactive mode.
Possible AppLifecycleState are:
enum AppLifecycleState {
detached,
resumed,
inactive,
hidden,
pause,
}
I've used local_auth package and with WidgetBindingObserver to listen to app states.
Now I have a method that returns a boolean to whether to show the local_auth screen or not.
Future<bool> get shouldShowLocalAuthenticationScreen async {
bool result = false;
// whit scan method you can get the intermediate result
final subscription = _appLifeCycleStateSubject
.scan<List<ui.AppLifecycleState>>(
(list, value, _) => [...list, value], []).listen((list) {
if (list.last == ui.AppLifecycleState.resumed && list.length > 1) {
// So if the last state is AppLifecycleState.resumed and list have
// more than one element then the application should show LocalAuthScreen.
// Some possible combination where the last state is AppLifecycleState.resumed.
//[AppLifecycleState.inactive, AppLifecycleState.resumed]
// [AppLifecycleState.paused, AppLifecycleState.hidden,
//AppLifecycleState.inactive, AppLifecycleState.resumed]
//[AppLifecycleState.inactive, AppLifecycleState.hidden,
//AppLifecycleState.paused, AppLifecycleState.hidden,
//AppLifecycleState.inactive, AppLifecycleState.resumed]
result = true;
}
});
subscription.cancel();
return result;
}
I have 2 questions, The first one is did I consider all the possible changes in the state and is the app secure due it shows sensitive information? The second one is should I call subscription.cancel(); even though subscription is inside the getter.