【发布时间】:2021-01-19 22:41:57
【问题描述】:
前提・我想达到的目标
我打算在按下 Android 后退按钮时使用 WillPopScope 禁用它。
问题・错误信息
在 WillPopScope 中封闭 Scaffold 并按下 Android 后退按钮不会执行 WillPopScope 中设置的功能。
对应源码
Future<bool> onWillPopScope() async {
print('on');
return false;
}
Widget build(BuildContext context) {
return ChangeNotifierProvider<xxxModel>(
create:(_) => xxxModel(),
child: Stack(
children<Widget>[
WillPopScope(
onWillPop: onWillPopScope,
child: Scaffold(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
)
),
Consumer<xxxModel>(
~~~~~~~~~~~~~~~~~~~~
),
],
),
);
}
我尝试了什么
我更改了 WillPopScope 的位置,但它不起作用。
补充信息(FW/工具版本等)
・Flutter 1.17.5
・飞镖2.8.4
【问题讨论】: