text
stringlengths 0
197
|
---|
final String explanation =
|
'The screen forces the Center to be exactly the same size as the screen, '
|
'so the Center fills the screen.'
|
'\n\n'
|
'The Center tells the Container that it can be any size it wants, but not bigger than the screen.'
|
'\n\n'
|
'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.'
|
'\n\n'
|
'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 documentation to understand how it behaves, depending on the circumstances. ';
|
@override
|
Widget build(BuildContext context) {
|
return Center(
|
child: Container(color: red),
|
);
|
}
|
}
|
class Example7 extends Example {
|
const Example7({super.key});
|
@override
|
final code = 'Center(\n'
|
' child: Container(color: red\n'
|
' child: Container(color: green, width: 30, height: 30)))';
|
@override
|
final String explanation =
|
'The screen forces the Center to be exactly the same size as the screen, '
|
'so the Center fills the screen.'
|
'\n\n'
|
'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.'
|
'\n\n'
|
'The red Container tells its child that it can be any size it wants, but not bigger than the screen.'
|
'\n\n'
|
'The child is a green Container that wants to be 30x30.'
|
'\n\n'
|
'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 color isn\'t visible, since the green Container entirely covers all of the red Container.';
|
@override
|
Widget build(BuildContext context) {
|
return Center(
|
child: Container(
|
color: red,
|
child: Container(color: green, width: 30, height: 30),
|
),
|
);
|
}
|
}
|
class Example8 extends Example {
|
const Example8({super.key});
|
@override
|
final code = 'Center(\n'
|
' child: Container(color: red\n'
|
' padding: const EdgeInsets.all(20),\n'
|
' child: Container(color: green, width: 30, height: 30)))';
|
@override
|
final String explanation =
|
'The red Container sizes itself to its children size, but it takes its own padding into consideration. '
|
'So it is also 30x30 plus padding. '
|
'The red color is visible because of the padding, and the green Container has the same size as in the previous example.';
|
@override
|
Widget build(BuildContext context) {
|
return Center(
|
child: Container(
|
padding: const EdgeInsets.all(20),
|
color: red,
|
child: Container(color: green, width: 30, height: 30),
|
),
|
);
|
}
|
}
|
class Example9 extends Example {
|
const Example9({super.key});
|
@override
|
final code = 'ConstrainedBox(\n'
|
' constraints: BoxConstraints(\n'
|
' minWidth: 70, minHeight: 70,\n'
|
' maxWidth: 150, maxHeight: 150),\n'
|
' child: Container(color: red, width: 10, height: 10)))';
|
@override
|
final String explanation =
|
'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.'
|
'\n\n'
|
'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.';
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.