loadImage static method

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

Implementation

static Future<Image?> loadImage(url, bool flipY, {Function? imageDecoder}) async {
  final Image? image;
  if (imageDecoder == null) {
    final Uint8List? bytes;
    if (url is Blob) {
      bytes = url.data;
    } else if (url.startsWith("http")) {
      final http.Response response = await http.get(Uri.parse(url));
      bytes = response.bodyBytes;
    } else if (url.startsWith("assets") || url.startsWith("packages")) {
      final ByteData fileData = await rootBundle.load(url);
      bytes = Uint8List.view(fileData.buffer);
    } else {
      final File file = File(url);
      bytes = await file.readAsBytes();
    }

    image = await compute(imageProcess2, DecodeParam(bytes!, flipY, null));
  } else {
    image = await imageDecoder(null, url);
  }

  return image;
}