text
stringlengths 0
197
|
---|
),
|
),
|
),
|
],
|
)
|
<code_end>
|
The only difference if you use Flexible instead of Expanded,
|
is that Flexible lets its child have the same or smaller
|
width than the Flexible itself, while Expanded forces
|
its child to have the exact same width of the Expanded.
|
But both Expanded and Flexible ignore their children’s width
|
when sizing themselves.
|
info Note
|
This means that it’s impossible to expand Row children
|
proportionally to their sizes. The Row either uses
|
the exact child’s width, or ignores it completely
|
when you use Expanded or Flexible.
|
<topic_end>
|
<topic_start>
|
Example 28
|
<code_start>
|
Scaffold(
|
body: Container(
|
color: blue,
|
child: const Column(
|
children: [
|
Text('Hello!'),
|
Text('Goodbye!'),
|
],
|
),
|
),
|
)
|
<code_end>
|
The screen forces the Scaffold to be exactly the same size
|
as the screen, so the Scaffold fills the screen.
|
The Scaffold tells the Container that it can be any size it wants,
|
but not bigger than the screen.
|
info Note
|
When a widget tells its child that it can be smaller than a
|
certain size, we say the widget supplies loose constraints
|
to its child. More on that later.
|
<topic_end>
|
<topic_start>
|
Example 29
|
<code_start>
|
Scaffold(
|
body: SizedBox.expand(
|
child: Container(
|
color: blue,
|
child: const Column(
|
children: [
|
Text('Hello!'),
|
Text('Goodbye!'),
|
],
|
),
|
),
|
),
|
)
|
<code_end>
|
If you want the Scaffold’s child to be exactly the same size
|
as the Scaffold itself, you can wrap its child with
|
SizedBox.expand.
|
<topic_end>
|
<topic_start>
|
Tight vs loose constraints
|
It’s very common to hear that some constraint is
|
“tight” or “loose”, so what does that mean?
|
<topic_end>
|
<topic_start>
|
Tight constraints
|
A tight constraint offers a single possibility,
|
an exact size. In other words, a tight constraint
|
has its maximum width equal to its minimum width;
|
and has its maximum height equal to its minimum height.
|
An example of this is the App widget,
|
which is contained by the RenderView class:
|
the box used by the child returned by the
|
application’s build function is given a constraint
|
that forces it to exactly fill the application’s content area
|
(typically, the entire screen).
|
Another example: if you nest a bunch of boxes inside
|
each other at the root of your application’s render tree,
|
they’ll all exactly fit in each other,
|
forced by the box’s tight constraints.
|
If you go to Flutter’s box.dart file and search for
|
the BoxConstraints constructors,
|
you’ll find the following:
|
If you revisit Example 2,
|
the screen forces the red Container to be
|
exactly the same size as the screen.
|
The screen achieves that, of course, by passing tight
|
constraints to the Container.
|
<topic_end>
|
<topic_start>
|
Loose constraints
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.