569680 (1) [Avatar] Offline
#1
In the caption of figure 1.5 we have:

Flutter lays out all the widgets in one walk down and back up the tree, because widgets dictate their children’s size constraints in Flutter.


But inside of the image, the book says:

Flutter walks back up the tree, and each node decides its actual size.


So, I don't understand, each widget decides its own size? Or it's the parent who decided.
ericwindmill (5) [Avatar] Offline
#2
569680 wrote:In the caption of figure 1.5 we have:

Flutter lays out all the widgets in one walk down and back up the tree, because widgets dictate their children’s size constraints in Flutter.


But inside of the image, the book says:

Flutter walks back up the tree, and each node decides its actual size.


So, I don't understand, each widget decides its own size? Or it's the parent who decided.



Hey, that's a good question. I should probably make that clearer.

The parent of a widget tells the child its size constraints, but the child itself sets its own final size.

So the parent says "Hey child, you can be a maximum of 300px by 300px, and a minimum of 50px by 50px." and then the child says "okay, well based on my content I'll be 150px by 300px, because that size is within my constraints".

You can see the difference in the class ConstraintedBox vs SizedBox. A sized box strictly enforces a size, but a constrained box just gives minimums and maximums.

https://docs.flutter.io/flutter/rendering/BoxConstraints-class.html