sumseflut
sumseflut

Reputation: 678

image not found in Image.Network

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;
                  }
                }

Upvotes: 2

Views: 3102

Answers (2)

Ravindra Kushwaha
Ravindra Kushwaha

Reputation: 8032

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
                   )

Upvotes: 4

helping you
helping you

Reputation: 11

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

Upvotes: -1

Related Questions