loadImage method

  1. @override
ImageStreamCompleter loadImage(
  1. DiskImage key,
  2. ImageDecoderCallback decode
)
override

Converts a key into an ImageStreamCompleter, and begins fetching the image.

For backwards-compatibility the default implementation of this method returns an object that will cause resolveStreamForKey to consult loadBuffer. However, implementors of this interface should only override this method and not loadBuffer, which is deprecated.

The decode callback provides the logic to obtain the codec for the image.

See also:

  • ResizeImage, for modifying the key to account for cache dimensions.

Implementation

@override
ImageStreamCompleter loadImage(DiskImage key, ImageDecoderCallback decode) {
  // The image cache drops entries on its own; forget those keys too, so a
  // long-running gallery doesn't grow this set without bound.
  if (_loaded.length >= 512) {
    final ImageCache cache = PaintingBinding.instance.imageCache;
    _loaded.removeWhere((loaded) => !cache.containsKey(loaded));
  }
  _loaded.add(key);
  return MultiFrameImageStreamCompleter(
    codec: _load(key, decode),
    scale: key.scale,
    debugLabel: 'DiskImage(${key.disk}:${key.path})',
    informationCollector: () => <DiagnosticsNode>[
      DiagnosticsProperty<ImageProvider>('Image provider', this),
      DiagnosticsProperty<DiskImage>('Image key', key),
    ],
  );
}