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

Is it possible to handle scroll UP and DOWN to load more? #46

Closed
valerybodak opened this issue Feb 8, 2021 · 10 comments
Closed

Is it possible to handle scroll UP and DOWN to load more? #46

valerybodak opened this issue Feb 8, 2021 · 10 comments

Comments

@valerybodak
Copy link

valerybodak commented Feb 8, 2021

I see that we can handle scroll DOWN to load more, but is it possible to handle scroll UP as well to load more? For example, initial page is 2. So when I scroll to top I need to fetch page 1 etc.

@EdsonBueno
Copy link
Owner

Yes, it is!
Set the reverse property from PagedListView to true.
Keep in mind that the "page ordering" is on you. The PagingController will ask first whatever page number you provided on its constructor.

@valerybodak
Copy link
Author

@EdsonBueno
But looks like we can't enable the pagination to both directions (up & down). For example, if the initial index is 2, I need to scroll down to fetch page 3 etc. and I need to scroll up to fetch 1, 0.
Can I enable this behaviour?

@EdsonBueno
Copy link
Owner

Ooooh, wow! Now I get it...
No, that's not possible...

@zefaxet
Copy link

zefaxet commented Feb 17, 2021

When you say it's not possible, do you mean just as a limitation of this widget?
This other repository:
https://github.com/fluttercommunity/flutter_infinite_listview
accomplishes what @valerybodak is asking for, but it uses the normal index-based generator scheme that the normal ListView uses. I would prefer to use the key-based builder pattern implemented on this widget, and it seems to me like a small effort to combine these two features here.

I'm eager to hear what your thoughts are here, but in the meantime I and others may have to rely on the alternatives like the one I linked to meet this specific need.

@EdsonBueno
Copy link
Owner

EdsonBueno commented Feb 18, 2021

@zefaxet From what I could understand, the package you listed has nothing to do with pagination, it's just a circular ListView. When you reach the end of it, you start seeing the initial items again.
Did I got it wrong? If not, it's nowhere close to what @valerybodak needs.

What @valerybodak wants is to start showing the user the third page (for example). Then if the user scrolls up, we lazily fetch the second page. If he scrolls down, we lazily fetch the fourth page.

@zefaxet
Copy link

zefaxet commented Feb 18, 2021

Not quite. Example:
Let's say you create the exemplar PagingController hooked up to the Article repository (referencing your guide here), but instead you give the controller firstPageKey: 2. When you scroll down, you end up dispatching requests for page 3, 4, 5, etc...

What @valerybodak is asking for is, if they were to scroll up in this case, for the controller to dispatch a request for page 1 and prepend it to the top of the scroll view (preserving order).

You're right that the package I linked is not paginating anything, but it is not circular. Is is able to generate indices infinitely in both directions, up or down, allowing you to have infinite scroll in both directions with fresh items. I think this concept can be extended to your implementation of the PagingController. I'm new to Dart so I might have missed some semantics, but I think at a high level all you need to do is add a new key boundary for the controller to keep track of the top of the page results as well as the bottom (what it does now). Then you should be able to invoke a prepending analogy to the existing appendPage.

Perhaps:

void prependPage(List<ItemType> newItems, PageKeyType nextReversePageKey) {
  ...
}

Can't figure out a better name for nextReversePageKey so I hope my explanation clears up what that's supposed to mean.

What do you think?

@EdsonBueno
Copy link
Owner

EdsonBueno commented Feb 18, 2021

It can definitely be done, and the API you suggested would work. But, I'm afraid the inner workings of this aren't that simple, not to mention the visual aspects (loading and error indicators).
Another thing we have to keep in mind, is that if this isn't something lots of users need, it would just bloat up the API and make the package more confusing to use. To avoid that, we could create a new BidirectionalPagingController.

I'll keep an eye on this, and if enough users start asking for it, I can give it a try.
For now, if the other package solves your problem, I suggest going with it.

@zefaxet
Copy link

zefaxet commented Feb 18, 2021

I agree with creating a new widget for this. I was going to suggest that next so it's good to see there's room for the feature if the demand comes.

@sachin052
Copy link

I agree with creating a new widget for this. I was going to suggest that next so it's good to see there's room for the feature if the demand comes.

It's a great Idea. I'm looking for the same

@EdsonBueno EdsonBueno reopened this Mar 2, 2021
@EdsonBueno
Copy link
Owner

From now on, let's track this issue here.
I think it's better explained over there.

@valerybodak valerybodak changed the title Is it possible to handle scroll UP to load more? Is it possible to handle scroll UP and DOWN to load more? Apr 21, 2021
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

4 participants