如何在激活状态下取消激活或替代appBar中的向后箭头?

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

在特定页面上,是否可以禁用后退箭头按钮?我构建了一个启动屏幕,并且每当启动屏幕导航到HomePage时,在HomePage 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!")
    ),
  ),
),
);
}

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9kcW1GSC5qcGcifQ==” alt =“在此处输入图像说明”>

android flutter
2个回答
0
投票

flutter remove back button on appbar

您可能会发现您的答案已在此问题中回答


0
投票

将小部件包装在WillPopScope内,并返回错误的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:how to disable phone back press in flutter

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