Pārlūkot izejas kodu

Precache image only if the widget is still mounted

Vishnu Mohandas 5 gadi atpakaļ
vecāks
revīzija
1d2630ecb9
1 mainītis faili ar 13 papildinājumiem un 11 dzēšanām
  1. 13 11
      lib/ui/thumbnail_widget.dart

+ 13 - 11
lib/ui/thumbnail_widget.dart

@@ -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;
+          });
+        }
       });
     }
   }