fix(mobile): make cancellation in image providers consistent (#31823)

fix(mobile): handle cancellation in image providers
This commit is contained in:
Luis Nachtigall
2026-09-26 17:39:15 -04:00
committed by GitHub
parent d1faeb8199
commit 93f65b750e
@@ -98,6 +98,9 @@ mixin CancellableImageProviderMixin<T extends Object> 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<T extends Object> on CancellableImageProvide
Stream<ImageInfo> 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;