Precache image only if the widget is still mounted

This commit is contained in:
Vishnu Mohandas 2020-08-14 04:02:54 +05:30
parent bda0d8afd9
commit 1d2630ecb9

View file

@ -121,17 +121,19 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {
_isLoadingThumbnail = true;
getThumbnailFromServer(widget.file).then((file) {
final imageProvider = Image.file(file).image;
precacheImage(imageProvider, context).then((value) {
if (mounted) {
setState(() {
_imageProvider = imageProvider;
_hasLoadedThumbnail = true;
});
}
}).catchError((e) {
_logger.severe("Could not load image " + widget.file.toString());
_encounteredErrorLoadingThumbnail = true;
});
if (mounted) {
precacheImage(imageProvider, context).then((value) {
if (mounted) {
setState(() {
_imageProvider = imageProvider;
_hasLoadedThumbnail = true;
});
}
}).catchError((e) {
_logger.severe("Could not load image " + widget.file.toString());
_encounteredErrorLoadingThumbnail = true;
});
}
});
}
}