Rablidad
Rablidad

Reputation: 55

How to destroy previous page in flutter?

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

Answers (3)

Jaison Thomas
Jaison Thomas

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

Gaspard Merten
Gaspard Merten

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

Rémi Rousselet
Rémi Rousselet

Reputation: 276921

Instead of Navigator.push, use another option like Navigator.pushReplacement or Navigator.pushAndRemoveUntil

Upvotes: 9

Related Questions