sticky_grouped_list icon indicating copy to clipboard operation
sticky_grouped_list copied to clipboard

Could not implement ScrollController for load more functionality

Open santoshpro95 opened this issue 4 years ago • 9 comments

santoshpro95 avatar Oct 23 '20 11:10 santoshpro95

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

Dimibe avatar Oct 23 '20 13:10 Dimibe

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

santoshpro95 avatar Oct 24 '20 05:10 santoshpro95

Hi @Dimibe I have the same question as santohpro95.

GroupedItemScrollController only has the method jumpTo and scrollTo.

bezaou avatar Oct 26 '20 17:10 bezaou

@bezaou Which method would you expect on the GroupedItemScrollController?

Dimibe avatar Oct 26 '20 19:10 Dimibe

@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 avatar Oct 26 '20 20:10 bezaou

@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.

Dimibe avatar Oct 26 '20 20:10 Dimibe

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

matszafraniec avatar Jan 14 '21 07:01 matszafraniec

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,
        );
      }

bezaou avatar Jan 14 '21 08:01 bezaou

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

nicks258 avatar Mar 14 '23 08:03 nicks258