how to convert an image to base64 image in flutter?

I just changed my code as follows,

import 'dart:convert';

List<int> imageBytes = widget.fileData.readAsBytesSync();
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 the main thread

 List<int> imageBytes = await widget.fileData.readAsBytes();

Leave a Comment