有什么方法可以onBackPressed从Android后退按钮捕获事件吗?
我尝试了WillPopScope但是我的onWillPop功能仅在我点击材料后退箭头按钮时触发
我这样说:
class MyView extends StatelessWidget{
Widget build(BuildContext context) {
return new WillPopScope(
onWillPop: () async {
debugPrint("Will pop");
return true;
},
child: ScopedModel<AppModel>(
model: new AppModel(),
child: new Scaffold(......
Run Code Online (Sandbox Code Playgroud)
我需要抓住它,因为不知何故我的屏幕在按下后退按钮时表现不正确,它弹出屏幕和它下面的屏幕,但不知何故,使用材料后退箭头按钮工作正常.
更新:
the code works, my problem was not in the pop of this screen, but on the previous screen, I use 2 MaterialApp widgets, and somehow it gave a weird behavior.
Run Code Online (Sandbox Code Playgroud)