底部导航栏背景随着新项目而变化



当我开始使用我的应用程序时,BottomNavigationBar上有3个项目。效果很好,然后我又添加了一个项目,背景颜色变成了白色。如果我删除一个项目,背景色将设置为mainBgColor

这是我迄今为止的代码:

bottomNavigationBar: BottomNavigationBar(
unselectedItemColor: secondaryColor.withOpacity(0.5),
selectedItemColor: secondaryColor,
elevation: 5,
backgroundColor: mainBgColor,
currentIndex: widget.index,
onTap: _onItemTapped,
items: const [
BottomNavigationBarItem(
icon: Icon(
Icons.add,
size: 20.0,
),
label: 'New'),
BottomNavigationBarItem(
icon: Icon(
Icons.near_me,
size: 20.0,
),
label: 'Find'),
BottomNavigationBarItem(
icon: Icon(
Icons.wallet,
size: 20.0,
),
label: 'Wallet'),
BottomNavigationBarItem(
icon: Icon(
Icons.wallet,
size: 20.0,
),
label: ''),
],
),

如何设置所需的背景色?

问题是这样解决的:我只需要更新这个属性:

type: BottomNavigationBarType.fixed,

如果没有这一点,无论设置什么,默认背景颜色都将是白色。

最新更新