Skip to content

Add a lazy SliverTree #114299

@naamapps

Description

@naamapps

📜 Design Document


Related:

Use case

Currently when trying to implement tree UIs (for example: comments section with nested comments - see Instagram's comments for reference) there is no way to do it but to flatten the list and use one SliverList to show the data in the UI.

Proposal

Add a way to add a SliverList inside of a SliverList.
This will allow the CustomListView to scroll with all the data while also perform nicely with all the Slivers benefits.

In my use case, this is critical in SliverAnimatedList.

If you have any other solutions I will be happy to discuss.

Solutions I tried

  1. Using a ListView.Builder inside the SliverList builder function with shrinkWrap: true. - Poor Performance
  2. As pointed above - Normalizing the nested list with the list.expand function and using this list as the data source. - Poor Developer Experience - because everytime new data arrives we need to manage the flattened list which is not ideal.

Code example

CustomScrollView(
    slivers: [
      SliverList(
        delegate: SliverChildBuilderDelegate(
          (context, index) {
            final data = widget.comments[index];
            return SliverList(
              delegate: SliverChildBuilderDelegate(
                (context, index) {
                  if (index == 0) {
                    return CommentWidget(data);
                  } else {
                    return CommentWidget(
                        data.comments[index - 1],
                        isNested: true);
                  }
                },
                childCount: data.comments.length + 1,
              ),
            );
          },
          childCount: widget.comments.length,
        ),
      ),
    ]
)

Metadata

Metadata

Assignees

Labels

📜Issue was posted to Discord. Remove to have the issue reannounced. (For "design doc", "emergency")P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterdesign docTracks a design discussion documentf: 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 teamwaiting for PR to land (fixed)A fix is in flight

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions