How to put SVG icons in flutter?
Asked Answered
V

1

9

Put this code in pubspec.yaml

flutter_svg: ^0.19.3

Even I put in assets these

assets:
     - assets\icons\logo.jpg
     - assets\icons\menuicon.svg
     - assets\icons\searchIcon.svg

In code it looks like this

IconButton(
                    icon: Icon(Icons.searchicon.svg),
                    onPressed: () {},
Vicenta answered 21/4, 2021 at 4:43 Comment(1)
Does this answer your question? Flutter SVG renderingMithraism
I
18

The Icon parameter accept any kind of widget not only Icon So you can use any widget like below

   IconButton(icon: SvgPicture.asset(
      assetName,
      color: Colors.red,
      semanticsLabel: 'Label'
    ),onPressed: () {},
Indoors answered 21/4, 2021 at 4:46 Comment(2)
The problem is we have to manually control theming on each icon. It does not inherit IconTheme class.Apelles
@HamdamMuqimov how about passing Theme.of(context).iconTheme.color for the color property?Irreproachable

© 2022 - 2024 — McMap. All rights reserved.