Challenge - 5 Problems
Expanded and Flexible Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
Understanding Expanded widget behavior
Given a Row with two children: a fixed-width Container and an Expanded Container, what will be the width of the Expanded Container if the Row's total width is 300 pixels and the fixed Container is 100 pixels wide?
Flutter
Row(
children: [
Container(width: 100, color: Colors.red),
Expanded(child: Container(color: Colors.blue))
]
)Attempts:
2 left
💡 Hint
Expanded takes all remaining space after fixed widgets.
✗ Incorrect
The fixed Container takes 100 pixels, so Expanded fills the rest: 300 - 100 = 200 pixels.
❓ ui_behavior
intermediate2:00remaining
Flexible with fit property effect
What is the difference in behavior between Flexible with fit: FlexFit.tight and Flexible with fit: FlexFit.loose inside a Row?
Flutter
Row(
children: [
Flexible(fit: FlexFit.tight, child: Container(color: Colors.green)),
Flexible(fit: FlexFit.loose, child: Container(color: Colors.yellow))
]
)Attempts:
2 left
💡 Hint
Think about how much space the child is forced to occupy.
✗ Incorrect
FlexFit.tight makes the child fill all the space allocated; FlexFit.loose allows the child to be smaller if it chooses.
❓ lifecycle
advanced2:30remaining
Effect of multiple Expanded widgets with flex values
In a Row with three Expanded children having flex values 1, 2, and 3 respectively, how is the available horizontal space divided among them?
Flutter
Row(
children: [
Expanded(flex: 1, child: Container(color: Colors.red)),
Expanded(flex: 2, child: Container(color: Colors.green)),
Expanded(flex: 3, child: Container(color: Colors.blue))
]
)Attempts:
2 left
💡 Hint
Flex values act like weights for space distribution.
✗ Incorrect
The total flex is 6 (1+2+3). Space is split proportionally: 1/6, 2/6, and 3/6.
🔧 Debug
advanced2:30remaining
Why does this layout overflow error occur?
Consider a Row with two children: a Container with fixed width 200 and an Expanded child. The Row is inside a parent with width 250. Why does a horizontal overflow error occur?
Flutter
Container( width: 250, child: Row( children: [ Container(width: 200, color: Colors.red), Expanded(child: Container(color: Colors.blue)) ] ) )
Attempts:
2 left
💡 Hint
Think about how Expanded passes constraints to its child.
✗ Incorrect
Expanded gives its child max width of remaining space (50 pixels), but if the child tries to be bigger, overflow happens.
🧠 Conceptual
expert3:00remaining
Choosing between Expanded and Flexible
Which statement best describes when to use Expanded versus Flexible in Flutter layouts?
Attempts:
2 left
💡 Hint
Think about how strictly the child fills space.
✗ Incorrect
Expanded forces the child to fill remaining space; Flexible allows the child to be smaller if it wants.