0

When I started to work on my app there were 3 items on the BottomNavigationBar. It worked well, then I added one more item and the background color changed to white. If I remove one item, the background color is set to mainBgColor

This is my code so far:

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: ''),
                ],
              ),

How could I set the required background color?

Ballazx
  • 431
  • 4
  • 12
  • Your code is working fine. Can you explain your issue in detail? – G H Prakash Sep 05 '22 at 12:13
  • When there are 3 BottomNavigationBarItem the backgroundColor is the color that I needed (mainBGColor). When I add one item, the background gets white, no matter what the backgroundcolor is. – Ballazx Sep 06 '22 at 07:13

1 Answers1

0

The problem is solved this way: I only needed to update this property:

type: BottomNavigationBarType.fixed,

Without this, the default background color will be white no matter what is set up.

Ballazx
  • 431
  • 4
  • 12