Search code examples
flutterdartsvgassets

How to use jovial_svg with assets


I was using jovial_svg library for fetching svg from internet because my svg files looks corrupted with flutter_svg library. Now I want to use jovial_svg library for my files which are in my assets folder.

I tried

ScalableImageSource.fromSvg()

but i didn't make it.


Solution

  • You can do like this

    ScalableImageWidget.fromSISource(
          si: ScalableImageSource.fromSvg(
            MySVG(imagePath: image.svg),
            'key',
            compact: true,
          ),
        ),
    
    class MySVG extends AssetBundle {
      final String imagePath;
      MySVG({required this.imagePath});
      @override
      Future<ByteData> load(String key) async {
        // TODO: implement load
        return await rootBundle.load(imagePath);
      }
    
      @override
      Future<T> loadStructuredData<T>(
          String key, Future<T> Function(String value) parser) {
        // TODO: implement loadStructuredData
        throw UnimplementedError();
      }
    }