Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not implement ScrollController for load more functionality #24

Open
santoshpro95 opened this issue Oct 23, 2020 · 9 comments
Open

Comments

@santoshpro95
Copy link

No description provided.

@Dimibe
Copy link
Owner

Dimibe commented Oct 23, 2020

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

@santoshpro95
Copy link
Author

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

@bezaou
Copy link

bezaou commented Oct 26, 2020

Hi @Dimibe
I have the same question as santohpro95.

GroupedItemScrollController only has the method jumpTo and scrollTo.

@Dimibe
Copy link
Owner

Dimibe commented Oct 26, 2020

@bezaou Which method would you expect on the GroupedItemScrollController?

@bezaou
Copy link

bezaou commented Oct 26, 2020

@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());
    }
  }

@Dimibe
Copy link
Owner

Dimibe commented Oct 26, 2020

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

@matszafraniec
Copy link

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

@bezaou
Copy link

bezaou commented Jan 14, 2021

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

@nicks258
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants