简体   繁体   English

如何在 flutter 中更改为我的 DrawerMenuBar 背景 colors?

[英]How can i change to my drawerMenuBar background colors in flutter?

Below is my code, i've been able to change the drawerheader to black, but the when i did color: Colors.grey[800] for the listtiles, only it's area is covered in grey, the remaining extra space is white..下面是我的代码,我已经能够将drawerheader更改为黑色,但是当我做color: Colors.grey[800]对于listtiles,只有它的区域被灰色覆盖,剩余的额外空间是白色的..

drawer: Drawer(
              child: ListView(
                padding: EdgeInsets.zero,
                children: [
                  Container(
                    height: 130,
                    child: DrawerHeader(
                      child: new Text(
                        'Hi Bolade',
                        style: TextStyle(color: Colors.white),
                      ),
                      decoration: BoxDecoration(
                        color: Colors.black,
                      ),
                    ),
                  ),
                  Container(
                    padding: EdgeInsets.zero,
                    margin: EdgeInsets.zero,
                    decoration: BoxDecoration(
                      color: Colors.grey[800],
                    ),
                    child: Column(
                      children: [
                        ListTile(
                          leading: Icon(Icons.home),
                          title: Text('Dashboard'),
                          onTap: () {},
                        ),
                        ListTile(
                          leading: FaIcon(FontAwesomeIcons.tree),
                          title: Text('Savings'),
                          onTap: () {},
                        ),
                        ListTile(
                          leading: Icon(Icons.trending_up),
                          title: Text('Investments'),
                          onTap: () {},
                        ),
                        ListTile(
                          leading: Icon(Icons.account_box_sharp),
                          title: Text('Products'),
                          onTap: () {},
                        ),
                        ListTile(
                          leading: Icon(Icons.wallet_membership),
                          title: Text('Wallet'),
                          onTap: () {},
                        ),
                        ListTile(
                          leading: Icon(Icons.card_giftcard),
                          title: Text('Cards & Bank'),
                          onTap: () {},
                        ),
                        ListTile(
                          leading: Icon(Icons.card_giftcard),
                          title: Text('Share & Earn'),
                          onTap: () {},
                        ),
                        ListTile(
                          leading: Icon(Icons.chat),
                          title: Text('Support'),
                          onTap: () {},
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),

enter image description here Image of the current state here below在此处输入图像描述当前 state 的图像在下面

Keep your listview inside a Container and give a color to this container.将您的列表视图保存在 Container 中并为该容器指定颜色。

Container(
color: Colors.grey[800]
child: ListView(
.... 
)
)

I didn't get you question completely.....But I'm guessing that the header is black as expected, but only the tiles are covered in the grey color and the remaining space is white.(the default color).我没有完全问你问题......但我猜测 header 是黑色的,但只有瓷砖被灰色覆盖,剩余空间为白色。(默认颜色)。

If this is the case then you can maybe wrap your listview with a container and give it the grey color.如果是这种情况,那么您可以用一个容器包装您的列表视图并将其设置为灰色。 By doing this the newly added grey container will act as a background color.通过这样做,新添加的灰色容器将充当背景颜色。

Keep your listview inside a Container and give a color to this container.将您的列表视图保存在 Container 中并为该容器指定颜色。

    Container(
height: MediaQuery.of(context).size.height,
    color: Colors.grey[800]
    child: ListView(
    .... 
    )
    )

just wrap your Driver with Theme widget and replace canvasColor只需用 Theme 小部件包装您的驱动程序并替换canvasColor

  drawer: Theme(
    data: Theme.of(context).copyWith(canvasColor: Colors.grey[800]),
    child: Drawer(
      child: ListView(
        padding: EdgeInsets.zero,
        children: [
          Container(
            height: 130,
            child: DrawerHeader(
              child: Text('Hi Bolade', style: TextStyle(color: Colors.white)),
              decoration: BoxDecoration(color: Colors.black),
            ),
          ),
          Column(
            children: [
              ListTile(
                leading: Icon(Icons.home),
                title: Text('Dashboard'),
                onTap: () {},
              ),
              ListTile(
                leading: Icon(Icons.trending_up),
                title: Text('Savings'),
                onTap: () {},
              ),
              ListTile(
                leading: Icon(Icons.trending_up),
                title: Text('Investments'),
                onTap: () {},
              ),
              ListTile(
                leading: Icon(Icons.account_box_sharp),
                title: Text('Products'),
                onTap: () {},
              ),
              ListTile(
                leading: Icon(Icons.wallet_membership),
                title: Text('Wallet'),
                onTap: () {},
              ),
              ListTile(
                leading: Icon(Icons.card_giftcard),
                title: Text('Cards & Bank'),
                onTap: () {},
              ),
              ListTile(
                leading: Icon(Icons.card_giftcard),
                title: Text('Share & Earn'),
                onTap: () {},
              ),
              ListTile(
                leading: Icon(Icons.chat),
                title: Text('Support'),
                onTap: () {},
              ),
            ],
          ),
        ],
      ),
    ),
  ),

also in this case you don't need Container above Column anymore同样在这种情况下,您不再需要 Container above Column
在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM