Fot isstance,如果有人不关心关闭路线,那么多少空间可以占用导航堆栈?
是否有清理所有导航堆栈以清理一些空间的方法或途径?
例如,如果某人进行多次推送
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
最佳答案
为了清除所有路由,只留下第一个,您可以使用 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
关于flutter - 如何清除所有路由以减少内存量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66732895/