discontinuedPackage layrz_theme has been discontinued and replaced by layrz_ui.

parseFileToBase64 function

Future<Map<String, String>?> parseFileToBase64(
  1. ThemedFile file
)

parseFileToBase64 is a helper function to parse a file to base64. Will return a Map with the keys:

  • 'base64' - the base64 string of the file.
  • 'name' - the name of the file.
  • 'mimeType' - the mime type of the file. And, will receive a file argument that should be a PlatformFile instance.

Implementation

Future<Map<String, String>?> parseFileToBase64(ThemedFile file) async {
  List<int> byteArray = file.bytes.toList();
  String? mimeType = file.mimeType;

  if (mimeType != null) {
    return {
      'name': file.name,
      'mimeType': mimeType,
      'base64': base64Encode(byteArray),
    };
  }

  return null;
}