Skip to content

Image.network handle bad url image, like 404 #34451

Closed

Description

@cosinus84

The code below still shows as an exception. This is a very common situation.

 Image.network("${image}x",
                    fit: BoxFit.cover,
                    width: 150,
                    height: 150, loadingBuilder: (BuildContext context,
                        Widget child, ImageChunkEvent loadingProgress) {
                  if (loadingProgress == null) {
                    return child;
                  }
                  return Platform.isIOS
                      ? CupertinoActivityIndicator(radius: 20)
                      : CircularProgressIndicator();
                });
              } catch(_) {
                return Container();
              }

[✓] Flutter (Channel dev, v1.7.3, on Mac OS X 10.14.5 18F132, locale en-RO)
• Flutter version 1.7.3 at /Users/devx/flutter
• Framework revision 362b999 (6 days ago), 2019-06-07 12:43:27 -0700
• Engine revision 0602dbb
• Dart version 2.3.2 (build 2.3.2-dev.0.1 6e0d978505)

Activity

  1. The-Redhat commented on Jun 14, 2019

    @The-Redhat
    Contributor

    You can use preCacheImage to handle errors. Run it before creating your Image Widget.

  2. cosinus84 commented on Jun 14, 2019

    @cosinus84
    Author

    I will use what you suggested but this is not what you expect from all million examples out there on how easy is to show an image from network with flutter.
    I think this should be fixed on the Image.network. This issue is very important and should be fixed so you easily show a list of images without doing other kind of magic.

  3. The-Redhat commented on Jun 14, 2019

    @The-Redhat
    Contributor

    Yes I share your opinion. But my issue regarding this problem was closed with no comments. Flutter should definitely provide a better way of error handling for images.

  4. cosinus84 commented on Jun 14, 2019

    @cosinus84
    Author

    Btw, thanks :)

  5. mikhail-tokarev commented on Oct 8, 2019

    @mikhail-tokarev

    HI @cosinus84
    given your last message I feel safe to close this issue,
    if you disagree please write in the comments
    and I will reopen it

  6. henperi commented on Nov 6, 2019

    @henperi

    I'm having the same issue. Can someone please share his/her implementation if possible?

  7. chornbe commented on Feb 27, 2020

    @chornbe

    Why in the world doesn't this provide some way to gracefully capture the exception and just provide some other optional image, akin to loadingBuilder. Why wouldn't there be something like exceptionBuilder:... or something?

    Especially when stuffing the widget into a big build block that you may or may not be able or willing to otherwise break up into small parts. Maybe I'll circle back and add it to the core code after I get this project done; I don't have time at the moment. :(

  8. alexgarciaju commented on Apr 9, 2020

    @alexgarciaju

    @mikhail-tokarev this issue is still happening

  9. lock commented on Apr 25, 2020

    @lock

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  10. locked and limited conversation to collaborators on Apr 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions