I'm getting confused with flutter's render boxes. Here's what I understand: The layouting algorithm starts at the root and traverses down the widget tree, passing down constraints to the children. Flex boxes, in bounded constraints in their scroll direction, try to match their parent constraints.
Consider the following code:
Widget build(BuildContext context) {
return LayoutBuilder(builder: (context, constraints) {
print("Parent");
print(constraints.maxWidth);
print(constraints.maxHeight);
return Column(children: [
LayoutBuilder(builder: (context, constraints) {
print("Child");
print(constraints.maxWidth);
print(constraints.maxHeight);
return SizedBox(
height: 12,
);
})
]);
});
}
This prints
flutter: Parent
flutter: 320.0
flutter: 568.0
flutter: Child
flutter: 320.0
flutter: Infinity
How does the height constraints suddenly become Infinity? Shouldn't it match its parent and be 568.0?
LayoutBuilder parent size is important, if size of parent isn't clear, constraints sizes will be infinity. for example if you wrap your widget with scaffold, LayoutBuilder provides exact size.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With