From 4c79c3c9029c204c8b77c591f740bcdae4198d0b Mon Sep 17 00:00:00 2001 From: Luis Nachtigall <31982496+LeLunZ@users.noreply.github.com> Date: Wed, 25 Feb 2026 23:31:37 +0100 Subject: [PATCH] feat(mobile): Prevent premature image cache eviction when higher image loading is enabled (#26208) * feat(mobile): enhance image loading with error handling and eviction options * pull request suggestions: remove log and remove useless local implementation --- .../widgets/images/image_provider.dart | 15 ++++++++++----- .../widgets/images/local_image_provider.dart | 1 - .../widgets/images/remote_image_provider.dart | 5 +++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/mobile/lib/presentation/widgets/images/image_provider.dart b/mobile/lib/presentation/widgets/images/image_provider.dart index 3c3ed460b4..c3cda46e81 100644 --- a/mobile/lib/presentation/widgets/images/image_provider.dart +++ b/mobile/lib/presentation/widgets/images/image_provider.dart @@ -48,7 +48,7 @@ mixin CancellableImageProviderMixin on CancellableImageProvide return null; } - Stream loadRequest(ImageRequest request, ImageDecoderCallback decode) async* { + Stream loadRequest(ImageRequest request, ImageDecoderCallback decode, {bool evictOnError = true}) async* { if (isCancelled) { this.request = null; PaintingBinding.instance.imageCache.evict(this); @@ -57,14 +57,19 @@ mixin CancellableImageProviderMixin on CancellableImageProvide try { final image = await request.load(decode); - if (image == null || isCancelled) { + if ((image == null && evictOnError) || isCancelled) { PaintingBinding.instance.imageCache.evict(this); return; + } else if (image == null) { + return; } yield image; - } catch (e) { - PaintingBinding.instance.imageCache.evict(this); - rethrow; + } catch (e, stack) { + if (evictOnError) { + PaintingBinding.instance.imageCache.evict(this); + rethrow; + } + _log.warning('Non-fatal image load error', e, stack); } finally { this.request = null; } diff --git a/mobile/lib/presentation/widgets/images/local_image_provider.dart b/mobile/lib/presentation/widgets/images/local_image_provider.dart index 03b9370190..1c7d102239 100644 --- a/mobile/lib/presentation/widgets/images/local_image_provider.dart +++ b/mobile/lib/presentation/widgets/images/local_image_provider.dart @@ -94,7 +94,6 @@ class LocalFullImageProvider extends CancellableImageProvider