底部导航栏全白,如何解决?

Mil*_*lie 5 navigationbar dart flutter

我的BottomNavigationBar是全白的。当有3图标时它工作正常,但当增加到 时4,导航栏会变成完全白色。仍然可以选择和更改选项卡。

这是运行小部件时控制台的输出。

ic=null mNaviBarColor -15724014 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false
Run Code Online (Sandbox Code Playgroud)

这是导航栏的构建:

_bottomNavChildren[_currentIndex],
  bottomNavigationBar: BottomNavigationBar(
    onTap: onTabTapped,
    currentIndex: _currentIndex,
    items: [
      BottomNavigationBarItem(
        icon: Icon(Icons.search),
        title: Text('Browse'),
      ),
      BottomNavigationBarItem(
        icon: Icon(Icons.message),
        title: Text('Messages'),
      ),
      BottomNavigationBarItem(
        icon: Icon(Icons.person_outline),
        title: Text('Profile'),
Run Code Online (Sandbox Code Playgroud)

这是List指向相关索引类的小部件。

  int _currentIndex = 0;
  final List<Widget> _bottomNavChildren = [
    BrowsePage(),
    MessagesPage(),
    ProfilePage(),
  ];
Run Code Online (Sandbox Code Playgroud)

有人知道问题是什么吗?谢谢

nic*_*nli 5

来自 flutters官方文档

BottomNavigationBarType.fixed,项目少于四个时的默认值。如果所选项目非空,则使用 selectedItemColor 进行渲染,否则使用主题的 ThemeData.primaryColor。如果backgroundColor为null,导航栏的背景颜色默认为Material背景颜色ThemeData.canvasColor(本质上是不透明的白色)。

BottomNavigationBarType.shifting,有四个或更多项目时的默认值。如果 selectedItemColor 为 null,则所有项目都呈现为白色。导航栏的背景颜色与所选项目的 BottomNavigationBarItem.backgroundColor 相同。在本例中,假设每个项目都有不同的背景颜色,并且该背景颜色将与白色形成鲜明对比。

  • 正确的。为“type”添加“BottomNavigationBarType.fixed”解决了这个问题。谢谢。 (3认同)