소스 검색

Fix minor glitch in Gallery

Vishnu Mohandas 4 년 전
부모
커밋
cea00d8e8f
1개의 변경된 파일18개의 추가작업 그리고 8개의 파일을 삭제
  1. 18 8
      lib/ui/gallery.dart

+ 18 - 8
lib/ui/gallery.dart

@@ -72,6 +72,9 @@ class _GalleryState extends State<Gallery> {
         _saveScrollPosition();
       });
     });
+    if (widget.asyncLoader == null) {
+      _hasLoadedAll = true;
+    }
     super.initState();
   }
 
@@ -108,6 +111,7 @@ class _GalleryState extends State<Gallery> {
       return nothingToSeeHere;
     }
     _collateFiles();
+    _logger.info("Collated length " + _collatedFiles.length.toString());
     _scrollController = ScrollController(
       initialScrollOffset: _scrollOffset,
     );
@@ -146,18 +150,23 @@ class _GalleryState extends State<Gallery> {
       // Eagerly load next batch
       _loadNextItems();
     }
-    if (index == _collatedFiles.length) {
-      if (_hasLoadedAll || widget.asyncLoader == null) {
-        return Container();
-      }
-      return loadWidget;
-    }
-    var fileIndex = index;
+    var fileIndex;
     if (widget.headerWidget != null) {
       if (index == 0) {
         return widget.headerWidget;
       }
-      fileIndex--;
+      fileIndex = index - 1;
+    } else {
+      fileIndex = index;
+    }
+    if (fileIndex == _collatedFiles.length) {
+      if (widget.asyncLoader != null) {
+        if (!_hasLoadedAll) {
+          return loadWidget;
+        } else {
+          return Container();
+        }
+      }
     }
     if (fileIndex < 0 || fileIndex >= _collatedFiles.length) {
       return Container();
@@ -205,6 +214,7 @@ class _GalleryState extends State<Gallery> {
   }
 
   Widget _getGallery(List<File> files) {
+    _logger.info("Building gallery with " + files.length.toString());
     return GridView.builder(
       shrinkWrap: true,
       padding: EdgeInsets.only(bottom: 12),