MultiFrameImageStreamCompleter constructor

MultiFrameImageStreamCompleter(
  1. {@required Future<Codec> codec,
  2. @required double scale,
  3. Stream<ImageChunkEvent> chunkEvents,
  4. InformationCollector informationCollector}
)

Creates a image stream completer.

Immediately starts decoding the first image frame when the codec is ready.

The codec parameter is a future for an initialized ui.Codec that will be used to decode the image.

The scale parameter is the linear scale factor for drawing this frames of this image at their intended size.

The chunkEvents parameter is an optional stream of notifications about the loading progress of the image. If this stream is provided, the events produced by the stream will be delivered to registered ImageChunkListeners (see addListener).

Implementation

MultiFrameImageStreamCompleter({
  @required Future<ui.Codec> codec,
  @required double scale,
  Stream<ImageChunkEvent> chunkEvents,
  InformationCollector informationCollector,
}) : assert(codec != null),
     _informationCollector = informationCollector,
     _scale = scale {
  codec.then<void>(_handleCodecReady, onError: (dynamic error, StackTrace stack) {
    reportError(
      context: ErrorDescription('resolving an image codec'),
      exception: error,
      stack: stack,
      informationCollector: informationCollector,
      silent: true,
    );
  });
  if (chunkEvents != null) {
    chunkEvents.listen(
      (ImageChunkEvent event) {
        if (hasListeners) {
          // Make a copy to allow for concurrent modification.
          final List<ImageChunkListener> localListeners = _listeners
              .map<ImageChunkListener>((ImageStreamListener listener) => listener.onChunk)
              .where((ImageChunkListener chunkListener) => chunkListener != null)
              .toList();
          for (final ImageChunkListener listener in localListeners) {
            listener(event);
          }
        }
      }, onError: (dynamic error, StackTrace stack) {
        reportError(
          context: ErrorDescription('loading an image'),
          exception: error,
          stack: stack,
          informationCollector: informationCollector,
          silent: true,
        );
      },
    );
  }
}