我遇到了一个烦人的样式问题,如果我打开抽屉,我会在 Android 的导航栏下看到空白。而如果我不在抽屉里,它会显示正确的颜色就好了。
我正在为我的抽屉小部件使用以下代码:
drawer: new Drawer(
child: new ListView(
children: <Widget>[
new UserAccountsDrawerHeader(
accountEmail: new Text("juhlinus@gmail.com"),
accountName: new Text("Linus Juhlin"),
currentAccountPicture: new CircleAvatar(
backgroundColor: Colors.pinkAccent,
child: new Text("LJ"),
),
otherAccountsPictures: <Widget>[
new CircleAvatar(
backgroundColor: Colors.purpleAccent,
child: new Text("MH"),
)
],
),
new ListTile(
title: new Text("Artiklar"),
leading: new Icon(Icons.web),
),
new ListTile(
title: new Text("Media"),
leading: new Icon(Icons.wallpaper),
),
new Divider(),
new ListTile(
title: new Text("Inställningar"),
leading: new Icon(Icons.settings)
),
],
),
),
Run Code Online (Sandbox Code Playgroud)
经过一番修修补补,我认为它一定是填充,我尝试从 ListView 小部件中删除所有填充,并且成功了。
我只是简单地将填充添加到 ListView 中,如下所示:
[...]
child: new ListView(
padding: new EdgeInsets.all(0.0),
children: <Widget>[
[...]
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助任何自己偶然发现的人。
我发现在 Flutter UserAccountsDrawerHeader 的源代码中,默认下边距是 8.0。这就是为什么你会在标题下看到这个白色的薄空间。
所以解决方案是将底部边距设置为零:
UserAccountsDrawerHeader(
margin: EdgeInsets.only(bottom: 0.0),
...
Run Code Online (Sandbox Code Playgroud)
工作正常,没有任何技巧。
| 归档时间: |
|
| 查看次数: |
2823 次 |
| 最近记录: |