Reputation: 31
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?
Upvotes: 1
Views: 637
Reputation: 31
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,
),
Upvotes: 0
Reputation: 267684
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?
}
Upvotes: 1