抽屉导航栏下白色space

White space under navigation bar in drawer

我遇到了一个恼人的样式问题,如果我打开我的抽屉,Android 上的导航栏下会变成白色 space。而如果我不在抽屉里,它会显示正确的颜色。

我正在为我的抽屉小部件使用以下代码:

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)
        ),
        ],
    ),
),

经过一番修改后,我认为它一定是填充,我尝试从 ListView 小部件中删除所有填充,结果成功了。

我只是像这样将填充添加到 ListView 中:

[...]
child: new  ListView(
    padding: new EdgeInsets.all(0.0),
    children: <Widget>[
[...]

希望这对自己遇到此问题的任何人有所帮助。

我发现在Flutter的源代码中UserAccountsDrawerHeader bottom margin 默认是8.0。 这就是为什么你在 header.

下看到这个白色薄 space

所以解决方案是将底部边距设置为零:

UserAccountsDrawerHeader(
    margin: EdgeInsets.only(bottom: 0.0),
...

工作正常,没有任何技巧。