From 32e2c08a5eaa629ec9cf68e737b387d64786e689 Mon Sep 17 00:00:00 2001 From: rwolfing Date: Wed, 29 Nov 2023 11:13:38 +0900 Subject: [PATCH] Add missing error listener --- .../cached_network_image_provider.dart | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/cached_network_image/lib/src/image_provider/cached_network_image_provider.dart b/cached_network_image/lib/src/image_provider/cached_network_image_provider.dart index 48136e0a..bc594abd 100644 --- a/cached_network_image/lib/src/image_provider/cached_network_image_provider.dart +++ b/cached_network_image/lib/src/image_provider/cached_network_image_provider.dart @@ -74,7 +74,7 @@ class CachedNetworkImageProvider DecoderBufferCallback decode, ) { final chunkEvents = StreamController(); - return MultiImageStreamCompleter( + final imageStreamCompleter = MultiImageStreamCompleter( codec: _loadBufferAsync(key, chunkEvents, decode), chunkEvents: chunkEvents.stream, scale: key.scale, @@ -86,6 +86,19 @@ class CachedNetworkImageProvider ); }, ); + + if (errorListener != null) { + imageStreamCompleter.addListener( + ImageStreamListener( + (image, synchronousCall) {}, + onError: (Object error, StackTrace? trace) { + errorListener?.call(error); + }, + ), + ); + } + + return imageStreamCompleter; } @Deprecated('_loadBufferAsync is deprecated, use _loadImageAsync instead') @@ -116,7 +129,7 @@ class CachedNetworkImageProvider ImageDecoderCallback decode, ) { final chunkEvents = StreamController(); - return MultiImageStreamCompleter( + final imageStreamCompleter = MultiImageStreamCompleter( codec: _loadImageAsync(key, chunkEvents, decode), chunkEvents: chunkEvents.stream, scale: key.scale, @@ -128,6 +141,19 @@ class CachedNetworkImageProvider ); }, ); + + if (errorListener != null) { + imageStreamCompleter.addListener( + ImageStreamListener( + (image, synchronousCall) {}, + onError: (Object error, StackTrace? trace) { + errorListener?.call(error); + }, + ), + ); + } + + return imageStreamCompleter; } Stream _loadImageAsync(