I want the user to be able to exit the app by clicking the phone back button one time (and then he gets a warning message).
but all I found is the option to call to exit(0), but this is logging the user out.
I am using firebase & flutter.
Also, when pressing the back button when I'm in the home_page (which appears after logging), I get the login view again instead of exiting the app. How can I prevent that (because I want the user to stay logged in)
these is the code in my main.dart build() :
return StreamProvider<User?>.value(
value: logic.listenToUserAuth(),
initialData: null, //user signed out
child: MaterialApp(
//initialRoute: '/login',
//routes: this.routes,
// passing the change in stream to child widgets
home: MainWrapper(routes: this.routes,),
),
these is the code from MainWrapper build() , that determines which view to show to the user, depends if he is logged in or not, but it does not work.. the user always gets the '/login' view :
final user = Provider.of<User?>(context);
String initRout = "/login";
// the user logged in
if(user != null) {
initRout = "/home_page.dart";
}
return MaterialApp(
initialRoute: initRout,
routes: routes,
);
Thanks