2

in my app i have ListTile where i show my images but how can i change my images url if i have 404 error, on default image, cuz if i get 404 i have white screen in image, i trying this:

                String imageURL = 'someURL';
                String imageUrlDef = 'defaulURL';
                String url = imageUrlDef;

                Future checkImg() async{
                  var response = await http.get(imageURL);

                  if(response.statusCode == 200){
                    url = imageURL;
                  }
                }
0

2 Answers 2

4

You can use CachedNetworkImage library for the check Image availability on the server or not ,if there is image not available on server then ,it redirect you to the errorWidget where you can create your Error widget as you want , below is the example of it, please check it once

 CachedNetworkImage(
      imageUrl: "https://picsum.photos/250?image=9",
      placeholder: (context, url) => new CircularProgressIndicator(),
      errorWidget: (context, url, error) => new Icon(Icons.error),  //// YOU CAN CREATE YOUR OWN ERROR WIDGET HERE
                   )
Sign up to request clarification or add additional context in comments.

1 Comment

Happy to help you man!! Keep happy coding :) And thank you very much for your lovely words :)
-1

Try to open the Image in a new Tab, because Flutter may not recognise the Image in the Website.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.