Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter how to handle Image.network error (like 404 or wrong url)

How to handle Image.network when the url is wrong or the destination leads to 404.

for example try

Image.network('https://image.tmdb.org/t/p/w92') 
like image 572
mohamed zayani Avatar asked Sep 29 '18 13:09

mohamed zayani


People also ask

How do I get the URL image in flutter?

Displaying images is fundamental for most mobile apps. Flutter provides the Image widget to display different types of images. To work with images from a URL, use the Image.network() constructor.

What is difference between NetworkImage and image network in flutter?

They are different. NetworkImage class creates an object the provides an image from the src URL passed to it. It is not a widget and does not output an image to the screen. Image.network creates a widget that displays an image on the screen.


1 Answers

I have handled the network image issue related to 404 by using an errorBuilder.

Image.network('Your image url...',     errorBuilder: (BuildContext context, Object exception, StackTrace stackTrace) {         return Text('Your error widget...');     }, ), 

errorBuilder property

like image 109
Niraj Phutane Avatar answered Oct 11 '22 13:10

Niraj Phutane