Skip to content

Items always lose their state in SliverGroupedList #225

Description

@CXgbw

Is your feature request related to a problem? Please describe.
When the Child-Widgets in your list are Stateful, they will always be reinstantiated on parent rebuild. So if you do some async stuff inside of them it might flicker.

The problem comes from the framework not finding the elements in the tree. To tackle this the SliverChildBuilderDelegate has the findChildIndexCallback parameter which lets you return the index of the item based on it's key.
Since we have separators and the groupSeperators, the actual index of widgets inside the list is different to the list of elements. Flutter's standard SliverList.separated faces the same problem because the separators are actual widgets put into the sliver.

Right now there is also the problem that _buildItem wraps the children in a container with a GlobalKey that is never used, I guess it's an artifact from the non-sliver variant.

Widget _buildItem(context, int actualIndex) { var key = GlobalKey(); _keys['$actualIndex'] = key; return widget.indexedItemBuilder == null ? widget.itemBuilder!(context, _sortedElements[actualIndex]) : widget.indexedItemBuilder!( context, _sortedElements[actualIndex], actualIndex); }

Describe the solution you'd like
The SliverList needs a parameter like getItemByKey or something and then it could determine the actual index of that item in the sliver. I did this in my fork and now my children aren't reinstantiating every time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions