-
Notifications
You must be signed in to change notification settings - Fork 28.5k
Use AnimatedSwitcher's _childNumber as Key in layoutBuilder's Stack #121408
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
Use AnimatedSwitcher's _childNumber as Key in layoutBuilder's Stack #121408
Conversation
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. |
@jimgerth Can you please sign the CLA (see previous message) and add a test for your change? Also, it looks like some other checks are failing as well. Please take a look at those as well. Thanks. |
@goderbauer I have signed the CLA now and will add a test for my change once I have time. Also it seems that the test failing currently is the one introduced by #107476, fixing a related issue of duplicate keys in the Children, that are transitioning out are simply completely removed from the widget tree, if another child with the same key is added. As the test's name introduced by that PR implies:
(And this does not even completely eliminate that problem of duplicate keys, as shown by #121336, which is why this PR exists...) However this is not the expected behaviour of the
It clearly states that multiple children with the same key can transition in and out at the same time. My question now is: Am I allowed to remove this test, as it tests for "wrong" behavior? Or how should I proceed? |
ae10d7e
to
ba238dd
Compare
ba238dd
to
503565c
Compare
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, thanks for the fix!
Revert the changes introduced by flutter#107476, as they do not completely fix the issue of duplicate keys in the AnimatedSwitcher switcher as demonstrated by flutter#121336, and introduce behavior that deviates from the AnimatedSwitcher's documentation. Specifically, children that are transitioning out are immediately removed from the widget tree, if another child with the same key is added, while the AnimatedSwitcher is clearly supposed to support multiple children with the same key transitioning in and out at the same time according to its documentation.
Previously KeyedSubtree.wrap gave children of the AnimatedSwitcher their own key as a key, if available, and their _childNumber as a key, if not. This could lead to multiple children having the same key in the defaultLayoutBuilder's Stack and thus a duplicate key exception being thrown, though. This is fixed by always using the uniquely identifiable _childNumber as a key for the children of the AnimatedSwitcher. This does not impair the functionality of having children of the same type be differentiated and transitioned between by giving them different keys, as the children's original key is still used to determine if a transition should take place or not.
Add a test for the AnimatedSwitcher, that test if multiple children with the same key can be added and are properly transitioned in and out.
503565c
to
8ac116e
Compare
@goderbauer My pleasure :) Could you add the Also, rebased onto |
auto label is removed for flutter/flutter, pr: 121408, due to - Please get at least one approved review if you are already a member or two member reviews if you are not a member before re-applying this label. Reviewers: If you left a comment approving, please use the "approve" review action instead. |
auto label is removed for flutter/flutter, pr: 121408, due to Validations Fail. |
In cl/512895929 there's a slight goldens diff that could possibly be due to this change, WDYT @goderbauer? |
I triaged them as acceptable. |
… Stack (flutter#121408)" (flutter#121835) [flutter roll] Revert "Use AnimatedSwitcher's _childNumber as Key in layoutBuilder's Stack"
Previously
KeyedSubtree.wrap
gave children of theAnimatedSwitcher
their own key as a key, if available, and their_childNumber
as a key, if not. This could lead to multiple children having the same key in thedefaultLayoutBuilder
'sStack
and thus a duplicate key exception being thrown, though (see #121336 for a detailed description of how this bug occurs). This is fixed by always using the uniquely identifiable_childNumber
as a key for the children of theAnimatedSwitcher
.This does not impair the functionality of having children of the same type be differentiated and transitioned between by giving them different keys, as the children's original key is still used to determine if a transition should take place or not.
This fixes #121336.
Note: This reverts the changes introduced by #107476, as they do not completely fix the issue of duplicate keys in the AnimatedSwitcher switcher as demonstrated by #121336, and introduce behavior that deviates from the AnimatedSwitcher's documentation.
Specifically, children that are transitioning out are immediately removed from the widget tree, if another child with the same key is added, while the AnimatedSwitcher is clearly supposed to support multiple children with the same key transitioning in and out at the same time according to its documentation:
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.