소스 검색

Fix swipe behavior

Vishnu 4 년 전
부모
커밋
4656340a68
1개의 변경된 파일12개의 추가작업 그리고 9개의 파일을 삭제
  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() {
     _files = widget.config.files;
     _selectedIndex = widget.config.selectedIndex;
-    _preloadEntries(_selectedIndex);
+    _preloadEntries();
     super.initState();
   }
 
@@ -161,7 +161,7 @@ class _DetailPageState extends State<DetailPage> {
           _selectedIndex = index;
           _hasPageChanged = true;
         });
-        _preloadEntries(index);
+        _preloadEntries();
         _preloadFiles(index);
       },
       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(
-          _files[index].creationTime + 1, DateTime.now().microsecondsSinceEpoch,
-          limit: kLoadLimit, asc: true);
+          _files[_selectedIndex].creationTime + 1,
+          DateTime.now().microsecondsSinceEpoch,
+          limit: kLoadLimit,
+          asc: true);
       setState(() {
         final files = result.files.reversed.toList();
         if (!result.hasMore) {
@@ -204,9 +206,10 @@ class _DetailPageState extends State<DetailPage> {
         _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(() {
         if (!result.hasMore) {
           _hasLoadedTillEnd = true;