1

I want to load an image if only I have internet connection, if it doesn't have internet I don't want to load image?

Currently, when I open my app with no internet connection the image once fails to load an image and it won't again load image until I restart my app?

Is there any way if I can load the image back again when I reconnect to the internet?

Sonu Dhakal
  • 31
  • 1
  • 2

2 Answers2

1

Based on this answer, you can listen to internet connectivity change and try something like

bool hasConnection; 

...

if (hasConnection) {
  // reload image here
} else {
  // maybe load an image from asset?
}
CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
0

You can easily do it by using ValueKey in which current DateTime as a value

FadeInImage.assetNetwork(
                            key: ValueKey(DateTime.now()),
                            placeholder: "lib/asset/images/no_image(1).jpg",
                            image: _movies[index].data['image'],
                            fit: BoxFit.cover,
                          ),
Sonu Dhakal
  • 31
  • 1
  • 2