【问题标题】:How to deactivate or override the arrow back button in the appBar in flutter?如何在flutter中停用或覆盖appBar中的箭头后退按钮?
【发布时间】:2020-03-13 19:55:32
【问题描述】:

有没有办法在特定页面上停用箭头返回按钮? 我建立了一个启动画面,每当启动画面导航到主页时,在主页应用程序栏中,返回的箭头会显示,如何停用它或清除返回上一页的箭头(欢迎屏幕)。

Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () {return Future.value();
}, // async => true,
child: Scaffold(
  appBar: AppBar(
    title: Text("Application!"),
    elevation: 20,
    centerTitle: true,
    actions: <Widget>[
      IconButton(
        icon: Icon(Icons.exit_to_app),
        onPressed: () {
          Navigator.pop(context);
        },
      ),
      PopupMenuButton(
        icon: Icon(Icons.more_vert),
        itemBuilder: (context) => [
          PopupMenuItem(
            child: Text("Home"),
          ),
          PopupMenuItem(
            child: Text("Hire"),
          ),
          PopupMenuItem(
            child: Text("Settings"),
          ),
          PopupMenuItem(
            child: Text("About"),
          ),
        ],
      ),
    ],
  ),
  body: Center(
    child: Container(
      child: Text("Chech out my new Mobile Applications!")
    ),
  ),
),
);
}

【问题讨论】:

    标签: android flutter


    【解决方案1】:

    将您的小部件包装在 WillPopScope 中并onWillPop 属性中返回一个错误的 Future

        @override
        Widget build(BuildContext context) {
          return WillPopScope(
            onWillPop: () => Future.value(false),
            child: Scaffold(
              appBar: AppBar(
                title: const Text("Home Page"),
              ),
              body: Center(
                child: const Text("Home Page"),
              ),
            ),
          );
        }
    

    参考号:how to disable phone back press in flutter

    【讨论】:

      【解决方案2】:

      flutter remove back button on appbar

      您可能会发现您的答案已在此问题中得到解答

      【讨论】:

        猜你喜欢
        • 2020-10-22
        • 2018-02-05
        • 2020-10-10
        • 2023-01-27
        • 2018-02-08
        • 2015-11-30
        • 2015-05-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多