Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Flutter bottomNavigationBar inactive

I'm having an app with a bottom navigation bar:

BottomNavigationBar(
 type: BottomNavigationBarType.fixed,
 items: [

   BottomNavigationBarItem(
    icon: Image.asset('assets/icons/inactive/sth.png'),
    activeIcon: Image.asset('assets/icons/active/sth.png'),
    title: Text('Sth')
   ),

   BottomNavigationBarItem(
    icon: Image.asset('assets/icons/inactive/sth.png'),
    activeIcon: Image.asset('assets/icons/active/sth.png'),
    title: Text('Sth')
   ),

  ],
  onTap: (int index) {
    _currentIndex = index;
  },
  currentIndex: _currentIndex
)

Now I have some use cases where I want to display the bottomNavigationBar but none of its items should be active.

When setting the currentIndex to a non-existing index, I'm getting an error as expected.

Is there any way to achieve my goal?

Thank you in advance.

like image 341
aksn Avatar asked Sep 11 '25 14:09

aksn


1 Answers

You can try something like

bool isInactive;
BottomNavigationBar(
    type: BottomNavigationBarType.fixed,
    items: [

      BottomNavigationBarItem(
          icon: Image.asset('assets/icons/inactive/sth.png'),
          activeIcon: isInactive ? Image.asset('assets/icons/active/sth.png') : Image.asset('assets/icons/inactive/sth.png'),
          title: Text('Sth')
      ),
...
like image 171
Andrey Turkovsky Avatar answered Sep 13 '25 04:09

Andrey Turkovsky