I want to check if a URL returns a valid image and if it doesn't I want to show a different image. I used CachedNetworkImage, but it didn't work.
The problem is that if the image does not exist on the website, it redirects you to one of these 'Site not found', and i think that confuses the CachedNetworkImage, so the errorWidget is not displayed.
What i want the code to do is check if the first url works, and if not display the list view with the other 2 images.
Error in console:
E/flutter ( 4808): [ERROR:flutter/lib/ui/painting/codec.cc(89)] Failed decoding image. Data is either invalid, or it is encoded using an unsupported format.
I/flutter ( 4808): Another exception was thrown: Exception: operation failed
Code is as following:
Widget _getImages(String url) {
return new CachedNetworkImage(
imageUrl: url,
placeholder: new Center(child: new CircularProgressIndicator()),
errorWidget: new ListView(
children: <Widget>[
new CachedNetworkImage(
imageUrl: url.split('.')[0] + '-0.' + url.split('.')[1],
placeholder: new Center(child: new CircularProgressIndicator()),
),
new CachedNetworkImage(
imageUrl: url.split('.')[0] + '-1.' + url.split('.')[1],
)
],
),
);
}