text
stringlengths 1
372
|
---|
); |
} |
} |
////////////////////////////////////////////////// |
class example25 extends example { |
const example25({super.key}); |
@override |
final code = 'row(children:[\n' |
' expanded(\n' |
' child: container(color: red, child: text(\'…\')))\n' |
' container(color: green, child: Text(\'Goodbye!\'))]'; |
@override |
final string explanation = |
'when a row\'s child is wrapped in an expanded widget, the row won\'t let this child define its own width anymore.' |
'\n\n' |
'instead, it defines the expanded width according to the other children, and only then the expanded widget forces the original child to have the expanded\'s width.' |
'\n\n' |
'in other words, once you use expanded, the original child\'s width becomes irrelevant, and is ignored.'; |
@override |
widget build(BuildContext context) { |
return row( |
children: [ |
expanded( |
child: center( |
child: container( |
color: red, |
child: const text( |
'this is a very long text that won\'t fit the line.', |
style: big, |
), |
), |
), |
), |
container(color: green, child: const Text('Goodbye!', style: big)), |
], |
); |
} |
} |
////////////////////////////////////////////////// |
class example26 extends example { |
const example26({super.key}); |
@override |
final code = 'row(children:[\n' |
' expanded(\n' |
' child: container(color: red, child: text(\'…\')))\n' |
' expanded(\n' |
' child: container(color: green, child: Text(\'Goodbye!\'))]'; |
@override |
final string explanation = |
'if all of row\'s children are wrapped in expanded widgets, each expanded has a size proportional to its flex parameter, ' |
'and only then each expanded widget forces its child to have the expanded\'s width.' |
'\n\n' |
'in other words, expanded ignores the preferred width of its children.'; |
@override |
widget build(BuildContext context) { |
return row( |
children: [ |
expanded( |
child: container( |
color: red, |
child: const text( |
'this is a very long text that won\'t fit the line.', |
style: big, |
), |
), |
), |
expanded( |
child: container( |
color: green, |
child: const text( |
'goodbye!', |
style: big, |
), |
), |
), |
], |
); |
} |
} |
////////////////////////////////////////////////// |
class example27 extends example { |
const example27({super.key}); |
@override |
final code = 'row(children:[\n' |
' flexible(\n' |
' child: container(color: red, child: text(\'…\')))\n' |
' flexible(\n' |
' child: container(color: green, child: Text(\'Goodbye!\'))]'; |
@override |
final string explanation = |
'the only difference if you use flexible instead of expanded, ' |
'is that flexible lets its child be SMALLER than the flexible width, ' |
'while expanded forces its child to have the same width of the expanded.' |
'\n\n' |
'but both expanded and flexible ignore their children\'s width when sizing themselves.' |
'\n\n' |
'this means that it\'s IMPOSSIBLE to expand row children proportionally to their sizes. ' |
'the row either uses the exact child\'s width, or ignores it completely when you use expanded or flexible.'; |
@override |
widget build(BuildContext context) { |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.