Describe the bug
I'm passing the url from one screen to another and trying to show the image with Photo_View, but keep getting the exception.
Exception has occurred.
_AssertionError ('package:flutter/src/painting/image_stream.dart': Failed assertion: line 245 pos 12: '_completer == null': is not true.)
To Reproduce
Pass a url String in arguments of Navigator.pushNamed from one screen to another.
Class that shows the image:
class _ImageZoomState extends State<ImageZoom> {
String url;
@override
Widget build(BuildContext context) {
Map data = ModalRoute.of(context).settings.arguments;
url = data['url'];
return Scaffold(
appBar: AppBar(
title: Text('Image'),
),
body: Container(
child: Center(child: PhotoView(imageProvider: NetworkImage(url)))),
);
}
}
What is the current behavior?
Exception occurs.
Expected behavior
Should show a network image.
Which versions of Flutter/Photo View, and which browser / OS are affected by this issue? Did this work in previous versions of Photo View?
Flutter doctor:
[✓] Flutter (Channel master, 1.22.0-10.0.pre.200, on Mac OS X 10.15.4 19E287, locale en-KG)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 11.6)
[✓] Android Studio (version 4.0)
[✓] Connected device (2 available)
• No issues found!
I solved the issue by extracting local variable like so:
var photoView = PhotoView(
imageProvider: NetworkImage(url),
backgroundDecoration: BoxDecoration(color: Colors.white),
);
return Scaffold(
appBar: AppBar(
title: Text('Image'),
),
body: Container(child: Center(child: photoView)),
);
Edit. The above mentioned solution didn't help. I still keep getting this error for some reason.
@renancaraujo Hello. any update on this?
Encounter same issue. Any update?
@UlanNurmatov U can try replace NetworkImage with CachedNetworkImageProvider(https://pub.dev/packages/cached_network_image) as temporary solution, which works in my case.
Having the same problem, unfortunately...
I'm using the gallery option and had the same issue. I used the ChachedNetworkImage inside the customChild and it solved the error.
PhotoViewGalleryPageOptions _buildItem(BuildContext context, int index) {
final String imageUrl = widget.galleryItems[index]['imageUrl'];
return PhotoViewGalleryPageOptions.customChild(
child: Container(
child: CachedNetworkImage(
imageUrl: imageUrl,
),
),
initialScale: PhotoViewComputedScale.contained,
minScale: PhotoViewComputedScale.contained * (0.5 + index / 10),
maxScale: PhotoViewComputedScale.covered * 4.1,
heroAttributes: PhotoViewHeroAttributes(tag: imageUrl),
);
}
Most helpful comment
Having the same problem, unfortunately...