Hi I'm learning flutter but having this problem. I'm trying change svg icon when user click on menu item but icons not changing. When click on menu item I need change icons.
class BottomNavigation extends StatefulWidget {
const BottomNavigation({
Key key,
}) : super(key: key);
@override
_BottomNavigationState createState() => _BottomNavigationState();
}
class _BottomNavigationState extends State<BottomNavigation> {
@override
Widget build(BuildContext context) {
num _currentIndex = 1;
return Container(
padding: EdgeInsets.only(
left: kDefaultPadding * 2,
right: kDefaultPadding * 2,
bottom: kDefaultPadding),
height: 90,
decoration: BoxDecoration(color: Colors.white, boxShadow: [
BoxShadow(
offset: Offset(0, -10),
blurRadius: 35,
color: kPrimaryColor.withOpacity(0.1))
]),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconButton(
icon: _currentIndex == 1
? SvgPicture.asset("assets/svg/bhomeActive.svg")
: SvgPicture.asset("assets/svg/bhome.svg"),
onPressed: () {
setState(() {
_currentIndex = 1;
});
print(_currentIndex);
}),
IconButton(
icon: _currentIndex == 5
? SvgPicture.asset("assets/svg/bprofileActive.svg")
: SvgPicture.asset("assets/svg/bprofile.svg"),
onPressed: () {
setState(() {
_currentIndex = 5;
});
print(_currentIndex);
})
],
),
);
}
}
Im doing wrong or flutter can't change svg after render?
tried with default icons also not working after state change not rendering again?
icon: _currentIndex == 1 ? Icon(Icons.work) : Icon(Icons.alarm),