Skip to content

Improvements to estimateMaxScrollOffset #97676

Open

Description

@Piinks

Chatted with @HansMuller about this the other day.

Currently, Flutter only estimates the maximum scroll offset one way, but taking the average size of the visible children and multiplying it by the number of children:

static double _extrapolateMaxScrollOffset(

This can be a bit unfortunate when the user has a list of dynamically sized items in which the max scroll extent changes as they scroll.

There seem to be some opportunities for improvement here. Things we might consider:

  • Adding more strategies for estimating the max scroll offset for different situations
    • optionally could let the user decide which estimation method they would like used
    • One should be that we cache the metrics as we go, rather than disposing of extent info of children we have scrolled past already
  • Better expose an option for users to provide their own estimate
    • could just involve a good example or two showing how to override estimateMaxScrollOffset for any SliverChildDelegate, but if there are more approachable options we should explore further

Related to #25652

Activity

  1. added
    c: new featureNothing broken; request for a new capability
    frameworkflutter/packages/flutter repository. See also f: labels.
    f: scrollingViewports, list views, slivers, etc.
    d: api docsIssues with https://api.flutter.dev/
    c: proposalA detailed proposal for a change to Flutter
    a: annoyanceRepeatedly frustrating issues with non-experimental functionality
    a: layoutSystemChrome and Framework's Layout Issues
    on Feb 2, 2022
  2. added
    P3Issues that are less important to the Flutter project
    on Feb 2, 2022
  3. chipweinberger commented on Mar 3, 2022

    @chipweinberger
    Contributor

    I looked over some of your scrolling PRs and want to strongly request we replace/supplant ListView.itemExtent (double) with ListView.itemExtentList (List<double>).

    The programmer knows a lot about the sizes of things and how user actions can impact size.

    For example, if a user hits a button that expands all or some the widgets inside the ListView, the programmer knows which ones are now the new size.

    It also lets the programmer associate a scrollOffset with a specific item, which is needed for jumping to a known item using the scrollOffset. Today, event if the programmer knows where an item is, they still can't jump to it correctly because Flutter doesn't know where it is.

  4. knopp commented on Sep 26, 2022

    @knopp
    Member

    We've published first version of SuperSliverList, you can see live example here. The average item estimation is simply (last item paint offset + extent) / (last item index + 1). In the example you can see that the scrollbar is much "calmer" than with SliverList.

    (I'm not saying this is better algorithm that what Flutter uses in Sliver list, it's just better suitable for our use-case).

  5. 0921dma commented on Oct 11, 2023

    @0921dma

    Is there a way to implement a similar solution for SliverAnimatedList as described in this issue? I'm facing the same issue due to the dynamic sizes of the list items, and I'm wondering if there's a workaround or an upcoming fix for SliverAnimatedList as well.

  6. added a commit that references this issue on Apr 3, 2024
  7. added a commit that references this issue on Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projecta: annoyanceRepeatedly frustrating issues with non-experimental functionalitya: layoutSystemChrome and Framework's Layout Issuesc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterd: api docsIssues with https://api.flutter.dev/d: examplesSample code and demosf: scrollingViewports, list views, slivers, etc.frameworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions