Flutter & Dart (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
How does Layout work in Flutter: "Constraints Go Down, Sizes Go Up, Parent Sets Position"?
senior LevelCode ExampleflutterAdvanced Internals
In Simple Words: The golden rule of the Flutter layout pipeline:
- Constraints Go Down: A parent widget passes minimum and maximum width/height constraints (
BoxConstraints) down to its child. - Sizes Go Up: The child determines its own dimensions within those constraints and passes its calculated
Sizeback up to the parent. - Parent Sets Position: The parent places the child at an $(x, y)$ coordinate position within its coordinate space.
- An unconstrained widget (e.g. placing
ListViewinsideColumnwithoutExpanded) causes the fatal crash:Vertical viewport was given unbounded height.
text
The Flutter Layout Rule:
[Parent Widget]
│ ▲
│ (Constraints: Min/Max Width & Height)
▼ │ (Calculated Size: Width & Height)
[Child Widget]
│
(Parent places Child at x, y position)