Reputation: 8666
I am trying to return the user to the login page once they sign out from the app but goodness,nothing is working. I am getting exceptions like Bad state: Future already completed
or the app returns to the login screen but the previous screen still exists in the stack when I hit back.
Here is my code:
_logOut() async{
await _auth.signOut().then((value){
print("***** log out");
//Navigator.pop(context);
//Navigator.popUntil(context, ModalRoute.withName("/login"));
Navigator.pushReplacement(context, new MaterialPageRoute(builder: (context)=>new MyApp()));
});
// Navigator.popUntil(context, ModalRoute.withName("/login"));
}
Upvotes: 0
Views: 4872
Reputation: 2252
You should not manually send user to login page after they sign out. Instead you should listen to the user's authentication state change and choose the page that you should show to your user based on their authentication state.
Checkout my answer here for more details: Firebase Login with Flutter using onAuthStateChanged
Upvotes: 4
Reputation: 8666
After trying out every function from Navigator
, this worked finally:
_logOut() async{
await _auth.signOut().then((_){
Navigator.of(context).pushNamedAndRemoveUntil("/login", ModalRoute.withName("/home"));
});
}
Upvotes: 2
Reputation: 1228
Try to use following code
Navigator.pushReplacementNamed(context, routeName)
Upvotes: 0