'How to convert Uint8List to Image Data Type

The below code is converting png image to Image DataType but it is not converting SVG image to Image DataType.

var decodedImage = await decodeImageFromList(img.buffer.asUint8List()); // This is not working for SVG images.

Getting error:-

E/FlutterJNI( 9122): Failed to decode image
E/FlutterJNI( 9122): android.graphics.ImageDecoder$DecodeException: Failed to create image decoder with message 'unimplemented'Input contained an error.
E/FlutterJNI( 9122):    at android.graphics.ImageDecoder.nCreate(Native Method)
E/FlutterJNI( 9122):    at android.graphics.ImageDecoder.access$200(ImageDecoder.java:173)
E/FlutterJNI( 9122):    at android.graphics.ImageDecoder$ByteBufferSource.createImageDecoder(ImageDecoder.java:250)
E/FlutterJNI( 9122):    at android.graphics.ImageDecoder.decodeBitmapImpl(ImageDecoder.java:1862)
E/FlutterJNI( 9122):    at android.graphics.ImageDecoder.decodeBitmap(ImageDecoder.java:1855)
E/FlutterJNI( 9122):    at io.flutter.embedding.engine.FlutterJNI.decodeImage(FlutterJNI.java:431)
I/flutter ( 9122): Exception: Invalid image data


Solution 1:[1]

SVGs aren't supported in the Image class. Use flutter_svg and then pass your Uint8List to SvgPicture.memory(yourUint8List)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 a.shak