如何在flutter应用程序中处理或重写Android设备后退按钮的操作?

问题描述 投票:0回答:2

我想将用户导航到主屏幕,并在按下另一个屏幕上的某个按钮后删除以前的导航堆栈。目前我使用 Navigator.pushNamedAndRemoveUntil 方法。但情况是,当我按下主屏幕上的设备后退按钮时,我的应用程序崩溃了,所以我想处理或覆盖设备后退按钮操作。

android flutter android-layout flutter-layout accessibility
2个回答
0
投票

像这样使用

WillPopScope
小部件

return new WillPopScope(
    onWillPop: () async {
   //  your logic here 
   //  
   return Future.value(false); // true if you want the back button to take effect 
},
    child: new Scaffold(
     //then the rest of your code...

0
投票

这个答案已经过时了。您可以使用 popscope() 或覆盖 dispose()。

© www.soinside.com 2019 - 2024. All rights reserved.