text
stringlengths 0
197
|
---|
Instead, it aligns the container to the bottom-right of the
|
available space.
|
<topic_end>
|
<topic_start>
|
Example 5
|
<code_start>
|
Center(
|
child: Container(
|
width: double.infinity, height: double.infinity, color: red),
|
)
|
<code_end>
|
The screen forces the Center to be exactly the
|
same size as the screen, so the Center fills the screen.
|
The Center tells the Container that it can be any size it wants,
|
but not bigger than the screen. The Container wants to be
|
of infinite size, but since it can’t be bigger than the screen,
|
it just fills the screen.
|
<topic_end>
|
<topic_start>
|
Example 6
|
<code_start>
|
Center(
|
child: Container(color: red),
|
)
|
<code_end>
|
The screen forces the Center to be exactly the
|
same size as the screen, so the Center fills the screen.
|
The Center tells the Container that it can be any
|
size it wants, but not bigger than the screen.
|
Since the Container has no child and no fixed size,
|
it decides it wants to be as big as possible,
|
so it fills the whole screen.
|
But why does the Container decide that?
|
Simply because that’s a design decision by those who
|
created the Container widget. It could have been
|
created differently, and you have to read the
|
Container API documentation to understand
|
how it behaves, depending on the circumstances.
|
<topic_end>
|
<topic_start>
|
Example 7
|
<code_start>
|
Center(
|
child: Container(
|
color: red,
|
child: Container(color: green, width: 30, height: 30),
|
),
|
)
|
<code_end>
|
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,
|
),
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.