DEV Community

loading...

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

Pratik Butani
Android Developer By Passion | Freelancer | Being Helpful By Nature | Stack-Overflowing | Fluttering | Exploring Kotlin & Flutter.
・1 min read

You can display image from assets when you found 404 or any other error while loading image.

What I have done is:

  FadeInImage(
      image: NetworkImage("imageUrl"),
      placeholder: AssetImage(
          "assets/images/placeholder.jpg"),
      imageErrorBuilder:
          (context, error, stackTrace) {
        return Image.asset(
            'assets/images/error.jpg',
            fit: BoxFit.fitWidth);
      },
      fit: BoxFit.fitWidth,
    )

Check imageErrorBuilder property.

Discussion (0)