convertImageAssetToString function

Future<String> convertImageAssetToString(
  1. String imagePath
)

This function converts an image asset into a base 64 encoded string. The imagePath parameter is the path to something in your assets folder, for example "assets/images/profile.jpg".

Implementation

Future<String> convertImageAssetToString(String imagePath) async {
  ByteData bytes = await rootBundle.load(imagePath);
  var buffer = bytes.buffer;
  return base64.encode(Uint8List.view(buffer));
}