繁体   English   中英

为什么我无法更改 Flutter 底部导航栏的背景颜色?

[英]Why am I not able to change the background color of my bottom navigation bar in Flutter?

我想将底部导航栏的背景颜色更改为黑色,但它仍然是白色。 是什么导致了这个问题?

底部导航栏截图

底部导航栏截图

底部导航条码。

bottomNavigationBar: BottomNavigationBar(
    onTap: _onItemTapped,
    type: BottomNavigationBarType.shifting,
    iconSize: 30,

    unselectedItemColor: Colors.black,
    selectedIconTheme: const IconThemeData(color: Colors.black, size: 30),
    selectedItemColor: Colors.black,
    selectedLabelStyle: const TextStyle(fontWeight: FontWeight.bold),
    backgroundColor: Colors.white,

    items: const <BottomNavigationBarItem>[
      BottomNavigationBarItem(
        icon: Icon(Icons.home),
        label: 'Home',
      ),
      BottomNavigationBarItem(
        icon: Icon(Icons.door_back_door),
        label: 'Rooms',
      ),
      BottomNavigationBarItem(
        icon: Icon(Icons.search),
        label: 'Search',
      ),
      BottomNavigationBarItem(
        icon: Icon(Icons.map),
        label: 'Maps',
      ),
      BottomNavigationBarItem(
        icon: Icon(Icons.person),
        label: 'Profile',
      ),
    ],
    currentIndex: _selectedIndex,
  ),

我一直在努力弄清楚这部分,但我似乎看不出问题的原因。 如果可能的话,我将不胜感激::)

阅读BottomNavigationBar backgroundColor的描述,它说

如果 [type] 是 [BottomNavigationBarType.shifting] 并且 [items] 设置了 [BottomNavigationBarItem.backgroundColor],则 [items] 的 backgroundColor 将飞溅并覆盖此颜色。

因此,解决方案可以是将backgroundColor设置为您的BottomNavigationItem之一,它将应用于整个BottomNavigationBar

background color仅在typeBottomNavigationBarType.fixed时有效

如果typeBottomNavigationBarType.shiftingitems将覆盖此color


BottomNavigationBarType.fixed

在此处输入图像描述

BottomNavigationBarType.shifting

在此处输入图像描述

暂无
暂无

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

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