Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display more than 3 items in a BottomNavigationBar while coding in flutter

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

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

BottomNavigationBar missing

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

like image 614
Naveen Avatar asked Jun 11 '18 08:06

Naveen


People also ask

How do I show the bottom navigation bar in all pages in flutter?

Showing BottomNavigationBar Scaffold( appBar: AppBar( title: const Text('BottomNavigationBar Demo'), ), bottomNavigationBar: BottomNavigationBar( items: const <BottomNavigationBarItem>[ BottomNavigationBarItem( icon: Icon(Icons. call), label: 'Calls', ), BottomNavigationBarItem( icon: Icon(Icons.


2 Answers

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

Just add a extra parameter in your BottomNavigationBar Constructor -

type : BottomNavigationBarType.fixed

Check also the Flutter Official Ref.

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

like image 59
Bechitra Avatar answered Sep 28 '22 20:09

Bechitra


It's because the default NavigatioBar doesn't support more than 3 items, Use this parameter inside your BottomNavigationBar widget: type: BottomNavigationBarType.fixed

OR Copy and Paste this code below

    bottomNavigationBar: BottomNavigationBar(
     type: BottomNavigationBarType.fixed, ///This allow more than 3 items
     backgroundColor: Theme.Colors.primaryDarkColor,
    currentIndex: 1,
     items: [
    BottomNavigationBarItem(icon: Icon(Icons.arrow_drop_up,), title: Text("GLO", 
    style: TextStyle(color: Colors.black),),),
    BottomNavigationBarItem(icon: Icon(Icons.arrow_drop_up), title: 
    Text("MTN"),),
    BottomNavigationBarItem(icon: Icon(Icons.arrow_drop_up), title: 
    Text("Airtel"),),
    BottomNavigationBarItem(icon: Icon(Icons.arrow_drop_up), title: 
    Text("9mobile"),),
     ],
  ),
like image 32
SilenceCodder Avatar answered Sep 28 '22 20:09

SilenceCodder