0
0
Fluttermobile~20 mins

Stack and Positioned in Flutter - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Stack and Positioned Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What is the visual output of this Flutter code?

Consider this Flutter widget tree using Stack and Positioned. What will you see on the screen?

Flutter
Stack(
  children: [
    Container(width: 100, height: 100, color: Colors.red),
    Positioned(
      left: 20,
      top: 20,
      child: Container(width: 50, height: 50, color: Colors.blue),
    ),
  ],
)
AA red square with a smaller blue square inside it, offset 20 pixels from top-left
BA blue square behind a red square, both fully overlapping
COnly a blue square visible at top-left corner
DA red square with a blue square positioned outside its bounds
Attempts:
2 left
💡 Hint

Remember, Positioned places its child relative to the Stack's edges.

lifecycle
intermediate
2:00remaining
How does Flutter handle hit testing in a Stack with Positioned widgets?

Given multiple Positioned widgets inside a Stack, which statement about touch event hit testing is true?

AOnly widgets without <code>Positioned</code> can receive touch events
BThe bottom widget always receives the touch event regardless of position
CThe topmost widget visually receives the touch event if it is hit
DTouch events are ignored inside a Stack
Attempts:
2 left
💡 Hint

Think about which widget is drawn last and visible on top.

📝 Syntax
advanced
2:00remaining
Which code snippet correctly uses Positioned.fill inside a Stack?

Choose the Flutter code that fills the entire Stack area with a green container using Positioned.fill.

AStack(children: [Positioned.fill(child: Container(color: Colors.green))])
BStack(children: [Positioned.fill(left: 0, top: 0, child: Container(color: Colors.green))])
CStack(children: [Positioned.fill(child: Container(color: Colors.green), left: 0)])
DStack(children: [Positioned(child: Container(color: Colors.green), fill: true)])
Attempts:
2 left
💡 Hint

Positioned.fill does not take positional parameters like left.

🔧 Debug
advanced
2:00remaining
Why does this Positioned widget cause a layout error?

Examine this code snippet inside a Stack. Why does it cause a layout error?

Stack(
  children: [
    Positioned(left: 10, child: Container(width: 50, height: 50, color: Colors.red))
  ],
)
ABecause Stack requires all Positioned widgets to have all four sides set
BBecause <code>width</code> and <code>height</code> cannot be set inside Positioned children
CBecause <code>left</code> must be zero or null
DBecause <code>top</code> or <code>bottom</code> is missing, so vertical position is undefined
Attempts:
2 left
💡 Hint

Think about how Flutter calculates vertical position when only left is set.

🧠 Conceptual
expert
2:00remaining
How does Stack's fit property affect its size and children layout?

Given a Stack with fit: StackFit.expand, what is the effect on the Stack and its children?

AStack shrinks to fit only positioned children, ignoring non-positioned ones
BStack expands to fill its parent, and non-positioned children fill the Stack
CStack ignores the fit property and sizes to zero
DStack sizes itself to the largest child, ignoring parent constraints
Attempts:
2 left
💡 Hint

Consider how StackFit.expand changes Stack's size behavior.