首页 > 解决方案 > 如何清除所有路由以减少内存量?

问题描述

例如,如果有人不关心关闭路线,那么导航堆栈可以占用多少空间?

是否有清理所有导航堆栈以清除一些空间的方法或方法?

例如,如果有人进行多次推送

Navigator.push...
Navigator.push...
Navigator.push...
Navigator.push...
Navigator.push...
Navigator.push...
Navigator.push...
Navigator.push...
...
// and at some point he would like to dismiss it all
[Navigator.cleanUp()] // for example

标签: flutter

解决方案


为了清除所有的路线,只留下第一个可以使用的Navigator.popUntil方法。像这样:

Navigator.of(context).popUntil((route)=> route.isFirst);
// Pops routes until the current route's isFirst getter equals to true
// (until the current route is the first route

推荐阅读