text
stringlengths 0
197
|
---|
class Example2 extends Example {
|
const Example2({super.key});
|
@override
|
final code = 'Container(width: 100, height: 100, color: red)';
|
@override
|
final String explanation =
|
'The red Container wants to be 100x100, but it can\'t, '
|
'because the screen forces it to be exactly the same size as the screen.'
|
'\n\n'
|
'So the Container fills the screen.';
|
@override
|
Widget build(BuildContext context) {
|
return Container(width: 100, height: 100, color: red);
|
}
|
}
|
class Example3 extends Example {
|
const Example3({super.key});
|
@override
|
final code = 'Center(\n'
|
' child: Container(width: 100, height: 100, color: red))';
|
@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 Container that it can be any size it wants, but not bigger than the screen.'
|
'Now the Container can indeed be 100x100.';
|
@override
|
Widget build(BuildContext context) {
|
return Center(
|
child: Container(width: 100, height: 100, color: red),
|
);
|
}
|
}
|
class Example4 extends Example {
|
const Example4({super.key});
|
@override
|
final code = 'Align(\n'
|
' alignment: Alignment.bottomRight,\n'
|
' child: Container(width: 100, height: 100, color: red))';
|
@override
|
final String explanation =
|
'This is different from the previous example in that it uses Align instead of Center.'
|
'\n\n'
|
'Align also tells the Container that it can be any size it wants, but if there is empty space it won\'t center the Container. '
|
'Instead, it aligns the Container to the bottom-right of the available space.';
|
@override
|
Widget build(BuildContext context) {
|
return Align(
|
alignment: Alignment.bottomRight,
|
child: Container(width: 100, height: 100, color: red),
|
);
|
}
|
}
|
class Example5 extends Example {
|
const Example5({super.key});
|
@override
|
final code = 'Center(\n'
|
' child: Container(\n'
|
' color: red,\n'
|
' width: double.infinity,\n'
|
' height: double.infinity))';
|
@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 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.';
|
@override
|
Widget build(BuildContext context) {
|
return Center(
|
child: Container(
|
width: double.infinity, height: double.infinity, color: red),
|
);
|
}
|
}
|
class Example6 extends Example {
|
const Example6({super.key});
|
@override
|
final code = 'Center(child: Container(color: red))';
|
@override
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.