Browse Source

Fix swipe behavior

Vishnu 4 years ago
parent
commit
4656340a68
1 changed files with 12 additions and 9 deletions
  1. 12 9
      lib/ui/detail_page.dart

+ 12 - 9
lib/ui/detail_page.dart

@@ -70,7 +70,7 @@ class _DetailPageState extends State<DetailPage> {
   void initState() {
   void initState() {
     _files = widget.config.files;
     _files = widget.config.files;
     _selectedIndex = widget.config.selectedIndex;
     _selectedIndex = widget.config.selectedIndex;
-    _preloadEntries(_selectedIndex);
+    _preloadEntries();
     super.initState();
     super.initState();
   }
   }
 
 
@@ -161,7 +161,7 @@ class _DetailPageState extends State<DetailPage> {
           _selectedIndex = index;
           _selectedIndex = index;
           _hasPageChanged = true;
           _hasPageChanged = true;
         });
         });
-        _preloadEntries(index);
+        _preloadEntries();
         _preloadFiles(index);
         _preloadFiles(index);
       },
       },
       physics: _shouldDisableScroll
       physics: _shouldDisableScroll
@@ -187,11 +187,13 @@ class _DetailPageState extends State<DetailPage> {
     });
     });
   }
   }
 
 
-  void _preloadEntries(int index) async {
-    if (index == 0 && !_hasLoadedTillStart) {
+  void _preloadEntries() async {
+    if (_selectedIndex == 0 && !_hasLoadedTillStart) {
       final result = await widget.config.asyncLoader(
       final result = await widget.config.asyncLoader(
-          _files[index].creationTime + 1, DateTime.now().microsecondsSinceEpoch,
-          limit: kLoadLimit, asc: true);
+          _files[_selectedIndex].creationTime + 1,
+          DateTime.now().microsecondsSinceEpoch,
+          limit: kLoadLimit,
+          asc: true);
       setState(() {
       setState(() {
         final files = result.files.reversed.toList();
         final files = result.files.reversed.toList();
         if (!result.hasMore) {
         if (!result.hasMore) {
@@ -204,9 +206,10 @@ class _DetailPageState extends State<DetailPage> {
         _selectedIndex = length;
         _selectedIndex = length;
       });
       });
     }
     }
-    if (index == _files.length - 1 && !_hasLoadedTillEnd) {
-      final result = await widget.config
-          .asyncLoader(0, _files[index].creationTime - 1, limit: kLoadLimit);
+    if (_selectedIndex == _files.length - 1 && !_hasLoadedTillEnd) {
+      final result = await widget.config.asyncLoader(
+          0, _files[_selectedIndex].creationTime - 1,
+          limit: kLoadLimit);
       setState(() {
       setState(() {
         if (!result.hasMore) {
         if (!result.hasMore) {
           _hasLoadedTillEnd = true;
           _hasLoadedTillEnd = true;