在特定页面上,是否可以禁用后退箭头按钮?我构建了一个启动屏幕,并且每当启动屏幕导航到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 =“在此处输入图像说明”>
flutter remove back button on appbar
您可能会发现您的答案已在此问题中回答
将小部件包装在WillPopScope
内,并返回错误的Future
在onWillPop
属性中。
@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"),
),
),
);
}