From 0c0e6c3b99559e9b70419a7febb51b005abed95e Mon Sep 17 00:00:00 2001 From: Yousef Almutairi Date: Thu, 5 May 2022 00:12:46 +0300 Subject: [PATCH] Fixed Cannot clone a disposed image --- lib/src/blurhash_widget.dart | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/src/blurhash_widget.dart b/lib/src/blurhash_widget.dart index e218ae0..dd2ada3 100644 --- a/lib/src/blurhash_widget.dart +++ b/lib/src/blurhash_widget.dart @@ -151,8 +151,13 @@ class BlurHashState extends State { /// Decode the blurhash then display the resulting Image Widget buildBlurHashBackground() => FutureBuilder( future: _image, - builder: (ctx, snap) => - snap.hasData ? Image(image: UiImage(snap.data!), fit: widget.imageFit) : Container(color: widget.color), + builder: (ctx, snap) => snap.hasData + ? Image( + image: UiImage(snap.data!), + fit: widget.imageFit, + errorBuilder: widget.errorBuilder, + ) + : Container(color: widget.color), ); } @@ -175,7 +180,8 @@ class _DisplayImage extends StatefulWidget { _DisplayImageState createState() => _DisplayImageState(); } -class _DisplayImageState extends State<_DisplayImage> with SingleTickerProviderStateMixin { +class _DisplayImageState extends State<_DisplayImage> + with SingleTickerProviderStateMixin { late Animation opacity; late AnimationController controller; @@ -212,10 +218,12 @@ class UiImage extends ImageProvider { const UiImage(this.image, {this.scale = 1.0}); @override - Future obtainKey(ImageConfiguration configuration) => SynchronousFuture(this); + Future obtainKey(ImageConfiguration configuration) => + SynchronousFuture(this); @override - ImageStreamCompleter load(UiImage key, DecoderCallback decode) => OneFrameImageStreamCompleter(_loadAsync(key)); + ImageStreamCompleter load(UiImage key, DecoderCallback decode) => + OneFrameImageStreamCompleter(_loadAsync(key)); Future _loadAsync(UiImage key) async { assert(key == this); @@ -233,5 +241,6 @@ class UiImage extends ImageProvider { int get hashCode => hashValues(image.hashCode, scale); @override - String toString() => '$runtimeType(${describeIdentity(image)}, scale: $scale)'; + String toString() => + '$runtimeType(${describeIdentity(image)}, scale: $scale)'; }