-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Synchronizing Configs of Widgets with Keys #240
Comments
Yes. There are two kinds of keys, local keys and global keys. If you use local keys, their scope is just their own sibling list. If you use global keys, their scope is the entire tree. Local keys are more efficient but less powerful.
You have two choices: (1) you can add keys to the
(2) you can use global keys:
The global keys will let your widgets sync anywhere in the tree. The tradeoff is that (1) is more efficient than (2) but you can't always arrange for it to happen whereas. |
I missed the point on Global Keys, so it does look like sync covers the most important cases. I think these distinctions are worth adding to the tutorial. My app now keys the Positioned as well, as in solution (1). (I was unable to remove Positioned since MyChild expanded to fill the full Stack without it.) It turns out that my app was using global keys as in solution (2). It looks like it did sync the MyChild configurations correctly, though a combination of other bugs made that difficult to see. Aside: Unfortunately, (2) will not work for my app specifically because my app does global vs local Point computations for each SlideTransition animation. Since MyChild computes its local animation destination, if it's wrapping Positioned parent is swapped out, then it will not realize that it is animating to the wrong location. |
How do we take action on this? Is this for documentation, or also enhancements/changes to the framework? |
The issues being discussed here are mostly obsolete now. |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Thursday Oct 29, 2015 at 07:47 GMT
Originally opened as https://github.com/flutter/engine/issues/1867
The Flutter tutorial is quite helpful at clarifying the framework, but I think that the section on Keys can be clarified. My understanding of
sync
is that it is connected to the notion ofconfig
in StatefulComponents. I think it would be good to tie it back to the description (a few paragraphs earlier).It also appears that key-based synchronization does not always occur. I looked at framework.dart's
updateChildren
method, and it says that this synchronization only happens for sibling widgets that share the same keys.For example, this Widget Tree scenario should move the two children without changing their original configurations.
to
The above scenario should work well for most layouts (Flex/Row/Column/Block/Grid).
However, Stack is problematic when the children are in Positioned: here, the keyed Widgets are cousins, not siblings.
to
Since Stack children are usually Positioned, this second scenario should be quite common. However, the code (and my observations) show that the children would not sync with their original configurations (instead, they trade).
I think the fact that keys only affect sync of sibling widgets is very important to convey. However, I expected key-based matching to occur regardless of the actual layout of the Widget tree. Is sibling-only sync an intentional choice by the Flutter framework?
If it is, how can I synchronize my Stack's Positioned keyed children?
Note: I think I can work around the "cousins not syncing" issue in my app by reworking it. To make the keyed widgets be siblings again, I will pass the coordinates to them instead of to a Positioned. The widgets will use a SlideTransition to get into place. (IIRC, I don't think I can have my top-level child widget be a Positioned. Is there an alternative widget that won't animate?)
Please let me know if you have questions, or if I got something wrong. Thank you!
The text was updated successfully, but these errors were encountered: