-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Apply indexToItemIndex to indices returned by findChildIndexCallback in SliverAnimatedListState
#108710
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
Apply indexToItemIndex to indices returned by findChildIndexCallback in SliverAnimatedListState
#108710
Conversation
…Callback in SliverAnimatedListState
|
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!). If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
5195766 to
de4cc53
Compare
0e1c961 to
24fca4b
Compare
| expect(reorderedListEntries[0].data, equals('item 3')); | ||
| expect(reorderedListEntries[1].data, equals('item 1')); | ||
| expect(reorderedListEntries[2].data, equals('item 2')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fails on master - hence this PR.
|
CLA signed, test added, PR ready for review. |
chunhtai
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just some nitpicking
| _itemBuilder, | ||
| childCount: _itemsCount, | ||
| findChildIndexCallback: widget.findChildIndexCallback, | ||
| findChildIndexCallback: widget.findChildIndexCallback == null ? null : (Key key) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should follow the other in line if else format if it is too long
findChildIndexCallback: widget.findChildIndexCallback == null
? null
: (Key key) {
....
}
| slivers: <Widget>[ | ||
| SliverAnimatedList( | ||
| key: listKey, | ||
| initialItemCount: items.length, // we will insert one item later |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avoid we
| expect(tester.getTopLeft(find.text('item 0')).dy, 200); | ||
| }); | ||
|
|
||
| testWidgets('passes correctly derived index of findChildIndexCallback to inner SliverChildBuilderDelegate', (WidgetTester tester) async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| testWidgets('passes correctly derived index of findChildIndexCallback to inner SliverChildBuilderDelegate', (WidgetTester tester) async { | |
| testWidgets('passes correctly derived index of findChildIndexCallback to the inner SliverChildBuilderDelegate', (WidgetTester tester) async { |
chunhtai
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
cc @Piinks for secondary review |
Piinks
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…exCallback` in `SliverAnimatedListState` (flutter/flutter#108710)
…exCallback` in `SliverAnimatedListState` (flutter/flutter#108710)
…exCallback` in `SliverAnimatedListState` (flutter/flutter#108710)
…exCallback` in `SliverAnimatedListState` (flutter/flutter#108710)
…exCallback` in `SliverAnimatedListState` (flutter/flutter#108710)
…exCallback` in `SliverAnimatedListState` (flutter/flutter#108710)
…exCallback` in `SliverAnimatedListState` (flutter/flutter#108710)
…exCallback` in `SliverAnimatedListState` (flutter/flutter#108710)
…exCallback` in `SliverAnimatedListState` (flutter/flutter#108710)
…exCallback` in `SliverAnimatedListState` (flutter/flutter#108710)
…exCallback` in `SliverAnimatedListState` (flutter/flutter#108710)
…exCallback` in `SliverAnimatedListState` (flutter/flutter#108710)
…ck` in `SliverAnimatedListState` (flutter#108710)

In
SliverAnimatedListState, theinsertItem()andremoveItem()index parameters are defined as if theremoveItem()operation removed the corresponding list entry immediately. The entry is only actually removed from theListViewwhen the remove animation finishes._indexToItemIndexis used to convert the user-supplied index to the internal index, which takes item removal into account.The user can also provide a
findChildIndexCallbackto theSliverAnimatedListwhich is passed on to the internalSliverChildBuilderDelegate. Sincedelegaterenders all items, including items being removed, the same_indexToItemIndexneeds to be applied to the indices returned by the user-provided function. Otherwise it is impossible for the user to implementfindChildIndexCallback, because the internal state of theSliverAnimatedListand hence the current content of thedelegateis not known to the user.findChildIndexCallbackindices originate from the same user-facing source of truth asinsertItem()andremoveItem(), and hence must likewise be converted to internal indices.The call to
_indexToItemIndexin the innerfindChildIndexCallbackwas previously omitted by oversight, making it impossible for the user to implementfindChildIndexCallbackcorrectly, resulting in unwanted rebuilds and state loss. This PR fixes this.