App crashes when image url is not specified
Hi, I'm not sure if I should post it on stackoverflow but anyway. There is errorWidget property and I think it should work in any case when there is an error in loading network image. How can I achieve this behavior ?
Could you please explain how to catch exceptions on creation of the widget ?
Hello, same here, if the image url is not found (404) I get exception. Maybe I am wrong but I was thinking that the errorWidget must be shown and no exception. Can you help up with this?
@cosinus84 I'm having the same problem. There's an uncaught exception somewhere Unhandled Exception: HttpException: No valid statuscode. Statuscode was 404
There's already an open issue for it: #144
Because I can't wait for the fix, it seems to me that nobody answers, I can understand that is not an easy task to maintain a package. I am sure this will be fixed in the future. This worked for me, collected some ninja code :): flutter_image: 1.0.0
Image(
fit: BoxFit.cover,
width: 150,
height: 150,
image: NetworkImageWithRetry(user.profile_image,
fetchStrategy: (Uri uri, FetchFailure failure) {
if (failure != null) {
return Future<FetchInstructions>.value(
FetchInstructions.giveUp(
uri: null, alternativeImage: _getImageInfo('assets/images/profile_placeholder.png')));
} else {
return NetworkImageWithRetry.defaultFetchStrategy(
uri, failure);
}
})),
Future<ImageInfo> _getImageInfo(String imagePath) async {
ui.Image image = await loadImage(imagePath);
return ImageInfo(image: image);
}
Future<ui.Image> loadImage(String imagePath) async {
final ByteData data =
await rootBundle.load(imagePath);
List<int> img = new Uint8List.view(data.buffer);
final Completer<ui.Image> completer = new Completer();
ui.decodeImageFromList(img, (ui.Image img) {
return completer.complete(img);
});
return completer.future;
}
Hope it helps until fix is coming :)
@aerozavr, @basselch The error comes from visual code debugger, if you use flutter run from console then all works as it should. It happened to me with my own code and I posted an issue. https://github.com/flutter/flutter/issues/33427
Fixed in 1.1.0
cached_network_image: ^1.1.1

Unable to block 404