颤振删除所有路线 [英] Flutter remove all routes
本文介绍了颤振删除所有路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想开发一个注销按钮,该按钮会将我发送到登录路线,并从 Navigator
删除所有其他路线。该文档似乎并未解释如何制作 RoutePredicate
或具有任何removeAll函数。
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.
推荐答案
我能够使用以下代码完成此任务:
I was able to accomplish this with the following code:
Navigator.of(context)
.pushNamedAndRemoveUntil('/login', (Route<dynamic> route) => false);
这里的秘密是使用RoutePredicate,它总是返回false (Route< dynamic> ; route)=>错误
。在这种情况下,它将删除除我推送的新 / login
路由以外的所有路由。
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.
这篇关于颤振删除所有路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文