-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Issue by afandria
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 of config 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.
Stack
MyChild with key1
MyChild with key2
to
Stack
MyChild with key2
MyChild with key1
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.
Stack
Positioned
MyChild with key1
Positioned
MyChild with key2
to
Stack
Positioned
MyChild with key2
Positioned
MyChild with key1
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!