加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

dart – Flutter BottomNavigationBar不能使用超过三个项目

发布时间:2020-12-14 14:52:32 所属栏目:百科 来源:网络整理
导读:我在Flutter(0.6)中的BottomNavigationBar有问题.一旦我添加了超过三个BottomNavigationBarItems作为子项,栏中的按钮就会出现白色图标并且它们会混乱.当我只使用三件或更少的物品时,一切都很好. 这是我使用的小部件代码,它打破了这个障碍: bottomNavigation
我在Flutter(0.6)中的BottomNavigationBar有问题.一旦我添加了超过三个BottomNavigationBarItems作为子项,栏中的按钮就会出现白色图标并且它们会混乱.当我只使用三件或更少的物品时,一切都很好.

这是我使用的小部件代码,它打破了这个障碍:

bottomNavigationBar: BottomNavigationBar(
          currentIndex: 0,iconSize: 20.0,items: [
          BottomNavigationBarItem(
              title: Text('Home'),icon: Icon(Icons.accessibility)),BottomNavigationBarItem(
              title: Text('Preise'),icon: Icon(Icons.account_box)),BottomNavigationBarItem(
              title: Text('Test'),icon: Icon(Icons.adb)),BottomNavigationBarItem(
              title: Text('Mehr'),icon: Icon(Icons.menu))
        ])

有没有人知道这里有什么问题?

提前感谢任何提示,
迈克尔

解决方法

从 https://github.com/flutter/flutter/issues/13642#issuecomment-371875044起

When more than 3 BottomNavigationBar items are provided the type,if
unspecified,changes to BottomNavigationBarType.shifting per
07001.
This bit of information should be highlighted in the class’s doc. It’s
easy to overlook where it is (I overlooked it).

When the BottomNavigationBar’s type is
BottomNavigationBarType.shifting the items text and icons are
rendered in white,via DefaultTextStyle and IconTheme. It’s assumed
that theirBottomNavigationBarItem.backgroundColor will be specified
as a contrasting color. This is obviously confusing.

The overall idea with shifting type bottom navigation bars is that
each item will have a different background color (that contrasts with
white),since that color will become the color of the entire
navigation bar,when the item is selected.

The doc for BottomNavigationBar,and NavigationBarItem needs to be improved.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读