gpt4 book ai didi

flutter - flutter 抽屉:删除空白区域

转载 作者:行者123 更新时间:2023-12-03 03:15:39 30 4
gpt4 key购买 nike

我在抽屉里装了一个粘头。但是现在我在 header 和第一个ListTile项之间有一个空格。
如何删除此空间/将项目设置在标题的末尾?

谢谢你的帮助!
(我必须删除一些ListTiles,因为它对于stackoverflow来说是很多代码)

drawer: Drawer(
child: Column(
children: [
Expanded(
flex: 1,
child: Container(
width: MediaQuery.of(context).size.width * 0.85,
child: DrawerHeader(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomLeft,
colors: [Colors.blue, Colors.red])
),
child: Center (child: Text('Title', style: TextStyle(color: Colors.white, fontWeight: FontWeight.w700, fontSize: 30.0)),),

),
),
),
Expanded(
flex: 2,
child: ListView(children: [
ListTile(
leading: Icon(Icons.wb_sunny),
title: Text('Menu 1'),
trailing: Icon(Icons.keyboard_arrow_right),
onTap: () {print("Hallo");},
),
Divider(height: 1, thickness: 0.5, color: Colors.grey,),
ListTile(
leading: Icon(Icons.wb_sunny),
title: Text('Menu 2'),
trailing: Icon(Icons.keyboard_arrow_right),
onTap: () {print("Hallo");},
),
Divider(height: 1, thickness: 0.5, color: Colors.grey,),
ListTile(
leading: Icon(Icons.wb_sunny),
title: Text('Menu 3'),
trailing: Icon(Icons.keyboard_arrow_right),
onTap: () {print("Hallo");},
),
Divider(height: 1, thickness: 0.5, color: Colors.grey,),
]),
)
],
),
),

最佳答案

ListView具有默认的填充。
将listview的padding属性设置为0,空格消失了:

drawer: Drawer(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
flex: 1,
child: Container(
width: MediaQuery.of(context).size.width * 0.85,
child: DrawerHeader(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomLeft,
colors: [Colors.blue, Colors.red])),
child: Center(
child: Text('Title',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w700,
fontSize: 30.0)),
),
),
),
),
Expanded(
flex: 2,
child: ListView(
children: [
ListTile(
leading: Icon(Icons.wb_sunny),
title: Text('Menu 1'),
trailing: Icon(Icons.keyboard_arrow_right),
onTap: () {
print("Hallo");
},
),
Divider(
height: 1,
thickness: 0.5,
color: Colors.grey,
),
ListTile(
leading: Icon(Icons.wb_sunny),
title: Text('Menu 2'),
trailing: Icon(Icons.keyboard_arrow_right),
onTap: () {
print("Hallo");
},
),
Divider(
height: 1,
thickness: 0.5,
color: Colors.grey,
),
ListTile(
leading: Icon(Icons.wb_sunny),
title: Text('Menu 3'),
trailing: Icon(Icons.keyboard_arrow_right),
onTap: () {
print("Hallo");
},
),
Divider(
height: 1,
thickness: 0.5,
color: Colors.grey,
),
],
padding: EdgeInsets.only(top: 0),
),
)
],
),
),

关于flutter - flutter 抽屉:删除空白区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59842200/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com