Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter logout to remove all routes

Tags:

flutter

Below is my app widget tree. If user is not logged in then login page is shown if user is logged in then work page. on account page I have logout button.Logout button implements push replacement and shows login page.

Issue is - When user click on back button again work page is shown. How to remove all the routes from widget tree and only show login page after logout action?

Note - I am not using Named routes, just Push , Pop and Replacement

enter image description here

like image 776
max Avatar asked Oct 22 '25 03:10

max


1 Answers

If you are using namedRoutes, you can do this by simply :

Navigator.pushNamedAndRemoveUntil(context, "/login", (Route<dynamic> route) => false);

Where "/login" is the route you want to push on the route stack.

Note That :

This statement removes all the routes in the stack and makes the pushed one the root.

like image 56
Kelvin Mboto Avatar answered Oct 26 '25 18:10

Kelvin Mboto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!