I have a Flutter app, which has a BottomNavigationBar
, and its icons are made in svg. When selecting an icon from that bar, only the text changes color, the svg icons remain the same color.
bottomNavigationBar: BottomNavigationBar(
selectedItemColor: widget._colors.orange,
unselectedItemColor: widget._colors.grey,
items: _iconNavBar,
currentIndex: _index,
type: BottomNavigationBarType.fixed,
onTap: onTap,
),
Example of how the BottomNavigationBarItem()
is doing
BottomNavigationBarItem(
icon: SvgPicture.asset(
'svgs/home.svg',
),
label: 'Home')
Just try to use activeIcon:
in bottomBarItem
and there put your default icon with colorFilter
.
Example:
Edit as 2024 because color is now deprecated
BottomNavigationBarItem(
label: 'label',
icon: SvgPicture.asset(
iconPath,
),
activeIcon: SvgPicture.asset(
iconPath,
colorFilter: ColorFilter.mode(Colors.blue, BlendMode.srcIn),
),
),
old answer:
BottomNavigationBarItem(
label: 'label',
icon: SvgPicture.asset(
iconPath,
),
activeIcon: SvgPicture.asset(
iconPath,
color: Colors.blue,
),
),