CesareIsHere
CesareIsHere

Reputation: 233

How to handle the NetworkImage error if the URL not exists or the response is an error?

How to handle the NetworkImage error if the URL not exists or the response is an error?

I specify that i'm using NetworkImage, not Image.network, so please answer only if you have a solution for NetworkImage. Thank you!

Upvotes: 1

Views: 430

Answers (2)

IonicFireBaseApp
IonicFireBaseApp

Reputation: 1220

Use Image widget

Image(
      image: NetworkImage('Some URL'),
      errorBuilder:(context, error, stackTrace) {
           return SomeWidget();
     })

Upvotes: 2

eamirho3ein
eamirho3ein

Reputation: 17950

try this:

return Image(
      errorBuilder: (context, error, stackTrace) {
        return Container(
          height: 20,
          width: 20,
          color: Colors.red,
        );
      },
      image: const NetworkImage(
        'https://i.guim.co.uk/img/media/fe1e34da640c5c56ed16f76ce6f994fa9343d09d/0_174_3408_2046/master/3408.jpg?width=1200&height=900&quality=85&auto=format&fit=crop&s=0d3f33fb4b7713a00454c83d',
      ),
    );

Upvotes: 0

Related Questions