how to convert an image to base64 image in flutter?

前端 未结 2 1572
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-01 09:35

I am actually trying to convert an image picked by ImagePicker in flutter to base64 image. I am always getting the error.

FileSyst         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-01 10:04

    hi I just changed my code as follows,

    List imageBytes = widget.fileData.readAsBytesSync();
    print(imageBytes);
    String base64Image = base64Encode(imageBytes);
    

    and this is working fine now.

    It is better to read it asynchronously as the image can be very large which may cause blocking of main thread

     List imageBytes = await widget.fileData.readAsBytes();
    

提交回复
热议问题