Flutter_svg: Can SVG behave like an Icon and change colors?

Created on 11 May 2020  路  3Comments  路  Source: dnfield/flutter_svg

I am trying to use a SvgPicture inside BottomNavigationBar and it should change colors depending on if it's selected or unselected. This works with Icons out of the box - would it also be possible with SVG?

Most helpful comment

Alternatively you can use color passed by BottomNavigationBar from context:

BottomNavigationBarItem(
  icon: Builder(
    builder: (context) {
      return SvgPicture.asset(
        'my_icon.svg',
        color: IconTheme.of(context).color,
      );
    },
  ),
),

All 3 comments

It would be helpful to see a reproduction of what you're trying to do.

My understanding is that BottomNavigationBarItem has both an icon and activeIcon widget, and that's how that works - I don't see why SVG should need anything special for that.

Alternatively you can use color passed by BottomNavigationBar from context:

BottomNavigationBarItem(
  icon: Builder(
    builder: (context) {
      return SvgPicture.asset(
        'my_icon.svg',
        color: IconTheme.of(context).color,
      );
    },
  ),
),

Going to close this as not a bug in flutter_svg.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ChristianKleineidam picture ChristianKleineidam  路  5Comments

vanlooverenkoen picture vanlooverenkoen  路  5Comments

au-top picture au-top  路  7Comments

kentcb picture kentcb  路  4Comments

coupestartup picture coupestartup  路  6Comments