I want to show PinCode on app resume for all loggedIn Users
so i checked that there is WidgetsBindingObserver
and used it like this :
class ClientApp extends StatefulWidget {
@override
ClientAppState createState() => ClientAppState();
}
class ClientAppState extends State<ClientApp>
with WidgetsBindingObserver {
@override
Future didChangeAppLifecycleState(AppLifecycleState state) async {
if (state == AppLifecycleState.resumed &&
await auth.isLoggedIn() == true) {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => PinCode(),
),
);
}
super.didChangeAppLifecycleState(state);
}
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'App',
home: SplashScreen(),
);
}
}
the problem here that if user places app in memory and get in back (onResume) the event triggers right but i get this error
E/flutter (22097): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Navigator operation requested with a context that does not include a Navigator. E/flutter (22097): The context used to push or pop routes from the Navigator must be that of a widget that is a descendant of a Navigator widget.
that means that user are not in current state as what i think/understand (correct me if i'm wrong) but how is that ?
yea user is somewhere is application ,, even in splash screen ,, but the same error