flutterdartflutter-layoutuint8list

Flutter Converting String to Uint8List to use Image.memory


I had this issue in the linke below Converting String to Uint8List to use Image.memory(Uint8List uint8List)

Unfortunately I did not get helpful answers so am really desperate to resolve this issue as soon as possible.

my issue in summary is the i'm storing the images data in the database as string "[255, 216, 255, 225, 1]" and retrieving it in the same formate.

the problem is whenever i try to converted back t uint8List to use it by Image.memory(uint8List) i get this error.

E/FlutterJNI(23079): Failed to decode image
E/FlutterJNI(23079): android.graphics.ImageDecoder$DecodeException: Failed to create image decoder with message 'unimplemented'Input contained an error.
E/FlutterJNI(23079):    at android.graphics.ImageDecoder.nCreate(Native Method)
E/FlutterJNI(23079):    at android.graphics.ImageDecoder.access$200(ImageDecoder.java:169)
E/FlutterJNI(23079):    at android.graphics.ImageDecoder$ByteBufferSource.createImageDecoder(ImageDecoder.java:246)
E/FlutterJNI(23079):    at android.graphics.ImageDecoder.decodeBitmapImpl(ImageDecoder.java:1754)
E/FlutterJNI(23079):    at android.graphics.ImageDecoder.decodeBitmap(ImageDecoder.java:1747)
E/FlutterJNI(23079):    at io.flutter.embedding.engine.FlutterJNI.decodeImage(FlutterJNI.java:524)

I'm sorry for reposting this question again but I really desperate for help and I have no idea what I'm doing wrong.

any help will be appreciated, Thanks in advance.


Solution

  • Uint8List _convertListToInt(String input) {
        final reg = RegExp(r"([0-9]+|\d+)");
        final pieces = reg.allMatches(input);
        final result = pieces.map((e) => int.parse(e.group(0).toString())).toList();
    
        List<int> example = result;
    
        return Uint8List.fromList(example);
      }