0
0
Fluttermobile~20 mins

Expanded and Flexible in Flutter - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Expanded and Flexible Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2: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))
  ]
)
A200 pixels
B100 pixels
C300 pixels
D0 pixels
Attempts:
2 left
💡 Hint
Expanded takes all remaining space after fixed widgets.
ui_behavior
intermediate
2: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))
  ]
)
ABoth let children be any size they want without constraints.
BFlexFit.tight forces child to fill available space; FlexFit.loose lets child be smaller if it wants.
CBoth force children to fill all available space equally.
DFlexFit.loose forces child to fill available space; FlexFit.tight lets child be smaller if it wants.
Attempts:
2 left
💡 Hint
Think about how much space the child is forced to occupy.
lifecycle
advanced
2: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))
  ]
)
AOnly the child with flex 3 gets all the space; others get none.
BAll children get equal space regardless of flex values.
CThe space is divided in ratio 1:2:3 among the three children.
DThe first child gets all space; others get zero.
Attempts:
2 left
💡 Hint
Flex values act like weights for space distribution.
🔧 Debug
advanced
2: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))
    ]
  )
)
ABecause the fixed Container uses 200 pixels, Expanded tries to fill remaining 50 pixels, but the child inside Expanded has no width constraints and overflows.
BBecause Expanded ignores the available space and tries to be 250 pixels wide.
CBecause the Row automatically expands beyond parent width causing overflow.
DBecause Container with width 250 is too small to hold any children.
Attempts:
2 left
💡 Hint
Think about how Expanded passes constraints to its child.
🧠 Conceptual
expert
3:00remaining
Choosing between Expanded and Flexible
Which statement best describes when to use Expanded versus Flexible in Flutter layouts?
AUse Flexible when you want the child to ignore parent constraints; Expanded forces the child to shrink.
BUse Flexible only inside Columns; Expanded only inside Rows.
CExpanded and Flexible are interchangeable with no difference in behavior.
DUse Expanded when you want the child to fill all remaining space; use Flexible when you want the child to be able to be smaller than the available space.
Attempts:
2 left
💡 Hint
Think about how strictly the child fills space.