text
stringlengths 1
372
|
|---|
),
|
child: container(color: red, width: 100, height: 100),
|
),
|
)
|
<code_end>
|
center allows ConstrainedBox to be any size up to the
|
screen size. the ConstrainedBox imposes additional
|
constraints from its constraints parameter onto its child.
|
the container must be between 70 and 150 pixels.
|
it wants to have 100 pixels, and that’s the size it has,
|
since that’s between 70 and 150.
|
<topic_end>
|
<topic_start>
|
example 13
|
<code_start>
|
UnconstrainedBox(
|
child: container(color: red, width: 20, height: 50),
|
)
|
<code_end>
|
the screen forces the UnconstrainedBox to be exactly
|
the same size as the screen. however, the UnconstrainedBox
|
lets its child container be any size it wants.
|
<topic_end>
|
<topic_start>
|
example 14
|
<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>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.