From 93f65b750e6e244da1ed55bf9e3ada4a5c55a841 Mon Sep 17 00:00:00 2001 From: Luis Nachtigall <31982496+LeLunZ@users.noreply.github.com> Date: Sat, 26 Sep 2026 23:39:15 +0200 Subject: [PATCH] fix(mobile): make cancellation in image providers consistent (#31823) fix(mobile): handle cancellation in image providers --- .../presentation/widgets/images/image_provider.dart | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/mobile/lib/presentation/widgets/images/image_provider.dart b/mobile/lib/presentation/widgets/images/image_provider.dart index bdedd29d4..19701d7c7 100644 --- a/mobile/lib/presentation/widgets/images/image_provider.dart +++ b/mobile/lib/presentation/widgets/images/image_provider.dart @@ -98,6 +98,9 @@ mixin CancellableImageProviderMixin on CancellableImageProvide isFinished = isFinal; return codec; } catch (e) { + if (isCancelled) { + return null; + } if (isFinal) { isFinished = true; PaintingBinding.instance.imageCache.evict(this); @@ -111,16 +114,20 @@ mixin CancellableImageProviderMixin on CancellableImageProvide Stream initialImageStream() async* { final cachedOperation = this.cachedOperation; - if (cachedOperation == null) { + if (isCancelled || cachedOperation == null) { return; } try { final cachedImage = await cachedOperation.valueOrCancellation(); - if (cachedImage != null && !isCancelled) { - yield cachedImage; + if (isCancelled || cachedImage == null) { + return; } + yield cachedImage; } catch (e, stack) { + if (isCancelled) { + return; + } _log.severe('Error loading initial image', e, stack); } finally { this.cachedOperation = null;