Firelands128 / photo_gallery

A Flutter plugin that retrieves images and videos from mobile native gallery.
BSD 3-Clause "New" or "Revised" License
68 stars 62 forks source link

May be a bug on nextPage() #23

Closed right7ctrl closed 3 years ago

right7ctrl commented 3 years ago

When i call nextpage function first it gives me 30more images which i have been declared on take parameter. But when i call nextPage more than once, it returns take option * 2 items every time

To be more clear When i declared the MediaPage variable like this final MediaPage mediaPage = await album.listMedia(newest: true, take: 30, skip: 0); // returns 30 items as usual

When i call sth like this mediaPage.nextPage(); // returns 30 more items And just wanted to call one more page mediaPage.nextPage(); // returns 60 more items (30 * 2) one more page mediaPage.nextPage(); // returns 120 more items (60 * 2)


Future<void> getImages(albumId) async {
    images = [];
    final album = ImagesProvider.staticAlbums.elementAt(albumId);
    imagePage = await album.listMedia(newest: true, take: 30, skip: 0);
    images = imagePage.items;
    images?.sort((a, b) => b.creationDate.compareTo(a.creationDate));
    notifyListeners();
  }

  Future<void> getNextPage() async {
    if (imagePage != null && !imagePage.isLast) {
      final nextPage = await imagePage.nextPage();
      print('NEXT ITEMS: ${nextPage.items.length}');
      nextPage.items?.sort((a, b) => b.creationDate.compareTo(a.creationDate));
      print('CURRENT ITEMS: ${images.length}');
      images.addAll(nextPage.items);
      print('TOTAL ITEMS: ${images.length}');
      notifyListeners();
    }
  }

And the output

flutter: NEXT ITEMS: 30 flutter: CURRENT ITEMS: 30 flutter: TOTAL ITEMS: 60 flutter: NEXT ITEMS: 50 // i have total 110 images, if i have more it would be 120. flutter: CURRENT ITEMS: 60 flutter: TOTAL ITEMS: 110

right7ctrl commented 3 years ago

It was my bad :( solved like below

  Future<void> getNextPage() async {
    if (imagePage != null && !imagePage.isLast) {
      imagePage = await imagePage.nextPage();

      print('NEXT ITEMS: ${imagePage.items.length}');
      imagePage.items?.sort((a, b) => b.creationDate.compareTo(a.creationDate));
      print('CURRENT ITEMS: ${images.length}');
      images.addAll(imagePage.items);
      print('TOTAL ITEMS: ${images.length}');
      notifyListeners();
    }
  }