createImageElementFromBase64 function

ImageElement? createImageElementFromBase64(
  1. String? base64, [
  2. String? mimeType
])

Creates an image from a Base-64 with mimeType.

Implementation

ImageElement? createImageElementFromBase64(String? base64, [String? mimeType]) {
  if (base64 == null || base64.isEmpty) return null;

  if (!base64.startsWith('data:')) {
    if (mimeType == null || mimeType.trim().isEmpty) mimeType = 'image/jpeg';
    base64 = 'data:$mimeType;base64,$base64';
  }

  var imgElement = ImageElement();
  // ignore: unsafe_html
  imgElement.src = base64;

  return imgElement;
}