text
stringlengths 1
372
|
---|
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.'; |
@override |
widget build(BuildContext context) { |
return ConstrainedBox( |
constraints: const BoxConstraints( |
minWidth: 70, |
minHeight: 70, |
maxWidth: 150, |
maxHeight: 150, |
), |
child: container(color: red, width: 10, height: 10), |
); |
} |
} |
////////////////////////////////////////////////// |
class example10 extends example { |
const example10({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: 10, height: 10))))'; |
@override |
final string explanation = |
'now, center allows ConstrainedBox to be any size up to the screen size.' |
'\n\n' |
'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 10 pixels, so it will end up having 70 (the MINIMUM).'; |
@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: 10, height: 10), |
), |
); |
} |
} |
////////////////////////////////////////////////// |
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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.