Home > OS >  The selected icon in the bottom bar does not change
The selected icon in the bottom bar does not change

Time:02-02

I've tried a couple of options to make my icon change when it's clicked. But none of the options worked. She's just dyed blue.

Here is my first choice -

BottomNavigationBarItem(
                  icon: ImageIcon(
                    AssetImage('assets/images/home.PNG')
                  ), 
                  activeIcon: ImageIcon(
                      AssetImage('assets/images/home_color.PNG')
                  ),
                  label: "Главная",
                ),

And here is the second option -

BottomNavigationBarItem(
                  icon: selectedIndex == 0 ? ImageIcon(
                    AssetImage('assets/images/home.PNG')
                  ) : ImageIcon(
                          AssetImage('assets/images/home_color.PNG')
                      ),
                  // activeIcon: ImageIcon(
                  //     AssetImage('assets/images/home_color.PNG')
                  // ),
                  label: "Главная",
                ),

Tell me what's wrong

Here are the settings I use for the bottombar itself -

type: BottomNavigationBarType.fixed,
              currentIndex: selectedIndex,
              backgroundColor: Colors.deepPurple,
              items: <BottomNavigationBarItem>[

And full code bottom bar - https://dpaste.org/SuHuk

CodePudding user response:

Try replacing ImageIcon with Image.asset:

BottomNavigationBarItem(
    icon: Image.asset("assets/inactive_icon.png"),
    label: label,
    activeIcon: Image.asset("assets/active_icon.png"),
  );
  • Related