Reputation: 55
I want to make a login page in flutter, where when the login succeed, the app switches to the next page and destroy the previous one, i.e. once the user is logged in, the only way for him to go back to the login page is to explicitly logout from the current session, instead of only pressing the previous button of the android.
Upvotes: 3
Views: 9969
Reputation: 403
Just a quick tip if you're using routes in your material app and Navigating by screen name you can use:
Navigator.pushNamedAndRemoveUntil(context, newRouteName, (route) => false)
Upvotes: 0
Reputation: 1233
Just to complete what Rémi said, if you want to make sure that there is no other view before the home view, you should do that:
Navigator.pushAndRemoveUntil(context, YourMaterialPageRoute(), (e) => false);
Upvotes: 3
Reputation: 276921
Instead of Navigator.push
, use another option like Navigator.pushReplacement
or Navigator.pushAndRemoveUntil
Upvotes: 9