This commit is contained in:
@@ -42,6 +42,7 @@ Future<EquatableImage?> tryDecodeImage(
|
||||
int? targetWidth,
|
||||
int? targetHeight,
|
||||
bool allowUpscaling = true,
|
||||
bool cacheResult = true,
|
||||
}) async {
|
||||
// The decode options are part of the identity of the result, not just of the
|
||||
// request: the same bytes decoded at a thumbnail's target width and at an
|
||||
@@ -55,11 +56,13 @@ Future<EquatableImage?> tryDecodeImage(
|
||||
allowUpscaling: allowUpscaling,
|
||||
);
|
||||
|
||||
final cached = _cache.get(identity);
|
||||
if (cached?.value != null) {
|
||||
return cached;
|
||||
} else if (cached != null) {
|
||||
_cache.remove(identity);
|
||||
if (cacheResult) {
|
||||
final cached = _cache.get(identity);
|
||||
if (cached?.value != null) {
|
||||
return cached;
|
||||
} else if (cached != null) {
|
||||
_cache.remove(identity);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -74,7 +77,9 @@ Future<EquatableImage?> tryDecodeImage(
|
||||
final image = EquatableImage(frameInfo.image, identity: identity);
|
||||
|
||||
if (image.value != null && image.value!.width > 0) {
|
||||
_cache.set(identity, image);
|
||||
if (cacheResult) {
|
||||
_cache.set(identity, image);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
} catch (e, s) {
|
||||
@@ -87,7 +92,9 @@ Future<EquatableImage?> tryDecodeImage(
|
||||
targetHeight: targetHeight,
|
||||
);
|
||||
if (svgImage != null) {
|
||||
_cache.set(identity, svgImage);
|
||||
if (cacheResult) {
|
||||
_cache.set(identity, svgImage);
|
||||
}
|
||||
return svgImage;
|
||||
}
|
||||
} catch (svgError, svgStackTrace) {
|
||||
|
||||
Reference in New Issue
Block a user