Flutter convert to Base64 image and Display it

Flutter convert to Base64 image and Display it

Its a known issue for Flutter Camera Plugin will rotate the images 90 / 270 degree when uploading it to server or displaying it with a Image widget, like this:

The cause of the issue is due to EXIF meta embeded into the image itself with the orientation parameter,
for servers, just make sure that it handle EXIF once the image is uploaded, we won’t be digging into server end in this article.

The idea to solve this before Flutter fixing it is to convert the Image itself to base64,
hence all EXIF metas will be removed by:

await controller.takePicture(icPath).then((_) {
io.File imagefile = io.File(icPath);
List imageBytes = imagefile.readAsBytesSync();
icPicBytes = base64Encode(imageBytes);
}

Then display the image by using Image.memory:

Image.memory(base64Decode(icPicBytes))