Skip to content

RenderViewport maxLayoutCycles should depend on number of slivers in viewport #144102

Closed
@knopp

Description

@knopp

In super_sliver_list we rely on scrollOffsetCorrection to account for the difference between estimated and actual extent. In some corner cases, for example when the viewport is initially scrolled to end, this may result in one correction per SuperSliverList during initial layout.

The problem is that RenderViewport currently caps the maximum number of of layout cycles to 10, regardless of number of slivers. In case where there is a large amount of very short slivers, this may throw an exception, even though each sliver only requested at most one correction.

Ideally we'd want to track the number of correction requests per Sliver, but that's little bit difficult because slivers can be nested (i.e. SliverMainAxisGroup) and SliverGeometry propagated from child slivers does not carry the original sliver that requested the correction.

Less ideal but much easier solution would be to replace _maxLayoutCycles with _maxLayoutCyclesPerChild and then multiply it with number of viewport children:

void performLayout() {
  ...
  final int maxLayoutCycles = _maxLayoutCyclesPerChild * childCount;
  ...

While not perfect, this would still be a significant improvement. We could potentially reduce the value of _maxLayoutCyclesPerChild from 10 because it will be multiplied by the amount of child slivers.

cc @Piinks

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: proposalA detailed proposal for a change to Flutterf: scrollingViewports, list views, slivers, etc.frameworkflutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer versionteam-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