I am building an app in which I get image url from api and show them to user. This is my code:
Image.network(
news.urlToImage ??
defaultPlaceholderImageUrl,
),
Api sometimes doesn't provide url, so I displaye placeholder image, this part works fine. But I get the following error with one of the provided urls:
════════ Exception caught by image resource service ════════════════════════════════════════════════
Invalid argument(s): No host specified in URI https:////m.files.bbci.co.uk/modules/bbc-morph-sport-seo-meta/1.20.8/images/bbc-sport-logo.png
That link works in browser. But not in app. How can I solve this?
The problem was in the URL https:////m.files.bbci....
. it has 4 /
which was an invalid URL format for Image.network()
widget. So far there is no native way to catch the exception, but you can use different libraries. You can learn more about the issue and possible solutions from this post.
Flutter how to handle Image.network error (like 404 or wrong url)