text
stringlengths 1
474
|
|---|
);
|
}
|
}
|
//////////////////////////////////////////////////
|
class Example11 extends Example {
|
const Example11({super.key});
|
@override
|
final code = 'Center(\n'
|
' child: ConstrainedBox(\n'
|
' constraints: BoxConstraints(\n'
|
' minWidth: 70, minHeight: 70,\n'
|
' maxWidth: 150, maxHeight: 150),\n'
|
' child: Container(color: red, width: 1000, height: 1000))))';
|
@override
|
final String explanation =
|
'Center allows ConstrainedBox to be any size up to the screen size.'
|
'The ConstrainedBox imposes ADDITIONAL constraints from its \'constraints\' parameter onto its child'
|
'\n\n'
|
'The Container must be between 70 and 150 pixels. It wants to have 1000 pixels, so it ends up having 150 (the MAXIMUM).';
|
@override
|
Widget build(BuildContext context) {
|
return Center(
|
child: ConstrainedBox(
|
constraints: const BoxConstraints(
|
minWidth: 70,
|
minHeight: 70,
|
maxWidth: 150,
|
maxHeight: 150,
|
),
|
child: Container(color: red, width: 1000, height: 1000),
|
),
|
);
|
}
|
}
|
//////////////////////////////////////////////////
|
class Example12 extends Example {
|
const Example12({super.key});
|
@override
|
final code = 'Center(\n'
|
' child: ConstrainedBox(\n'
|
' constraints: BoxConstraints(\n'
|
' minWidth: 70, minHeight: 70,\n'
|
' maxWidth: 150, maxHeight: 150),\n'
|
' child: Container(color: red, width: 100, height: 100))))';
|
@override
|
final String explanation =
|
'Center allows ConstrainedBox to be any size up to the screen size.'
|
'ConstrainedBox imposes ADDITIONAL constraints from its \'constraints\' parameter onto its child.'
|
'\n\n'
|
'The Container must be between 70 and 150 pixels. It wants to have 100 pixels, and that\'s the size it has, since that\'s between 70 and 150.';
|
@override
|
Widget build(BuildContext context) {
|
return Center(
|
child: ConstrainedBox(
|
constraints: const BoxConstraints(
|
minWidth: 70,
|
minHeight: 70,
|
maxWidth: 150,
|
maxHeight: 150,
|
),
|
child: Container(color: red, width: 100, height: 100),
|
),
|
);
|
}
|
}
|
//////////////////////////////////////////////////
|
class Example13 extends Example {
|
const Example13({super.key});
|
@override
|
final code = 'UnconstrainedBox(\n'
|
' child: Container(color: red, width: 20, height: 50));';
|
@override
|
final String explanation =
|
'The screen forces the UnconstrainedBox to be exactly the same size as the screen.'
|
'However, the UnconstrainedBox lets its child Container be any size it wants.';
|
@override
|
Widget build(BuildContext context) {
|
return UnconstrainedBox(
|
child: Container(color: red, width: 20, height: 50),
|
);
|
}
|
}
|
//////////////////////////////////////////////////
|
class Example14 extends Example {
|
const Example14({super.key});
|
@override
|
final code = 'UnconstrainedBox(\n'
|
' child: Container(color: red, width: 4000, height: 50));';
|
@override
|
final String explanation =
|
'The screen forces the UnconstrainedBox to be exactly the same size as the screen, '
|
'and UnconstrainedBox lets its child Container be any size it wants.'
|
'\n\n'
|
'Unfortunately, in this case the Container has 4000 pixels of width and is too big to fit in the UnconstrainedBox, '
|
'so the UnconstrainedBox displays the much dreaded "overflow warning".';
|
@override
|
Widget build(BuildContext context) {
|
return UnconstrainedBox(
|
child: Container(color: red, width: 4000, height: 50),
|
);
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.