Skip to content

Commit

Permalink
fix: Fixed image cache was not working properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrunet committed Oct 26, 2023
1 parent ee1ac58 commit ad1b987
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
39 changes: 39 additions & 0 deletions packages/katana_theme/lib/src/others/asset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,19 @@ class _MemoizedNetworkImage extends network_image.NetworkImage {
}
return _ImageMemoryCache._setCache(key.url, super.load(key, decode));
}

@override
ImageStreamCompleter loadImage(
NetworkImage key, ImageDecoderCallback decode) {
if (key.url.isEmpty) {
return super.loadImage(key, decode);
}
final cache = _ImageMemoryCache._getCache(key.url);
if (cache != null) {
return cache;
}
return _ImageMemoryCache._setCache(key.url, super.loadImage(key, decode));
}
}

class _MemoizedFileImage extends FileImage {
Expand All @@ -209,6 +222,19 @@ class _MemoizedFileImage extends FileImage {
}
return _ImageMemoryCache._setCache(key.file.path, super.load(key, decode));
}

@override
ImageStreamCompleter loadImage(FileImage key, ImageDecoderCallback decode) {
if (key.file.path.isEmpty) {
return super.loadImage(key, decode);
}
final cache = _ImageMemoryCache._getCache(key.file.path);
if (cache != null) {
return cache;
}
return _ImageMemoryCache._setCache(
key.file.path, super.loadImage(key, decode));
}
}

class _MemoizedAssetImage extends AssetImage {
Expand All @@ -234,4 +260,17 @@ class _MemoizedAssetImage extends AssetImage {
}
return _ImageMemoryCache._setCache(key.name, super.load(key, decode));
}

@override
ImageStreamCompleter loadImage(
AssetBundleImageKey key, ImageDecoderCallback decode) {
if (key.name.isEmpty) {
return super.loadImage(key, decode);
}
final cache = _ImageMemoryCache._getCache(key.name);
if (cache != null) {
return cache;
}
return _ImageMemoryCache._setCache(key.name, super.loadImage(key, decode));
}
}
26 changes: 26 additions & 0 deletions packages/katana_theme/lib/src/web/asset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,19 @@ class _MemoizedNetworkImage extends network_image.NetworkImage {
}
return _ImageMemoryCache._setCache(key.url, super.load(key, decode));
}

@override
ImageStreamCompleter loadImage(
NetworkImage key, ImageDecoderCallback decode) {
if (key.url.isEmpty) {
return super.loadImage(key, decode);
}
final cache = _ImageMemoryCache._getCache(key.url);
if (cache != null) {
return cache;
}
return _ImageMemoryCache._setCache(key.url, super.loadImage(key, decode));
}
}

class _MemoizedAssetImage extends AssetImage {
Expand All @@ -204,4 +217,17 @@ class _MemoizedAssetImage extends AssetImage {
}
return _ImageMemoryCache._setCache(key.name, super.load(key, decode));
}

@override
ImageStreamCompleter loadImage(
AssetBundleImageKey key, ImageDecoderCallback decode) {
if (key.name.isEmpty) {
return super.loadImage(key, decode);
}
final cache = _ImageMemoryCache._getCache(key.name);
if (cache != null) {
return cache;
}
return _ImageMemoryCache._setCache(key.name, super.loadImage(key, decode));
}
}
2 changes: 1 addition & 1 deletion packages/katana_theme_annotation/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ packages:
path: "../katana"
relative: true
source: path
version: "2.4.2"
version: "2.4.3"
lints:
dependency: transitive
description:
Expand Down
4 changes: 2 additions & 2 deletions packages/katana_theme_builder/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,14 @@ packages:
path: "../katana"
relative: true
source: path
version: "2.4.2"
version: "2.4.3"
katana_theme_annotation:
dependency: "direct main"
description:
path: "../katana_theme_annotation"
relative: true
source: path
version: "2.0.17"
version: "2.0.19"
lints:
dependency: transitive
description:
Expand Down

0 comments on commit ad1b987

Please sign in to comment.