【发布时间】:2021-07-23 04:35:30
【问题描述】:
我想在屏幕关闭时始终执行一个功能,无论是当用户按下后退按钮还是滑动以关闭页面时。
我尝试的是使用WillPopScope
return WillPopScope(
onWillPop: _onWillPop,
child: CupertinoScaffold( ... the rest of my tree
Future<bool> _onWillPop() async {
myFunction();
return true;
}
虽然每当通过后退按钮关闭页面时这确实会成功执行我的功能,但它似乎已禁用滑动以返回 iOS。滑动以返回 android 似乎仍然有效。
还有其他方法可以让我在 iOS 上保留滑动返回功能吗?
编辑:
以防万一,myFunction() 涉及提供程序和上下文,当我尝试从 dispose 调用它时会引发错误。
实际上 myFunction() 是:
context.read(myVisibilityProvider).changeVisibility(false);
【问题讨论】: