【问题标题】:How to handle or override the action of android device back button in flutter application?如何在flutter应用程序中处理或覆盖android设备后退按钮的动作?
【发布时间】:2021-04-28 17:49:18
【问题描述】:

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

【问题讨论】:

  • 您可能希望包含一个堆栈跟踪,以便任何希望回答您问题的人更容易。

标签: android flutter android-layout flutter-layout android-accessibility


【解决方案1】:

像这样使用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...

【讨论】:

    猜你喜欢
    • 2020-10-10
    • 1970-01-01
    • 2023-01-27
    • 1970-01-01
    • 2012-08-01
    • 2013-09-30
    • 2016-11-30
    • 2014-05-01
    • 2020-03-13
    相关资源
    最近更新 更多