ScrollAwareImageProvider<T extends Object> class

An ImageProvider that makes use of Scrollable.recommendDeferredLoadingForContext to avoid loading images when rapidly scrolling.

This provider assumes that its wrapped imageProvider correctly uses the ImageCache, and does not attempt to re-acquire or decode images in the cache.

Calling resolve on this provider will cause it to obtain the image key and then check the following:

  1. If the returned ImageStream has been completed, end. This can happen if the caller sets the completer on the stream.
  2. If the ImageCache has a completer for the key for this image, ask the wrapped provider to resolve. This can happen if the image was precached, or another ImageProvider already resolved the same image.
  3. If the context has been disposed, end. This can happen if the caller has been disposed and is no longer interested in resolving the image.
  4. If the widget is scrolling with high velocity at this point in time, wait until the beginning of the next frame and go back to step 1.
  5. Delegate loading the image to the wrapped provider and finish.

If the cycle ends at steps 1 or 3, the ImageStream will never be marked as complete and listeners will not be notified.

The Image widget wraps its incoming providers with this provider to avoid overutilization of resources for images that would never appear on screen or only be visible for a very brief period.



ScrollAwareImageProvider({required DisposableBuildContext<State<StatefulWidget>> context, required ImageProvider<T> imageProvider})
Creates a ScrollAwareImageProvider.


context DisposableBuildContext<State<StatefulWidget>>
The context that may or may not be enclosed by a Scrollable.
hashCode int
The hash code for this object.
no setterinherited
imageProvider ImageProvider<T>
The wrapped image provider to delegate obtainKey and loadImage to.
runtimeType Type
A representation of the runtime type of the object.
no setterinherited


createStream(ImageConfiguration configuration) ImageStream
Called by resolve to create the ImageStream it returns.
evict({ImageCache? cache, ImageConfiguration configuration = ImageConfiguration.empty}) Future<bool>
Evicts an entry from the image cache.
loadBuffer(T key, DecoderBufferCallback decode) ImageStreamCompleter
Converts a key into an ImageStreamCompleter, and begins fetching the image.
loadImage(T key, ImageDecoderCallback decode) ImageStreamCompleter
Converts a key into an ImageStreamCompleter, and begins fetching the image.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
obtainCacheStatus({required ImageConfiguration configuration, ImageErrorListener? handleError}) Future<ImageCacheStatus?>
Returns the cache location for the key that this ImageProvider creates.
obtainKey(ImageConfiguration configuration) Future<T>
Converts an ImageProvider's settings plus an ImageConfiguration to a key that describes the precise image to load.
resolve(ImageConfiguration configuration) ImageStream
Resolves this image provider using the given configuration, returning an ImageStream.
resolveStreamForKey(ImageConfiguration configuration, ImageStream stream, T key, ImageErrorListener handleError) → void
Called by resolve with the key returned by obtainKey.
toString() String
A string representation of this object.


operator ==(Object other) bool
The equality operator.