如何在颤动中更改我的 drawerMenuBar 背景颜色?

时间:2021-02-15 11:02:41

标签: flutter dart

下面是我的代码,我已经能够将抽屉标题更改为黑色,但是当我为列表块执行 color: Colors.grey[800] 时,只有它的区域被灰色覆盖,剩余的额外空间是白色的..

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 下面是当前状态的图像

4 个答案:

答案 0 :(得分:0)

将您的列表视图保存在一个容器中,并为该容器指定颜色。

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

答案 1 :(得分:0)

我没有完全问你问题.....但我猜标题是黑色的,但只有瓷砖被灰色覆盖,剩余的空间是白色的。(默认颜色).

如果是这种情况,那么您可以用容器包装您的列表视图并为其赋予灰色。通过这样做,新添加的灰色容器将用作背景颜色。

答案 2 :(得分:0)

将您的列表视图保存在一个容器中,并为该容器指定颜色。

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

答案 3 :(得分:0)

只需用主题小部件包装您的驱动程序并替换 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: () {},
              ),
            ],
          ),
        ],
      ),
    ),
  ),

同样在这种情况下,您不再需要列上方的容器
enter image description here