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
ScrollController listenable maxScrollExtent #21541
Comments
Related or similar #12319 |
What is the status on the fix for this issue??? This makes my app look very clunky! Please provide a solution for this, Flutter! |
I am also impacted by this. It's a very common use case to add items to the top of a list. All possible workaround are not ideal because the list jumps around. Any solution for this? |
I'm making a chat room for multiple users and I'm having this problem. Please let me know if anyone has solved this issue. Thanks! |
+1, this would all be fixed by a getOffsetForIndex() API, which is sorely missing right now anyways. We really shouldn't need to measure previous and current extents in order to just jump to a specific index. If I was at index 0, and loaded 15 new items at the front if my list, I should simply be able to call controller.jumpToIndex(15) or controller.jumpTo(controller.getOffsetForIndex(15)) to maintain scroll position. Both would be nice :) |
@zoechi any updates on this? it's been two years, I'm still struggling with this... |
@tudor07 I "fixed" it by shaping our requirements to allow for all list items to be of the same height... |
This can done with a I made an example (add content below and above with the plus in the top left corner): https://dartpad.dartlang.org/c3b9b03925cdaaf88c1b8fe78a3b96b0 @florisvdg @tudor07 Does this solution solve the problem for you? I'll go ahead and close the ticket unless you think otherwise. |
While it solves this very specific use case, it does not address.the API limitation of scroll view that was the heart of the issue. Why not give us a simple event when maxExtents changes? |
@gskinner-shared - as @florisvdg pointed out, building a solution to this problem around reacting to the update of maxScrollExtent is tricky because the notification comes at layout time and ScrollController.jumpTo(), which - generally speaking - could trigger an additional layout, is going to affect the next frame. The solution suggested by @perclasson is relatively straightforward and nicely addresses this issue's use-case. I think we should close this issue upon adding a version of the sample solution to the CustomScrollView API docs. |
It's a pretty common use case to need to know the accurate size of the scroll contents. Especially when building scrollbars. What we do now is basically hack around it using sheduleMicrotask, or create some system where the child tells us it's extent (via Notification or post-build callback). Seems like a proper event would at least be preferable to that even if it's async? Our workarounds are all async anyways... |
@perclasson , I would like to thank you so much for addressing this important topic. I've tried this with SliverAppBar and I couldn't maintain the right behavior as floating = true. how can I handle SliverAppBar on CustomScrollView in this example? |
@perclasson just FYI, I had some success in embedding SliverAppbar using NestedScrollViews but won't float because the issue Support Floating+ SliverAppBars in NestedScrollViews #57707 Still have an issue with a jump back to the top of the screen, because with the approach it won't 0.0 it goes with minimize, even using minScrollExtent won't get into all top. |
I was successfully able to jump to the top with _scrollController.position.minScrollExtent - MediaQuery.of(context).size.height; Actually, I don't the reason exactly just went further than the minScrollExtent |
@HickYeah Looks like you manage to solve the issue! Here is something similar to what you need, but with the solution of using two [SliverList]s: https://dartpad.dartlang.org/38a9320bb8edd30af3c8543c24df8a21 For future questions, I suggest asking in the discord/slack channel for Flutter, or create a new issue with your feature requests. |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Use case: a ListView that supports loading in new items from the top and also from the bottom, like a Twitter timeline or an RSS feed. When dynamically adding new items at the bottom, everything is fine. However, when adding items from the top (in the case of a Twitter or RSS pull-to-refresh or a real time feed), the newly added items, from the perspective of the user, push the scroll position down, because the scroll content height has increased, resulting in a jump (or in the case of an AnimatedList: a slide animation). The user would just expect the scroll position to be at the same item the user is looking at at that moment.
Because Flutter does not seem to have anything for this use case out of the box, a way to fix this issue is to just recalculate the scroll offset when the new items are added and then call
scrollController.jumpTo
upon an updated state. This is easy when you know the item size in advance. When the items have content dependent heights the calculation can be done using the previousmaxScrollExtent
and the newmaxScrollExtent
. However, when to then run this calculation seems to be a harder issue.I tried invoking it
setState
, but that seems to be too early, because themaxScrollExtent
is not known and not updated at that timeWidgetsBinding.instance.addPostFrameCallback
, which works and sets the scroll offset to the desired position, but seems to do this too late, causing the scroll offset to quickly jumpBeing able to listen for when the
maxScrollExtent
is actually updated could solve this issue. Or would there be an alternative way to do this? Seems like a pretty basic problem any serious social, twitter, news, rss app would run into.The text was updated successfully, but these errors were encountered: