Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Cannot clone a disposed image #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions lib/src/blurhash_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,13 @@ class BlurHashState extends State<BlurHash> {
/// Decode the blurhash then display the resulting Image
Widget buildBlurHashBackground() => FutureBuilder<ui.Image>(
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),
);
}

Expand All @@ -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<double> opacity;
late AnimationController controller;

Expand Down Expand Up @@ -212,10 +218,12 @@ class UiImage extends ImageProvider<UiImage> {
const UiImage(this.image, {this.scale = 1.0});

@override
Future<UiImage> obtainKey(ImageConfiguration configuration) => SynchronousFuture<UiImage>(this);
Future<UiImage> obtainKey(ImageConfiguration configuration) =>
SynchronousFuture<UiImage>(this);

@override
ImageStreamCompleter load(UiImage key, DecoderCallback decode) => OneFrameImageStreamCompleter(_loadAsync(key));
ImageStreamCompleter load(UiImage key, DecoderCallback decode) =>
OneFrameImageStreamCompleter(_loadAsync(key));

Future<ImageInfo> _loadAsync(UiImage key) async {
assert(key == this);
Expand All @@ -233,5 +241,6 @@ class UiImage extends ImageProvider<UiImage> {
int get hashCode => hashValues(image.hashCode, scale);

@override
String toString() => '$runtimeType(${describeIdentity(image)}, scale: $scale)';
String toString() =>
'$runtimeType(${describeIdentity(image)}, scale: $scale)';
}