DioImageProvider class

A custom ImageProvider implementation that uses Dio to fetch images from network URLs with automatic fallback to a local asset image when network requests fail.

This provider extends Flutter's ImageProvider to leverage Dio's advanced HTTP capabilities, including:

  • Custom interceptors for device information, timezone, and token refresh
  • Cookie storage integration (on non-web platforms)
  • Automatic error handling with graceful fallback to asset images

The provider is designed to work seamlessly with Flutter's image loading system, allowing it to be used with Image widgets or other image-consuming widgets.

Example usage:

Image(
  image: DioImageProvider(
    imageUrl: Uri.parse('https://example.com/image.jpg'),
    fallbackAssetPath: 'assets/images/placeholder.png',
  ),
)
Inheritance

Constructors

DioImageProvider({required Uri imageUrl, required String fallbackAssetPath})
Creates a new DioImageProvider instance.

Properties

dio → Dio
The Dio HTTP client instance used for network requests.
final
fallbackAssetPath String
The path to the fallback asset image that will be used if the network request fails.
final
hashCode int
Returns a hash code based on imageUrl and fallbackAssetPath.
no setteroverride
imageUrl Uri
The network URL from which to fetch the image.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

createStream(ImageConfiguration configuration) ImageStream
Called by resolve to create the ImageStream it returns.
inherited
evict({ImageCache? cache, ImageConfiguration configuration = ImageConfiguration.empty}) Future<bool>
Evicts an entry from the image cache.
inherited
loadBuffer(DioImageProvider key, DecoderBufferCallback decode) ImageStreamCompleter
Converts a key into an ImageStreamCompleter, and begins fetching the image.
inherited
loadImage(DioImageProvider key, ImageDecoderCallback decode) ImageStreamCompleter
Loads the image and returns an ImageStreamCompleter that will provide the decoded image data.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
obtainCacheStatus({required ImageConfiguration configuration, ImageErrorListener? handleError}) Future<ImageCacheStatus?>
Returns the cache location for the key that this ImageProvider creates.
inherited
obtainKey(ImageConfiguration configuration) Future<DioImageProvider>
Returns a synchronous future containing this provider instance as the key.
override
resolve(ImageConfiguration configuration) ImageStream
Resolves this image provider using the given configuration, returning an ImageStream.
inherited
resolveStreamForKey(ImageConfiguration configuration, ImageStream stream, DioImageProvider key, ImageErrorListener handleError) → void
Called by resolve with the key returned by obtainKey.
inherited
toString() String
Returns a string representation of this provider for debugging purposes.
override

Operators

operator ==(Object other) bool
Equality operator for comparing two DioImageProvider instances.
override