load static method Null safety

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<Map<String, dynamic>?> loadInfo =
      _channel.invokeMapMethod<String, dynamic>('loadImage', name);
  final Completer<Uint8List> bytesCompleter = Completer<Uint8List>();
  final Completer<double> scaleCompleter = Completer<double>();
  loadInfo.then((Map<String, dynamic>? map) {
    if (map == null) {
      scaleCompleter.completeError(
        Exception("Image couldn't be found: $name"),
      );
      bytesCompleter.completeError(
        Exception("Image couldn't be found: $name"),
      );
      return;
    }
    scaleCompleter.complete(map['scale']! as double);
    bytesCompleter.complete(map['data']! as Uint8List);
  });
  return _FutureMemoryImage(bytesCompleter.future, scaleCompleter.future);
}