loadImage static method

Future<ImageElement> loadImage(
  1. dynamic url,
  2. dynamic flipY, {
  3. Function? imageDecoder,
})

Implementation

static Future<html.ImageElement> loadImage(url, flipY, {Function? imageDecoder}) {
  var completer = Completer<html.ImageElement>();
  var imageDom = html.ImageElement();
  imageDom.crossOrigin = "";

  imageDom.onLoad.listen((e) {
    completer.complete(imageDom);
  });

  if (url is Blob) {
    var blob = html.Blob([url.data.buffer], url.options["type"]);
    imageDom.src = html.Url.createObjectUrl(blob);
  } else {
    // flutter web for assets need add assets TODO
    if (url.startsWith("assets")) {
      imageDom.src = "assets/$url";
    } else {
      imageDom.src = url;
    }
  }

  return completer.future;
}