如何在Flutter中编码时在BottomNavigationBar中显示3个以上的项目 [英] How to display more than 3 items in a BottomNavigationBar while coding in flutter

查看:131
本文介绍了如何在Flutter中编码时在BottomNavigationBar中显示3个以上的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试添加5个BottomNavigationBarItem,但是,如果我尝试添加3个以上的项目,则编译器将引发错误.看起来像这样:

I tried adding 5 BottomNavigationBarItem but, the compiler throws an error if I try to add more than 3 items. It looks something like this:

 The following RangeError was thrown building BottomNavigationBar(dirty, state:
_BottomNavigationBarState#a56dd(tickers: tracking 3 tickers)):
 RangeError (index): Invalid value: Not in range 0..2, inclusive: 3

我需要在BottomNavigationBar中显示5个项目.帮我解决这个问题.

I need to display 5 items in the BottomNavigationBar. Help me out on this one.

缺少BottomNavigationBar

有指向代码的链接,目前那里只有三个项目,我想再添加两个项目,而编译器不会抛出错误消息

there is the link to the code and, currently there are just three items in there, I wanna add two more items without the compiler throwing error message

推荐答案

只需编写此代码,以供将来有关此问题的查询使用.

Just writing it for the future query regarding on this issue.

只需在您的BottomNavigationBar构造函数中添加一个额外的参数-

Just add a extra parameter in your BottomNavigationBar Constructor -

type:BottomNavigationBarType.fixed

也请查看Flutter官方参考文件.

可选:从一开始就重新启动您的应用,以解决呈现问题.

Optional : Restart your app from start for fixing rendering issue.

这篇关于如何在Flutter中编码时在BottomNavigationBar中显示3个以上的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆