I want to develop a logout button that will send me to the log in route and remove all other routes from the Navigator
. The documentation doesn't seem to explain how to make a RoutePredicate
or have any sort of removeAll function.
相关问题
- What means in Dart static type and why it differs
- Flutter : Prepare list data from http request
- How to schedule an alarm on specific time in Flutt
- MappedListIterable is not a SubType
- 'firebase_messaging/FirebaseMessagingPlugin.h&
相关文章
- Observatory server failed to start - Fails to crea
- Flutter error retrieving device properties for ro.
- Adding Shadows at the bottom of a container in flu
- Flutter. Check if a file exists before loading it
- Flutter - http.get fails on macos build target: Co
- Receive share file intents with Flutter
- Do stateless widgets dispose on their own?
- How to clean your build with Flutter RP2 in Androi
i can done with the following code snippet :
if you want to remove all the route below the pushed route, RoutePredicate always return false, e.g (Route route) => false.
I was able to accomplish this with the following code:
The secret here is using a RoutePredicate that always returns false
(Route<dynamic> route) => false
. In this situation it removes all of the routes except for the new/login
route I pushed.In case you want to go back to the particular screen and you don't use named router can use the next approach
Example:
With route is HomePage you check the name of your widget.
I dont know why no one mentioned the solution using SchedularBindingInstance,A little late to the party though,I think this would be the right way to do it originally answered here
The above code removes all the routes and naviagtes to '/login' this also make sures that all the frames are rendered before navigating to new route by scheduling a callback
Another solution is to use
pushAndRemoveUnit()
. To remove all other routes useModalRoute.withName('/')
Reference: https://api.flutter.dev/flutter/widgets/NavigatorState/pushAndRemoveUntil.html
Another alternative is
popUntil()
This will pop all routes off until you are back at the named route.