flutter - 如何清除所有路由以减少内存量?
问题描述
例如,如果有人不关心关闭路线,那么导航堆栈可以占用多少空间?
是否有清理所有导航堆栈以清除一些空间的方法或方法?
例如,如果有人进行多次推送
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
推荐阅读
- c# - 我有一个 WSDL,如何为请求创建(但不发送)SOAP?
- c++11 - 在 C++ 11 中的函数声明之后,'->' 是什么意思?
- codeigniter - Codeigniter 使用 url 切换语言
- server - 未启用fail2ban监狱
- angularjs - 使用angularjs将剑道网格的所有列导出为pdf
- r - 仅使用月份和年份更改日期格式
- android - 如何在 android studio 上导入 espresso withID?
- mysql - 通过 PHP 将 MySQL 数据发送到 Google BigQuery
- python - 索引中的错误日期与我没有要求的第二张图
- linux - 关于 DS 记录更新的 DNSSEC 密钥翻转