EdsonBueno / infinite_scroll_pagination

Flutter package to help you lazily load and display pages of items as the user scrolls down your screen.
https://pub.dev/packages/infinite_scroll_pagination
MIT License
605 stars 201 forks source link

Prepend functionality #327

Open rsegecin opened 2 months ago

rsegecin commented 2 months ago

There was an attempt to merge #258 to add the prepend functionality to the scrollcontroller, why wasn't it merged? and btw the beers api from punkapi is not online.

clragon commented 1 month ago

The PR mostly went under because the repository was not actively maintained at the time. Generally I am unsure if this functionality should be part of the library. It can easily be added via extensions from the outside, when required.

rsegecin commented 1 month ago

hi @clragon, thank you for your reply. I've forgot about this issue as I had found this extension but definitely it would be a nice to have it embedded it in the package.

for anyone looking for it.


extension PrependPageExtension<PageKeyType, ItemType>
    on PagingController<PageKeyType, ItemType> {
  /// Prepends [newItems] to the previously loaded ones
  void prependPage(List<ItemType> newItems) {
    final previousItems = value.itemList ?? [];
    final itemList = newItems + previousItems;
    value = PagingState<PageKeyType, ItemType>(
      itemList: itemList,
      error: null,
      nextPageKey: nextPageKey,
    );
  }
}