flutter_cached_network_image icon indicating copy to clipboard operation
flutter_cached_network_image copied to clipboard

App crashes when image url is not specified

Open aerozavr opened this issue 7 years ago • 7 comments

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 ?

aerozavr avatar May 09 '19 08:05 aerozavr

Could you please explain how to catch exceptions on creation of the widget ?

aerozavr avatar May 10 '19 08:05 aerozavr

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 avatar May 14 '19 16:05 cosinus84

@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

bassel avatar May 19 '19 13:05 bassel

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 :)

cosinus84 avatar May 19 '19 15:05 cosinus84

@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

cosinus84 avatar May 30 '19 13:05 cosinus84

Fixed in 1.1.0

renefloor avatar Jul 15 '19 06:07 renefloor

cached_network_image: ^1.1.1

image

Unable to block 404

januwA avatar Aug 08 '19 11:08 januwA