[英]How to disable drawer button in flutter
so I have an app with this app bar that has this Button.所以我有一个带有这个应用程序栏的应用程序,它有这个按钮。 When the user presses the button, it will open the drawer.
当用户按下按钮时,它会打开抽屉。 However, when you just swipe to the left, it will also open the drawer.
但是,当您向左滑动时,它也会打开抽屉。
This is the picture: The Button这是图片:按钮
And this is my code:这是我的代码:
return Scaffold(
appBar: AppBar(
title: Text(
"AppBar",
style: TextStyle(
fontSize: 30,
fontWeight: FontWeight.bold,
fontFamily: "FjallaOne"),
),
backgroundColor: Color(0xFFF0D5EAF),
),
body: Container(
child: ScrollView(),
),
drawer: Drawer(
child: ListView(
children: [
Text(
"Hello world",
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
],
),
),
);
How do I disable the button ?如何禁用按钮? I just want the user to swipe left, but the button is not shown on the screen.
我只希望用户向左滑动,但屏幕上未显示该按钮。
Any answers is appreciated, thank you !感谢任何答案,谢谢!
case 1: if You want the button but still don't want anything to happen on that案例1:如果您想要按钮但仍然不希望在该按钮上发生任何事情
return Scaffold(
appBar: AppBar(
title: Text(
"AppBar",
style: TextStyle(
fontSize: 30,
fontWeight: FontWeight.bold,
fontFamily: "FjallaOne"),
),
leading: IconButton(
icon: const Icon(Icons.menu),
onPressed: () {},
),
backgroundColor: Color(0xFFF0D5EAF),
),
body: Container(
child: Container(),
),
drawer: Drawer(
child: ListView(
children: [
Text(
"Hello world",
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
],
),
),
);
case 2: if You don't want button at all案例2:如果你根本不想要按钮
return Scaffold(
appBar: AppBar(
title: Text(
"AppBar",
style: TextStyle(
fontSize: 30,
fontWeight: FontWeight.bold,
fontFamily: "FjallaOne"),
),
leading: Container(),
backgroundColor: Color(0xFFF0D5EAF),
),
body: Container(
child: Container(),
),
drawer: Drawer(
child: ListView(
children: [
Text(
"Hello world",
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
],
),
),
);
You can hide your AppBars leading by setting automaticallyImplyLeading
property to false
您可以通过将
automaticallyImplyLeading
属性设置为false
来隐藏您的 AppBars 前导
automaticallyImplyLeading: false
Full example based on your code基于您的代码的完整示例
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
title: Text(
"AppBar",
style: TextStyle(
fontSize: 30,
fontWeight: FontWeight.bold,
fontFamily: "FjallaOne"),
),
backgroundColor: Color(0xFFF0D5EAF),
),
body: Container(
child: ScrollView(),
),
drawer: Drawer(
child: ListView(
children: [
Text(
"Hello world",
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
],
),
),
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.