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!
CodePudding user response:
Use Image widget
Image(
image: NetworkImage('Some URL'),
errorBuilder:(context, error, stackTrace) {
return SomeWidget();
})
CodePudding user response:
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',
),
);