From d4b4acb0c5470eab47ae71bc3928075f217d31d6 Mon Sep 17 00:00:00 2001 From: Robert Magnusson Date: Wed, 10 Apr 2024 15:37:20 +0200 Subject: [PATCH] Change how errors are reported by ImageLoader. Emits as stream instead of re-throwing --- cached_network_image/CHANGELOG.md | 3 +++ cached_network_image/example/lib/main.dart | 2 +- .../lib/src/image_provider/_image_loader.dart | 4 ++-- cached_network_image/pubspec.yaml | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cached_network_image/CHANGELOG.md b/cached_network_image/CHANGELOG.md index 0d72184f..c7b6156e 100644 --- a/cached_network_image/CHANGELOG.md +++ b/cached_network_image/CHANGELOG.md @@ -1,3 +1,6 @@ +## [3.3.2] - 2024-04-10 +* Change how errors are reported by ImageLoader. Emitting errors as streams instead of re-throwing. + ## [3.3.1] - 2023-12-31 * Adding an errorListener prevents automatic reporting to global error handler. diff --git a/cached_network_image/example/lib/main.dart b/cached_network_image/example/lib/main.dart index 56007175..f09ab3f6 100644 --- a/cached_network_image/example/lib/main.dart +++ b/cached_network_image/example/lib/main.dart @@ -142,7 +142,7 @@ class BasicContent extends StatelessWidget { aspectRatio: 1.6, child: BlurHash(hash: 'LEHV6nWB2yk8pyo0adR*.7kCMdnj'), ), - imageUrl: 'https://blurha.sh/assets/images/img1.jpg', + imageUrl: 'https://blurha.sh/12c2aca29ea896a628be.jpg', fit: BoxFit.cover, ), ); diff --git a/cached_network_image/lib/src/image_provider/_image_loader.dart b/cached_network_image/lib/src/image_provider/_image_loader.dart index a7304e07..01f11ef9 100644 --- a/cached_network_image/lib/src/image_provider/_image_loader.dart +++ b/cached_network_image/lib/src/image_provider/_image_loader.dart @@ -125,14 +125,14 @@ class ImageLoader implements platform.ImageLoader { yield decoded; } } - } on Object { + } on Object catch (error, stackTrace) { // Depending on where the exception was thrown, the image cache may not // have had a chance to track the key in the cache at all. // Schedule a microtask to give the cache a chance to add the key. scheduleMicrotask(() { evictImage(); }); - rethrow; + yield* Stream.error(error, stackTrace); } finally { await chunkEvents.close(); } diff --git a/cached_network_image/pubspec.yaml b/cached_network_image/pubspec.yaml index ab9da65e..77519fb1 100644 --- a/cached_network_image/pubspec.yaml +++ b/cached_network_image/pubspec.yaml @@ -6,7 +6,7 @@ topics: - cache - image - network-image -version: 3.3.1 +version: 3.3.2 environment: sdk: ^3.0.0 flutter: '>=3.10.0'