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;
// delete single image from cache
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);
}