I have the following code in my widget build method:
return CustomStyle(
body: Scaffold(
backgroundColor: Colors.transparent,
body: Center(
child: _widgetOptions.elementAt(_selectedIndex),
),
bottomNavigationBar: SizedBox(
child: BottomNavigationBar(
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Image(
height: screenWidth * 0.1,
width: screenWidth * 0.1,
image: const Svg("lib/assets/images/icons/home.svg")),
label: 'Home',
),
BottomNavigationBarItem(
icon: ImageIcon(
const AssetImage("lib/assets/images/learnIcon.png"),
size: screenWidth * 0.1),
label: 'Learn',
),
],
currentIndex: _selectedIndex,
selectedItemColor: const Color(0xFFF24949),
onTap: _onItemTapped,
unselectedItemColor: Colors.white,
selectedLabelStyle: TextStyle(
color: const Color(0xFFF24949),
),
unselectedLabelStyle: TextStyle(
color: Colors.white,
),
),
),
));
selectedItemColor is working correctly for the 2nd BottomNavigationBarItem in which I am rendering icon using AssetImage with a png. However, it does not work for the 1st one where I am using svg. Screenshots of both below. in which one, i expected the home label and icon to be orange.
In the 2nd one, they are correctly both orange.
I have tried using both flutter_svg_provider
as well as flutter_svg
packages, same issue in both.
Kindly help someone!
2
Answers
This worked for me.
selectedItemColor
andselectedLabelStyle
have not effect on the SVGs.selectedItemColor of the bottomNavigationBar does not affect Svg.
I use package flutter_svg
Here is a workaround: