更改颤振抽屉背景颜色 [英] Change Flutter Drawer Background Color

查看:64
本文介绍了更改颤振抽屉背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改颤动导航抽屉的背景颜色?似乎没有颜色或背景颜色属性.

How can I change the background color of a flutter nav drawer? There doesn't seem to be a color or background-color property.

推荐答案

当您在 Drawerchild 属性中构建 ListView 时,您可以将 Drawer 的不同部分包装在 Container 中,并使用 Containercolor 属性.

When you build your ListView in the child property of your Drawer, you can wrap your different sections of the Drawer inside a Container and use the color property of the Container.

drawer: new Drawer(
        child: new ListView(
          children: <Widget>[
            new Container(child: new DrawerHeader(child: new CircleAvatar()),color: Colors.tealAccent,),
            new Container (
              color: Colors.blueAccent,
              child: new Column(
                children: new List.generate(4, (int index){
                  return new ListTile(
                    leading: new Icon(Icons.info),
                  );
                }),
              ),
            )
          ],
        ),
      ),

如果您已经有了一致的着色设计,一个更好的选择是在应用根目录的主题属性下定义您的 ThemeDataDrawerHeader并且正文将跟随您的 canvasColor,因此您需要覆盖其中之一的值以更改颜色:

A better alternative if you already have a consistent coloring design in your mind, is to define your ThemeData under the theme property of the root of your app, the DrawerHeader and the body will follow your canvasColor, so you need to override the value of one of them to change the color:

return new MaterialApp(
....
theme: new ThemeData(
       canvasColor: Colors.redAccent,

       ....),
)

这篇关于更改颤振抽屉背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆