image property

Future<Image> get image

Returns an ui.Image object containing the image data from this object.

Implementation

Future<ui.Image> get image async {
  // Used to convert listener callback to future
  final completer = Completer<ui.Image>();

  // Resolve the image as an [ImageStream] and listen to the stream
  resolve(ImageConfiguration.empty)
      .addListener(ImageStreamListener((info, _) {
    // Assign the [ui.Image] from the image information streamed as the completer value
    // When the image from the stream arrives, the completer is completed
    completer.complete(info.image);
  }));

  // Wait for the image data from the completer to arrive from the callback
  return await completer.future;
}