text
stringlengths 1
372
|
|---|
the child is a green container that wants to
|
be 30 × 30. given that the red container sizes itself to
|
the size of its child, it is also 30 × 30.
|
the red color isn’t visible because the green container
|
entirely covers the red container.
|
<topic_end>
|
<topic_start>
|
example 8
|
<code_start>
|
center(
|
child: container(
|
padding: const EdgeInsets.all(20),
|
color: red,
|
child: container(color: green, width: 30, height: 30),
|
),
|
)
|
<code_end>
|
the red container sizes itself to its children’s size,
|
but it takes its own padding into consideration.
|
so it is also 30 × 30 plus padding.
|
the red color is visible because of the padding,
|
and the green container has the same size as
|
in the previous example.
|
<topic_end>
|
<topic_start>
|
example 9
|
<code_start>
|
ConstrainedBox(
|
constraints: const BoxConstraints(
|
minWidth: 70,
|
minHeight: 70,
|
maxWidth: 150,
|
maxHeight: 150,
|
),
|
child: container(color: red, width: 10, height: 10),
|
)
|
<code_end>
|
you might guess that the container has to be
|
between 70 and 150 pixels, but you would be wrong.
|
the ConstrainedBox only imposes additional constraints
|
from those it receives from its parent.
|
here, the screen forces the ConstrainedBox to be exactly
|
the same size as the screen, so it tells its child container
|
to also assume the size of the screen, thus ignoring its
|
constraints parameter.
|
<topic_end>
|
<topic_start>
|
example 10
|
<code_start>
|
center(
|
child: ConstrainedBox(
|
constraints: const BoxConstraints(
|
minWidth: 70,
|
minHeight: 70,
|
maxWidth: 150,
|
maxHeight: 150,
|
),
|
child: container(color: red, width: 10, height: 10),
|
),
|
)
|
<code_end>
|
now, 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 10 pixels,
|
so it ends up having 70 (the minimum).
|
<topic_end>
|
<topic_start>
|
example 11
|
<code_start>
|
center(
|
child: ConstrainedBox(
|
constraints: const BoxConstraints(
|
minWidth: 70,
|
minHeight: 70,
|
maxWidth: 150,
|
maxHeight: 150,
|
),
|
child: container(color: red, width: 1000, height: 1000),
|
),
|
)
|
<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 1000 pixels,
|
so it ends up having 150 (the maximum).
|
<topic_end>
|
<topic_start>
|
example 12
|
<code_start>
|
center(
|
child: ConstrainedBox(
|
constraints: const BoxConstraints(
|
minWidth: 70,
|
minHeight: 70,
|
maxWidth: 150,
|
maxHeight: 150,
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.