load static method

ImageProvider<Object> load(
  1. String name
)

Loads an image from asset catalogs. The equivalent would be: [UIImage imageNamed:name].

Throws an exception if the image can't be found.

See https://developer.apple.com/documentation/uikit/uiimage/1624146-imagenamed?language=objc

Implementation

static ImageProvider load(String name) {
  final Future<PlatformImageData?> imageData = _hostApi.loadImage(name);
  final Completer<Uint8List> bytesCompleter = Completer<Uint8List>();
  final Completer<double> scaleCompleter = Completer<double>();
  imageData.then((PlatformImageData? image) {
    if (image == null) {
      scaleCompleter.completeError(
        Exception("Scale couldn't be found to load image: $name"),
      );
      bytesCompleter.completeError(
        Exception("Image couldn't be found: $name"),
      );
      return;
    }
    scaleCompleter.complete(image.scale);
    bytesCompleter.complete(image.data);
  });
  return _FutureMemoryImage(bytesCompleter.future, scaleCompleter.future);
}