颤振返回首页 [英] Flutter return to home page
问题描述
我制作了一个具有很多路由的应用程序,一个接一个地推送多个全屏对话框.但是,从一个对话框中,我想关闭所有对话框并返回首页.我该怎么办?
I have made an app that has quite some routing in it, pushing multiple fullscreen dialogs after each other. But from one dialog I want to close all and return to the homepage. How can I do that?
我不想再次推送主页,因为那样,我的导航历史记录中仍然包含所有这些对话框. pushReplacement
是正确的方法吗?似乎不是因为它只删除了导航历史记录中的最后一个条目,所以如果我按回去,则会进入倒数第二个对话框...
I don't want to push the homepage again, because then I have all these dialogs still in my navigation history. Is pushReplacement
the right way? It doesn't seem to be because it only deletes the last entry in the navigation history, so if i press back, i get to the second last dialog...
推荐答案
使用popUntil
返回所需的位置.如果它是主页,则应该可以:
Use popUntil
to go back to the point you want. If it's the Home page, this should work:
Navigator.popUntil(context, ModalRoute.withName('/'));
这篇关于颤振返回首页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!