Flutter 颤振抽屉:清除空的空间
我在抽屉里装了一个粘头。但现在我在标题和第一个ListTile项之间有一个空白。 如何删除此空格/将项目设置为标题的结尾 谢谢你的帮助! (由于stackoverflow的代码太多,我不得不删除一些ListTile)Flutter 颤振抽屉:清除空的空间,flutter,dart,navigation-drawer,flutter-layout,Flutter,Dart,Navigation Drawer,Flutter Layout,我在抽屉里装了一个粘头。但现在我在标题和第一个ListTile项之间有一个空白。 如何删除此空格/将项目设置为标题的结尾 谢谢你的帮助! (由于stackoverflow的代码太多,我不得不删除一些ListTile) 我想问题出在抽屉阅读器上。 我会用一个有填充物的容器 另一件事可能是您将抽屉阅读器的容器包装在一个扩展的容器中。Expanded将尝试获取所有可用空间。因此,在这种情况下,也可以尝试使用不同的FlexFit移动到Flexible Drawer( child: Column(
我想问题出在
抽屉阅读器上。
我会用一个有填充物的容器
另一件事可能是您将抽屉阅读器的容器包装在一个扩展的容器中。Expanded将尝试获取所有可用空间。因此,在这种情况下,也可以尝试使用不同的FlexFit移动到Flexible
Drawer(
child: Column(
children: [
Container(
padding: const EdgeInsets.symmetric(vertical: 16),
width: MediaQuery.of(context).size.width * 0.85,
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(
child: ListView(children: [
ListTile(
leading: Icon(Icons.wb_sunny),
title: Text('Menu 1'),
trailing: Icon(Icons.keyboard_arrow_right),
onTap: () {
print("Hallo");
},
),
]),
)
],
这里是最后一个例子。我想问题出在抽屉阅读器上。
我会用一个有填充物的容器
另一件事可能是您将抽屉阅读器的容器包装在一个扩展的容器中。Expanded将尝试获取所有可用空间。因此,在这种情况下,也可以尝试使用不同的FlexFit移动到Flexible
Drawer(
child: Column(
children: [
Container(
padding: const EdgeInsets.symmetric(vertical: 16),
width: MediaQuery.of(context).size.width * 0.85,
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(
child: ListView(children: [
ListTile(
leading: Icon(Icons.wb_sunny),
title: Text('Menu 1'),
trailing: Icon(Icons.keyboard_arrow_right),
onTap: () {
print("Hallo");
},
),
]),
)
],
这里是最后一个示例。用Inkwell
小部件包装listTile
小部件,如下所示。
这将减少一些空间
InkWell(
onTap: () {print("Hello");},
child: ListTile(
leading: Icon(Icons.wb_sunny),
title: Text('Menu 2'),
trailing: Icon(Icons.keyboard_arrow_right),
),
),
用Inkwell
小部件包装您的listTile
小部件,如下所示。
这将减少一些空间
InkWell(
onTap: () {print("Hello");},
child: ListTile(
leading: Icon(Icons.wb_sunny),
title: Text('Menu 2'),
trailing: Icon(Icons.keyboard_arrow_right),
),
),
将抽屉阅读器边距设置为0
。。。
儿童:抽屉阅读器(
边距:所有边集(0),
装饰:盒子装饰(
梯度:线性梯度(
开始:Alignment.topRight,
结束:对齐。左下角,
颜色:[颜色。蓝色,颜色。红色]),
儿童:中心(
子项:文本('标题',
...
将抽屉阅读器边距设置为0
。。。
儿童:抽屉阅读器(
边距:所有边集(0),
装饰:盒子装饰(
梯度:线性梯度(
开始:Alignment.topRight,
结束:对齐。左下角,
颜色:[颜色。蓝色,颜色。红色]),
儿童:中心(
子项:文本('标题',
...
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),
),
)
],
),
),
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),
),
)
],
),
),