OK so you just want to know why we get overflow
error in Column
but not in text
alone right??
here is the answer
Ans.
If you go to the Docs of Column Class you will find out the answer,
The yellow and black striped banner
When the contents of a Column exceed the amount of space available,
the Column overflows, and the contents are clipped. In debug mode,
a yellow and black striped bar is rendered at the overflowing edge to
indicate the problem, and a message is printed below the Column saying
how much overflow was detected.
they have also mentioned the Layout algorithm the column uses to build its children.
but if you go to the docs of Text there is no such talk about the Overflow since Text()
is not a Layout
like Row
or Column
but just a simple widget which is meant to be inside a layout.
~Still I agree with your point there should also be a Overflow error shown for Text alone ~
EDIT:
Overflow occurs when max height exist (not infinity as you noted, if there's no size exist for Column there will be a assertion error), columns max height is given by its parent, if column is the root Widget, the screen size will be the constraint so the overflow, where Text doesn't have any max height constraint or any Constraint so results in no overflow
EDIT 2:
By default Column()
has mainAxisSize:MainAxisSize.max
and upon going to its docs
mainAxisSize:MainAxisSize.max
Maximize the amount of free space along the main axis,
subject to the incoming layout constraints.
If the incoming layout constraints have a small enough
[BoxConstraints.maxWidth] or [BoxConstraints.maxHeight],
there might still be no free space.
If the incoming layout constraints are unbounded,
the [RenderFlex] will assert,
because there would be infinite remaining free space
and boxes cannot be given infinite size.
so since here incoming Constraint are of Text which are null according to the above edit so this gives overflow error