resolveStreamForKey method

  1. @protected
void resolveStreamForKey (
  1. ImageConfiguration configuration,
  2. ImageStream stream,
  3. T key,
  4. ImageErrorListener handleError
)
@protected

Called by resolve with the key returned by obtainKey.

Subclasses should override this method rather than calling obtainKey if they need to use a key directly. The resolve method installs appropriate error handling guards so that errors will bubble up to the right places in the framework, and passes those guards along to this method via the handleError parameter.

It is safe for the implementation of this method to call handleError multiple times if multiple errors occur, or if an error is thrown both synchronously into the current part of the stack and thrown into the enclosing Zone.

The default implementation uses the key to interact with the ImageCache, calling ImageCache.putIfAbsent and notifying listeners of the stream. Implementers that do not call super are expected to correctly use the ImageCache.

Implementation

@protected
void resolveStreamForKey(ImageConfiguration configuration, ImageStream stream, T key, ImageErrorListener handleError) {
  // This is an unusual edge case where someone has told us that they found
  // the image we want before getting to this method. We should avoid calling
  // load again, but still update the image cache with LRU information.
  if (stream.completer != null) {
    final ImageStreamCompleter completer = PaintingBinding.instance.imageCache.putIfAbsent(
      key,
      () => stream.completer,
      onError: handleError,
    );
    assert(identical(completer, stream.completer));
    return;
  }
  final ImageStreamCompleter completer = PaintingBinding.instance.imageCache.putIfAbsent(
    key,
    () => load(key, PaintingBinding.instance.instantiateImageCodec),
    onError: handleError,
  );
  if (completer != null) {
    stream.setCompleter(completer);
  }
}