In my flutter app, I wanted to check if a user is not using the app while they are in Foreground. WidgetsBindingObserver
only checks if the app is in the foreground/background. and if the app has resumed, inactive, detached, or paused. but how can I check if the user is not using the app in the foreground at a specific time?
@override
void initState() {
// TODO: implement initState
super.initState();
WidgetsBinding.instance!.addObserver(this);
}
@override
void dispose() {
// TODO: implement dispose
WidgetsBinding.instance!.removeObserver(this);
super.dispose();
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
super.didChangeAppLifecycleState(state);
if (state == AppLifecycleState.detached ||
state == AppLifecycleState.inactive) return;
final isBackground = state == AppLifecycleState.paused;
final isForeground = state == AppLifecycleState.resumed;
if (isBackground || isForeground) {
Get.offAll(Login());
}
}