From 5a6891750033d44508d4b48ee2269591f7e47d10 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Thu, 29 Jun 2023 14:38:02 +0200 Subject: [PATCH] neon: require key for NeonCachedImage --- .../neon/lib/src/widgets/cached_image.dart | 61 ++++++++++--------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/packages/neon/neon/lib/src/widgets/cached_image.dart b/packages/neon/neon/lib/src/widgets/cached_image.dart index d2c7cade..ed3a7a62 100644 --- a/packages/neon/neon/lib/src/widgets/cached_image.dart +++ b/packages/neon/neon/lib/src/widgets/cached_image.dart @@ -7,12 +7,12 @@ typedef APIImageDownloader = Future Function(); class NeonCachedImage extends StatefulWidget { const NeonCachedImage._({ required this.getImageFile, + required Key super.key, this.isSvgHint = false, this.size, this.fit, this.svgColor, this.iconColor, - super.key, }); factory NeonCachedImage.url({ @@ -33,7 +33,7 @@ class NeonCachedImage extends StatefulWidget { fit: fit, svgColor: svgColor, iconColor: iconColor, - key: key, + key: key ?? Key(url), ); factory NeonCachedImage.api({ @@ -46,34 +46,35 @@ class NeonCachedImage extends StatefulWidget { final Color? svgColor, final Color? iconColor, final Key? key, - }) => - NeonCachedImage._( - getImageFile: () async { - final realKey = '${account.id}-$cacheKey'; - final cacheFile = await _cacheManager.getFileFromCache(realKey); - if (cacheFile != null && cacheFile.validTill.isAfter(DateTime.now())) { - return cacheFile.file.readAsBytes(); - } - - final file = await download(); - - unawaited( - _cacheManager.putFile( - realKey, - file, - maxAge: const Duration(days: 7), - eTag: etag, - ), - ); - - return file; - }, - size: size, - fit: fit, - svgColor: svgColor, - iconColor: iconColor, - key: key, - ); + }) { + final realKey = '${account.id}-$cacheKey'; + return NeonCachedImage._( + getImageFile: () async { + final cacheFile = await _cacheManager.getFileFromCache(realKey); + if (cacheFile != null && cacheFile.validTill.isAfter(DateTime.now())) { + return cacheFile.file.readAsBytes(); + } + + final file = await download(); + + unawaited( + _cacheManager.putFile( + realKey, + file, + maxAge: const Duration(days: 7), + eTag: etag, + ), + ); + + return file; + }, + size: size, + fit: fit, + svgColor: svgColor, + iconColor: iconColor, + key: key ?? Key(realKey), + ); + } final Future Function() getImageFile; final bool isSvgHint;