首页 > 解决方案 > 如何在flutter中停用或覆盖appBar中的箭头后退按钮?

问题描述

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

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!")
    ),
  ),
),
);
}

在此处输入图像描述

标签: androidflutter

解决方案


将您的小部件包装在内部WillPopScope并在属性中返回 false 。FutureonWillPop

    @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"),
          ),
        ),
      );
    }

REF:如何在颤动中禁用手机后按


推荐阅读