text
stringlengths
1
372
return row(
children: [
flexible(
child: container(
color: red,
child: const text(
'this is a very long text that won\'t fit the line.',
style: big,
),
),
),
flexible(
child: container(
color: green,
child: const text(
'goodbye!',
style: big,
),
),
),
],
);
}
}
//////////////////////////////////////////////////
class example28 extends example {
const example28({super.key});
@override
final code = 'scaffold(\n'
' body: container(color: blue,\n'
' child: column(\n'
' children: [\n'
' Text(\'Hello!\'),\n'
' Text(\'Goodbye!\')])))';
@override
final string explanation =
'the screen forces the scaffold to be exactly the same size as the screen, '
'so the scaffold fills the screen.'
'\n\n'
'the scaffold tells the container that it can be any size it wants, but not bigger than the screen.'
'\n\n'
'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.';
@override
widget build(BuildContext context) {
return scaffold(
body: container(
color: blue,
child: const column(
children: [
Text('Hello!'),
Text('Goodbye!'),
],
),
),
);
}
}
//////////////////////////////////////////////////
class example29 extends example {
const example29({super.key});
@override
final code = 'scaffold(\n'
' body: container(color: blue,\n'
' child: SizedBox.expand(\n'
' child: column(\n'
' children: [\n'
' Text(\'Hello!\'),\n'
' Text(\'Goodbye!\')]))))';
@override
final string explanation =
'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.'
'\n\n'
'when a widget tells its child that it must be of a certain size, '
'we say the widget supplies "tight" constraints to its child. more on that later.';
@override
widget build(BuildContext context) {
return scaffold(
body: SizedBox.expand(
child: container(
color: blue,
child: const column(
children: [
Text('Hello!'),
Text('Goodbye!'),
],
),
),
),
);
}
}
//////////////////////////////////////////////////
<code_end>
if you prefer, you can grab the code from
this GitHub repo.
the examples are explained in the following sections.
<topic_end>
<topic_start>