Home > Enterprise >  how to import a svg icon to icondata
how to import a svg icon to icondata

Time:03-24

Im new to flutter and using a plugin called FloatBoxPanel, for the property panelIcon a IconData is expected, I created a svg icon, now i dont know how to use it. directly usage will display error:

The argument type 'Icon' can't be assigned to the parameter type 'IconData'. (Documentation)
The argument type 'SvgPicture' can't be assigned to the parameter type 'IconData'. (Documentation)

Here is part of this code, plz let me know if it is possible, thank you!!

              panelIcon: Icon(SvgPicture.asset(  // panelIcon 's Type:IconData
                'assets/images/candle.svg',
                height: 20.0,
                width: 20.0,
                allowDrawingOutsideViewBox: true,
              ),),

CodePudding user response:

The type IconData has to have an Icon(). You cannot set it to an Image or Svg.

You have 2 solutions. Either use what @Thierry said by converting the Svg to an Icon or change the code in the package to support an Image instead of an Icon.

CodePudding user response:

Svg in flutter https://pub.dev/packages/flutter_svg

1.add package in pubspec.yaml

2.dependencies: flutter_svg: any

3.assets: -assets/images/

4.to insert svg.

SvgPicture.asset('assets/images/your_image.svg', width: 24, height: 29.2),

  • Related