1

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

2 Answers 2

0

For the back button issues, this libray will solve your problem https://pub.dev/packages/back_button_interceptor

To sign out user, use this method on button clicks or after doing some logic

FirebaseAuth.instance.signOut();

To persist user auth using flutter and firebase, refer to this answer: https://stackoverflow.com/a/45084649/11838875

Sign up to request clarification or add additional context in comments.

1 Comment

i want the opposite, the user to stay logged in to the app even when it is closed. and as to the library-can you be more specific about which is the right method for my case? i need to pop all screens of the app
0

I was facing the same problem, the Get package solved everything, use Get package, and then use Get.offAll("spacify the screen which should be last in the stack"); and you're done

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.