text
stringlengths 1
372
|
|---|
'flutter can\'t render infinite sizes, so it throws an error with the following message: '
|
'"boxconstraints forces an infinite width."';
|
@override
|
widget build(BuildContext context) {
|
return UnconstrainedBox(
|
child: container(color: colors.red, width: double.infinity, height: 100),
|
);
|
}
|
}
|
//////////////////////////////////////////////////
|
class example17 extends example {
|
const example17({super.key});
|
@override
|
final code = 'unconstrainedbox(\n'
|
' child: LimitedBox(maxWidth: 100,\n'
|
' child: container(color: colors.red,\n'
|
' width: double.infinity, height: 100));';
|
@override
|
final string explanation = 'here you won\'t get an error anymore, '
|
'because when the LimitedBox is given an infinite size by the UnconstrainedBox, '
|
'it passes a maximum width of 100 down to its child.'
|
'\n\n'
|
'if you swap the UnconstrainedBox for a center widget, '
|
'the LimitedBox won\'t apply its limit anymore (since its limit is only applied when it gets infinite constraints), '
|
'and the width of the container is allowed to grow past 100.'
|
'\n\n'
|
'this explains the difference between a LimitedBox and a ConstrainedBox.';
|
@override
|
widget build(BuildContext context) {
|
return UnconstrainedBox(
|
child: LimitedBox(
|
maxWidth: 100,
|
child: container(
|
color: colors.red,
|
width: double.infinity,
|
height: 100,
|
),
|
),
|
);
|
}
|
}
|
//////////////////////////////////////////////////
|
class example18 extends example {
|
const example18({super.key});
|
@override
|
final code = 'fittedbox(\n'
|
' child: Text(\'Some example text.\'));';
|
@override
|
final string explanation =
|
'the screen forces the FittedBox to be exactly the same size as the screen.'
|
'the text has some natural width (also called its intrinsic width) that depends on the amount of text, its font size, and so on.'
|
'\n\n'
|
'the FittedBox lets the text be any size it wants, '
|
'but after the text tells its size to the FittedBox, '
|
'the FittedBox scales the text until it fills all of the available width.';
|
@override
|
widget build(BuildContext context) {
|
return const FittedBox(
|
child: Text('Some example text.'),
|
);
|
}
|
}
|
//////////////////////////////////////////////////
|
class example19 extends example {
|
const example19({super.key});
|
@override
|
final code = 'center(\n'
|
' child: FittedBox(\n'
|
' child: Text(\'Some example text.\')));';
|
@override
|
final string explanation =
|
'but what happens if you put the FittedBox inside of a center widget? '
|
'the center lets the FittedBox be any size it wants, up to the screen size.'
|
'\n\n'
|
'the FittedBox then sizes itself to the text, and lets the text be any size it wants.'
|
'\n\n'
|
'since both FittedBox and the text have the same size, no scaling happens.';
|
@override
|
widget build(BuildContext context) {
|
return const center(
|
child: FittedBox(
|
child: Text('Some example text.'),
|
),
|
);
|
}
|
}
|
////////////////////////////////////////////////////
|
class example20 extends example {
|
const example20({super.key});
|
@override
|
final code = 'center(\n'
|
' child: FittedBox(\n'
|
' child: text(\'…\')));';
|
@override
|
final string explanation =
|
'however, what happens if FittedBox is inside of a center widget, but the text is too large to fit the screen?'
|
'\n\n'
|
'fittedbox tries to size itself to the text, but it can\'t be bigger than the screen. '
|
'it then assumes the screen size, and resizes text so that it fits the screen, too.';
|
@override
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.