Dimibe/sticky_grouped_list

Could not implement ScrollController for load more functionality

Opened this issue · 9 comments

Could not implement ScrollController for load more functionality

@santoshpro95
You need to provide a GroupedItemScrollController
Instead on an ItemScrollController. The functionality is the same.

@Dimibe Can you please give me example to implement loadMore functionality using GroupedItemScrollController. Thanks

Hi @Dimibe
I have the same question as santohpro95.

GroupedItemScrollController only has the method jumpTo and scrollTo.

@bezaou Which method would you expect on the GroupedItemScrollController?

@Dimibe
For standard ListView, I can assign a ScrollController

return ListView.separated( controller: _scrollController

_scrollController is a ScrollController in which I can add a listener
_scrollController.addListener(_onScroll);

Whenever it reaches the end of the list, it can load new entities

void _onScroll() {
    final maxScroll = _scrollController.position.maxScrollExtent;
    final currentScroll = _scrollController.position.pixels;
    if (maxScroll - currentScroll <= _scrollThreshold) {
      _postBloc.add(ConversationFetched());
    }
  }

@bezaou @santoshpro95 I think that I understand the issue now. As mentioned in the readme this package is based on the scrollable_positioned_list and not on the standard list view.

Because of that you must use the itemPositionsListener property instead of the scrollController to add listeners. For an example please have a loo at the scrollable_positioned_list package and its examples.

@bezaou did you find any way how to implement 'load more' feature for this kind of list?

Hi @matszafraniec

I currently stopped working on the project, but the following used to work as far as I remember, please test it on your own.

  final ItemPositionsListener _itemPositionsListener = ItemPositionsListener.create();
   [...]
  _itemPositionsListener.itemPositions.addListener(() {
      //print('test' + _itemPositionsListener.itemPositions.value.last.itemTrailingEdge.toString());
      if (_itemPositionsListener.itemPositions.value.last.itemTrailingEdge < 1) {
        // print("bottom?" +
        //     _itemPositionsListener.itemPositions.value.last.itemTrailingEdge.toString() +
        //     '    ---- > ' +
        //     _itemPositionsListener.itemPositions.value.last.index.toString());
        if (_itemPositionsListener.itemPositions.value.last.index > 1) {
          //print('fetch');
          _homeBloc.add(HomeEventsFetched());
        }
      }
    });

  [...]
        return StickyGroupedListView<EventSearchResource, DateTime>(
     [...]
itemScrollController: GroupedItemScrollController(),
          itemPositionsListener: _itemPositionsListener,
        );
      }

Hi @bezaou Thanks for your solutions it works for some phones but on Samsung S10 its not detecting bottom. Can you please help?