flutter - 在 WillPopScope 中设置 `onWillPop` 方法时如何启用向后滑动效果
问题描述
如flutter源码所写。设置onWillPop
方法后,滑动效果被禁用。
static bool _isPopGestureEnabled<T>(PageRoute<T> route) {
...
// If attempts to dismiss this route might be vetoed such as in a page
// with forms, then do not allow the user to dismiss the route with a swipe.
if (route.hasScopedWillPopCallback)
return false;
...
}
这似乎是在issue中讨论的预期行为。
那么,我该如何收听 Navigator.pop 事件。我的需要是,如果某些变量不正确,它就无法成功返回。
解决方案
我刚刚测试了创建一个自定义 RouteManager 并且 willPop 在执行回扫效果时永远不会被调用。另一方面,您可以在删除 Widget 之前调用dispose()
和deactivate()
在您的 State 上清理您的变量。
推荐阅读
- python - 如何使用二进制逻辑选择标签?
- javascript - d3使用stroke-dasharray和stroke-dashoffset画线
- python - Airflow 1.9.0 无法对任务进行排队
- regex - 如何替换所有电子邮件的域名
- c++ - 迷失在指针的世界中
- mysql - 尝试优化执行时间较长的查询
- java - 在java中使用反射面临的问题
- vba - 显示上次用户在 vba 中打开共享工作簿的时间
- amazon-web-services - 如何处理 SQS + Lambda 中的消费者执行错误?
- dart - Flutter 调用 showTimePicker 函数导致错误:在 null 上调用了 getter 'modalBarrierDismissLabel'