Should we consider the Column widget constrained or unconstrained in the vertical direction?
According to the document of the Column widget:
When the contents of a Column exceed the amount of space available,
the Column overflows, and the contents are clipped.
To my understanding, this means that the Column widget is constrained (or bounded) vertically.
On the other hand, the documentation of the Center widget says:
If a dimension is unconstrained and the corresponding size factor is
null then the widget will match its child's size in that dimension.
When I place the Center widget in the children of a Column, what happens is that the Center widget shrinks its height to match the height of its child. According to the above document, this means that the Column widget is unconstrained in the vertical direction.
So which take is correct? Is the Column widget constrained or unconstrained in the vertical direction?
I think you're mixing the parent constraints with the children constraints.
The box constraints that the column itself receives from its parent is different from the one it passes on to its children: the column may be constrained in height by its parent, but it gives its children an infinite (unconstrained) height. Therefore..
To my understanding, this means that the Column widget is constrained (or bounded) vertically.
Yes, the column is constrained by its parent.
According to the above document, this means that the Column widget is unconstrained in the vertical direction.
Not the column itself but its children, on the other hand, are not constrained in height. This explains why the Center shrinks on the vertical direction to match its child.
Related
In my column have many widget inside it, and I down know size of that widget, so how can I calulate height of this column
My Flutter UI has a Row widget with and arbitrary number Widgets in it. I would like to move all of those widgets over to the right by a fixed amount. But the caveat is, if the other widgets grow in width such that the available horizontal space is consumed, the spacing widget will relinquish its space.
The Spacer widget does not work for me, as it does not allow you to specify a fix maximum. It only allows a flex value, which is a function of the width of the other content in the row. I want this spacer to take up a fixed amount of space regardless of the width of the other content of the row (unless all the room is used up).
Try using sizedBox or FractionallySizedBox as explained in this answer
https://stackoverflow.com/a/63430801/8213343
Since both are used to add spacing to our screen how do we decide when to use either of them .
SizedBox creates space between widget to widget only just height and width.
Padding is how much an element is away from itself — how much distance an element wants to keep with the elements inside it. They create distance top, bottom, left, and right.
Please checout my answer from here
Containers with no children try to be as big as possible unless the incoming constraints are unbounded, in which case they try to be as small as possible. Containers with children size themselves to their children. The width, height, and constraints arguments to the constructor override this.
Question
What does the incoming constraint mean in Flutter?
According to Google's flutter documentation on understanding constraints:
A widget gets its own constraints from its parent [the "incoming constraint" you are asking about]. A constraint is just a set of 4 doubles: a minimum and maximum width, and a minimum and maximum height.
Then the widget goes through its own list of children. One by one, the widget tells its children what their constraints are (which can be different for each child), and then asks each child what size it wants to be.
Then, the widget positions its children (horizontally in the x axis, and vertically in the y axis), one by one.
And, finally, the widget tells its parent about its own size (within the original constraints, of course).
I suggest you read that entire URL for more details. The Google people are writing some amazingly clear documentation.
I am trying to make a widget that does not have width constraints, so it depends on the biggest child, all other children should match the same width.
I know I can not achieve that with Row inside Column, because Column does not have a bounded width.
The result which I am trying to achieve in the red circle: