text
stringlengths 0
197
|
---|
<code_start> |
UnconstrainedBox( |
child: Container(color: red, width: 4000, height: 50), |
) |
<code_end> |
The screen forces the UnconstrainedBox to be exactly |
the same size as the screen, and UnconstrainedBox |
lets its child Container be any size it wants. |
Unfortunately, in this case the Container is |
4000 pixels wide and is too big to fit in |
the UnconstrainedBox, so the UnconstrainedBox displays |
the much dreaded “overflow warning”. |
<topic_end> |
<topic_start> |
Example 15 |
<code_start> |
OverflowBox( |
minWidth: 0, |
minHeight: 0, |
maxWidth: double.infinity, |
maxHeight: double.infinity, |
child: Container(color: red, width: 4000, height: 50), |
) |
<code_end> |
The screen forces the OverflowBox to be exactly the same |
size as the screen, and OverflowBox lets its child Container |
be any size it wants. |
OverflowBox is similar to UnconstrainedBox; |
the difference is that it won’t display any warnings |
if the child doesn’t fit the space. |
In this case, the Container has 4000 pixels of width, |
and is too big to fit in the OverflowBox, |
but the OverflowBox simply shows as much as it can, |
with no warnings given. |
<topic_end> |
<topic_start> |
Example 16 |
<code_start> |
UnconstrainedBox( |
child: Container(color: Colors.red, width: double.infinity, height: 100), |
) |
<code_end> |
This won’t render anything, and you’ll see an error in the console. |
The UnconstrainedBox lets its child be any size it wants, |
however its child is a Container with infinite size. |
Flutter can’t render infinite sizes, so it throws an error with |
the following message: BoxConstraints forces an infinite width. |
<topic_end> |
<topic_start> |
Example 17 |
<code_start> |
UnconstrainedBox( |
child: LimitedBox( |
maxWidth: 100, |
child: Container( |
color: Colors.red, |
width: double.infinity, |
height: 100, |
), |
), |
) |
<code_end> |
Here you won’t get an error anymore, |
because when the LimitedBox is given an |
infinite size by the UnconstrainedBox; |
it passes a maximum width of 100 down to its child. |
If you swap the UnconstrainedBox for a Center widget, |
the LimitedBox won’t apply its limit anymore |
(since its limit is only applied when it gets infinite |
constraints), and the width of the Container |
is allowed to grow past 100. |
This explains the difference between a LimitedBox |
and a ConstrainedBox. |
<topic_end> |
<topic_start> |
Example 18 |
<code_start> |
const FittedBox( |
child: Text('Some Example Text.'), |
) |
<code_end> |
The screen forces the FittedBox to be exactly the same |
size as the screen. The Text has some natural width |
(also called its intrinsic width) that depends on the |
amount of text, its font size, and so on. |
The FittedBox lets the Text be any size it wants, |
but after the Text tells its size to the FittedBox, |
the FittedBox scales the Text until it fills all of |
the available width. |
<topic_end> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.