android - 如何在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!")
),
),
),
);
}
解决方案
将您的小部件包装在内部WillPopScope
并在属性中返回 false 。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"),
),
),
);
}
REF:如何在颤动中禁用手机后按
推荐阅读
- loops - 对于高维数组,Julia 中的数组访问循环很慢
- python - Viber Bot 无法启动
- javascript - Angular 自定义元素、构造函数与 ngDoBootstrap
- pycharm - 如何在 PyCharm 中启用“停止并重新运行”弹出窗口?
- json - 不使用 cts:json-property-scope-query 获取结果
- terraform - 为什么 terraform 认为我将许多属性从“”更改为 null?
- python - KIVY 错误:异常:ScrollView 只接受一个小部件
- python-3.x - 如何将熊猫列拆分为多列
- debugging - Spyder 调试器忽略断点
- laravel - 计算具有相同地址的用户并将其返回到刀片视图中