LocalOrCachedNetworkImageProvider class
An ImageProvider for loading image from local file or network using a cache.
Some tips of parameters:
-
At lease one of file and url (or fileFuture and urlFuture, or file and url results of these two futures) must be non-null value, otherwise argument error will be thrown.
-
If given file (or result of fileFuture) is not null and exists, this provider will try to load image from this file, this also means local image has a higher priority than network image.
-
If given file is not null but does not exist, behavior will be depended by fileMustExist. Exception
Image file "xxx" is not found.
will be thrown if fileMustExist is true, otherwise url will be used as fallback. -
If given file is null or url is decided to be used, while given url (or result of urlFuture) is not null, this provider will try to load image from this web url, invalid format exception or network error exception may be thrown here.
-
If given file is null or not exists, while url is null (not include invalid format exceptions), this provider will throw an exception
Image file "xxx" is not found while given url is null.
-
Only file (or fileFuture), url (or urlFuture), scale, maxWidth, maxHeight will be used to determine whether it represents the same image.
- Inheritance
-
- Object
- ImageProvider<
LocalOrCachedNetworkImageProvider> - LocalOrCachedNetworkImageProvider
Constructors
-
LocalOrCachedNetworkImageProvider({Key? key, required File? file, required String? url, double? scale = 1.0, bool fileMustExist = true, Map<
String, String> ? headers, BaseCacheManager? cacheManager, String? cacheKey, int? maxWidth, int? maxHeight, bool asyncHeadFirst = false, Duration? networkTimeout, void onFileLoading()?, void onUrlLoading()?, void onFileLoaded(Object? err)?, void onUrlLoaded(Object? err)?}) -
Creates LocalOrCachedNetworkImageProvider with nullable file and url.
const
-
LocalOrCachedNetworkImageProvider.fromFutures({Key? key, required Future<
File?> ? fileFuture, required Future<String?> ? urlFuture, double? scale = 1.0, bool fileMustExist = true, Map<String, String> ? headers, BaseCacheManager? cacheManager, String? cacheKey, int? maxWidth, int? maxHeight, bool asyncHeadFirst = false, Duration? networkTimeout, void onFileLoading()?, void onUrlLoading()?, void onFileLoaded(Object? err)?, void onUrlLoaded(Object? err)?}) -
Creates LocalOrCachedNetworkImageProvider with nullable fileFuture and urlFuture.
const
- LocalOrCachedNetworkImageProvider.fromLocal({Key? key, required File file, double? scale = 1.0, bool fileMustExist = true, void onFileLoading()?, void onFileLoaded(Object? err)?})
-
Creates LocalOrCachedNetworkImageProvider with non-null file only.
const
-
LocalOrCachedNetworkImageProvider.fromLocalWithFuture({Key? key, required Future<
File?> fileFuture, double? scale = 1.0, bool fileMustExist = true, void onFileLoading()?, void onFileLoaded(Object? err)?}) -
Creates LocalOrCachedNetworkImageProvider with non-null fileFuture only.
const
-
LocalOrCachedNetworkImageProvider.fromNetwork({Key? key, required String url, double? scale = 1.0, Map<
String, String> ? headers, BaseCacheManager? cacheManager, String? cacheKey, int? maxWidth, int? maxHeight, bool asyncHeadFirst = false, Duration? networkTimeout, void onUrlLoading()?, void onUrlLoaded(Object? err)?}) -
Creates LocalOrCachedNetworkImageProvider with non-null url only.
const
-
LocalOrCachedNetworkImageProvider.fromNetworkWithFuture({Key? key, required Future<
String?> urlFuture, double? scale = 1.0, Map<String, String> ? headers, BaseCacheManager? cacheManager, String? cacheKey, int? maxWidth, int? maxHeight, bool asyncHeadFirst = false, Duration? networkTimeout, void onUrlLoading()?, void onUrlLoaded(Object? err)?}) -
Creates LocalOrCachedNetworkImageProvider with non-null urlFuture only.
const
Properties
- asyncHeadFirst → bool
-
The flag to check whether need to send HEAD request asynchronously to get network image's
real size, defaults to false.
final
- cacheKey → String?
-
The cache key for network image and will be stored in cacheManager, defaults to url
or urlFuture itself.
final
- cacheManager → BaseCacheManager?
-
The cache manager which is used to check whether network image has already been loaded.
final
- file → File?
-
The local file of the image to load.
final
-
fileFuture
→ Future<
File?> ? -
The local file future of the image to load.
final
- fileMustExist → bool
-
The flag to decide whether to throw exception or use url as fallback, when given
file does not exist, defaults to true.
final
- hashCode → int
-
The hash code for this object.
no setteroverride
-
headers
→ Map<
String, String> ? -
The headers for requesting network image, such as "Authorization" and "Referer".
final
- key → Key?
-
The key that can be used to reload the image in force when different Key passed.
final
- maxHeight → int?
-
If this value is not null and
ImageCacheManager
is used, the image will be resized on disk to fit the height. This value will be ignored if a normal cacheManager is used.final - maxWidth → int?
-
If this value is not null and
ImageCacheManager
is used, the image will be resized on disk to fit the width. This value will be ignored if a normal cacheManager is used.final - networkTimeout → Duration?
-
The timeout duration for network image loading, defaults to null, which means not to check.
final
- onFileLoaded → (void Function(Object? err)?)
-
The callback function to be called when the local image finished loading. Here null
err
represents it succeeded, otherwise represents it failed.final - onFileLoading → (void Function()?)
-
The callback function to be called when the local image starts to load.
final
- onUrlLoaded → (void Function(Object? err)?)
-
The callback function to be called when the network image finished loading. Here null
err
represents it succeeded, otherwise represents it failed.final - onUrlLoading → (void Function()?)
-
The callback function to be called when the network image starts to load.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scale → double?
-
The scale of the image, defaults to 1.0.
final
- url → String?
-
The web url of the image to load.
final
-
urlFuture
→ Future<
String?> ? -
The web url future of the image to load.
final
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
-
load(
LocalOrCachedNetworkImageProvider key, dynamic decode) → ImageStreamCompleter -
loadBuffer(
LocalOrCachedNetworkImageProvider key, DecoderBufferCallback decode) → ImageStreamCompleter -
Converts a key into an ImageStreamCompleter, and begins fetching the
image.
inherited
-
loadImage(
LocalOrCachedNetworkImageProvider key, ImageDecoderCallback decode) → ImageStreamCompleter -
Converts a key into an ImageStreamCompleter, and begins fetching the
image.
inherited
-
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< LocalOrCachedNetworkImageProvider> -
Converts an ImageProvider's settings plus an ImageConfiguration to a key
that describes the precise image to load.
override
-
resolve(
ImageConfiguration configuration) → ImageStream -
Resolves this image provider using the given
configuration
, returning an ImageStream.inherited -
resolveStreamForKey(
ImageConfiguration configuration, ImageStream stream, LocalOrCachedNetworkImageProvider key, ImageErrorListener handleError) → void -
Called by resolve with the key returned by obtainKey.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
dynamic other) → bool -
The equality operator.
override