text
stringlengths 1
474
|
---|
The screen forces the Center to be exactly the same |
size as the screen, so the Center fills the screen.The Center tells the red Container that it can be any size |
it wants, but not bigger than the screen. Since the red |
Container has no size but has a child, |
it decides it wants to be the same size as its child.The red Container tells its child that it can be any size |
it wants, but not bigger than the screen.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, |
), |
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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.