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

Unable to Implement Pagination with Scroll Listener in Dash Chat 2 #76

Closed
muj-i opened this issue Dec 28, 2023 · 3 comments
Closed

Unable to Implement Pagination with Scroll Listener in Dash Chat 2 #76

muj-i opened this issue Dec 28, 2023 · 3 comments
Labels
question Further information is requested

Comments

@muj-i
Copy link

muj-i commented Dec 28, 2023

Hello,

I am currently using the Dash Chat 2 package for Flutter in my project and I am facing some difficulties implementing pagination with a scroll listener for chat.

Here's what I am trying to achieve:

  • I want to load more messages when the user scrolls up to the top of the chat.
  • I am trying to use a scroll listener to detect when the user has scrolled to the top so that I can load more messages.

Could you please provide some guidance on how I can successfully implement this feature? Any help would be greatly appreciated.

Thank you in advance for your time and assistance.

Best regards,
Mujahedul Islam.

@LegendAF
Copy link
Contributor

LegendAF commented Jan 17, 2024

You will want to pass in a scroll controller to MessageListOptions(scrollController: _scrollController);

From there listen to it _scrollController.addListener(_onScroll);

and do something like:

  void _onScroll() {
    if (!_fetchingMessages) {
      // if the top is reached
      if (_scrollController.offset >=
          _scrollController.position.maxScrollExtent) {
        setState(() {
          _fetchingMessages = true;
        });
        // do things
        ...
        // reset fetching
        WidgetsBinding.instance.addPostFrameCallback((_) {
          setState(() {
            _fetchingMessages = false;
          });
        });
      }
    }
  }

@SebastienBtr
Copy link
Owner

Hey, you don't need to create a custom scrollController listener like suggested by @LegendAF. You can achieve the same by using onLoadEarlier from MessageListOptions and add your logic to fetch more messages and append them to the list of existing messages.

Let me know if you have more questions regarding the pagination

@SebastienBtr SebastienBtr added the question Further information is requested label Feb 1, 2024
@SebastienBtr
Copy link
Owner

Closing this, let us know if you have more questions

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

No branches or pull requests

3 participants