I have class for images that are displayed in a listview. Sometimes the image fails and setstate does not reload the image nor any method that I have thought of works, even when assigning a unique key value.
The image class returns this code:
CachedNetworkImage(
imageUrl: widget.url,
fit: BoxFit.fitWidth,
progressIndicatorBuilder: (context, url, downloadProgress) =>
Container(
alignment: Alignment.center,
height: MediaQuery.of(context).size.height * 0.5,
width: MediaQuery.of(context).size.width,
child: CircularProgressIndicator(
value: downloadProgress.progress),
),
errorWidget: (){
return Container(
alignment: Alignment.center,
height: MediaQuery.of(context).size.height * 0.5,
width: MediaQuery.of(context).size.width,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(
Icons.perm_scan_wifi,
color: Colors.grey[600],
size: 50,
),
Padding(
padding: const EdgeInsets.only(bottom: 20, top: 25),
child: Text(
'Failed To Load Image',
style: TextStyle(color: Colors.white, fontSize: 17),
),
),
Padding(
padding: const EdgeInsets.only(
bottom: 12.0, left: 10, right: 10),
child: Text(
'Check your internet connection and try again.',
textAlign: TextAlign.center,
style: TextStyle(color: Colors.grey),
),
),
FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8)),
child: Text('Retry',
style: TextStyle(color: Colors.black)),
onPressed: () {
setState(() {});
},
color: Pigment.fromString('#FFCC00'),
)
],
),
);
},
)
Can you please propose a way to reload the image when it fails, I can only use cached network image, no other packages would be useful cuz I was the unique cache key feature.