[英]How to disable drawer button in flutter
所以我有一個帶有這個應用程序欄的應用程序,它有這個按鈕。 當用戶按下按鈕時,它會打開抽屜。 但是,當您向左滑動時,它也會打開抽屜。
這是圖片:按鈕
這是我的代碼:
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,
),
),
],
),
),
);
如何禁用按鈕? 我只希望用戶向左滑動,但屏幕上未顯示該按鈕。
感謝任何答案,謝謝!
案例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,
),
),
],
),
),
);
案例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,
),
),
],
),
),
);
您可以通過將automaticallyImplyLeading
屬性設置為false
來隱藏您的 AppBars 前導
automaticallyImplyLeading: false
基於您的代碼的完整示例
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.