我使用 aWillPopScope来尝试阻止路由弹出:
WillPopScope(
onWillPop: () async {
print('This is never called');
return false;
}
)
Run Code Online (Sandbox Code Playgroud)
当我使用时Navigator.pop,当前路由只是弹出而不是onWillPop被调用:
Navigator.of(context).pop();
Run Code Online (Sandbox Code Playgroud)
这是设计使然。
你将不得不使用Navigator.maybePop:
尝试弹出最紧密包围给定上下文的导航器的当前路由,同时遵守路由的Route.willPop状态。
这意味着只Navigator.maybePop尊重onWillPop而Navigator.pop 不是:
Navigator.of(context).maybePop();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
582 次 |
| 最近记录: |