loadImage method
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(
_SizeAwareCacheKey key, ImageDecoderCallback decode) {
Future<Codec> decodeResize(
ImmutableBuffer buffer, {
TargetImageSizeCallback? getTargetSize,
}) {
assert(
getTargetSize == null,
'ResizeImage cannot be composed with another ImageProvider that applies '
'cacheWidth, cacheHeight, or allowUpscaling.',
);
return _instantiateImageCodec(
buffer,
decode,
compressionRatio: compressionRatio,
maxBytes: maxBytes,
targetWidth: width,
targetHeight: height,
);
}
final ImageStreamCompleter completer =
imageProvider.loadImage(key._providerCacheKey, decodeResize);
if (!kReleaseMode) {
completer.debugLabel =
'${completer.debugLabel} - Resized(${key._width}×${key._height})';
}
return completer;
}