getImage static method
Get the image codec
This function gets the image codec of url
. It verifies if the image is
in cache and returns it if enableCache
is true. If the images is not in cache
then the function download the image and stores in cache if enableCache
is true.
Implementation
static Future<ui.Codec> getImage(String url, Duration retryDuration,
Duration maxRetryDuration, bool enableCache,
{bool clearCacheImage = false}) async {
Uint8List bytes;
if (clearCacheImage) {
await deleteHiveImage(url);
}
HiveCacheImage? cacheImage = getHiveImage(url);
if (cacheImage == null) {
bytes = await downloadImage(
url,
retryDuration,
maxRetryDuration,
);
if (bytes.lengthInBytes != 0) {
if (enableCache) saveHiveImage(url, bytes);
} else {
/// TODO
throw "Image couldn't be downloaded";
}
} else {
bytes = cacheImage.binaryImage;
}
return ui.instantiateImageCodec(bytes);
}