Reputation: 41
I need to show an image obtained from the internet(NetworkImage) and I want to validate that when the query status of that image is 404, show an image by default.
Upvotes: 0
Views: 366
Reputation: 496
Just have to use errorBuilder:
Image.network(
'https://some_url.com/some_ime.jpeg',
errorBuilder: (context, error, stack) {
if (error is NetworkImageLoadException && error.statusCode == 404) {
return Image.asset('404_image.png');
}
return Image.asset('common_error.png');
},
),
Upvotes: 1