2

enter image description hereI try to solve the problem although the user is in offline situation, to show local image ,but I get this error.how to solve it please help me .My url is not worng but get error .

  FadeInImage(
                      height: 250,
                      width: 300,
                      // here `bytes` is a Uint8List containing the bytes for the in-memory image
                      placeholder: AssetImage('images/profile.jpg'),
                      image: NetworkImage(user?.photoUrl ?? ''),
                    ),

1 Answers1

1

... user is in offline situation, to show local image , but I get this error

The placeholder property is for while the image is loading, so after the image is fully loaded, you will still get an error in offline mode since it still tries to load a NetworkImage which won't work in offline mode.

to solve the problem, you can use an Image.network, which has an errorBuilder - and will get called if the network image isn't found, and then, you should load an Asset image.

FadeInImage(
              height: 250,
              width: 300,
              placeholder: NetworkImage('https://picsum.photos/200/300.jpg'),
              image: Image.network(
                'https://fastly.picsum.photos/id/493/200/300.jpg?hmac=grrcfhF-iSyQuaMEkd8b4OH6Gn2W3xm7dUL4-955Vxw',
                errorBuilder: (BuildContext context, Object exception,
                    StackTrace? stackTrace) {
                  return Image.asset('/path/to/image.png');
                },
              ).image)

See also

MendelG
  • 14,885
  • 4
  • 25
  • 52