Consider this Flutter widget tree using Stack and Positioned. What will you see on the screen?
Stack(
children: [
Container(width: 100, height: 100, color: Colors.red),
Positioned(
left: 20,
top: 20,
child: Container(width: 50, height: 50, color: Colors.blue),
),
],
)Remember, Positioned places its child relative to the Stack's edges.
The red container forms the base 100x100 square. The blue container is positioned 20 pixels from the left and top inside the Stack, so it appears inside the red square offset by 20 pixels.
Given multiple Positioned widgets inside a Stack, which statement about touch event hit testing is true?
Think about which widget is drawn last and visible on top.
Flutter hit tests widgets from top to bottom visually. The topmost widget under the touch point receives the event.
Choose the Flutter code that fills the entire Stack area with a green container using Positioned.fill.
Positioned.fill does not take positional parameters like left.
Positioned.fill is a named constructor that fills the Stack. It only takes a child parameter.
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))
],
)Think about how Flutter calculates vertical position when only left is set.
Positioned requires at least two constraints for each axis. Here, vertical constraints are missing, so Flutter cannot determine vertical position.
Given a Stack with fit: StackFit.expand, what is the effect on the Stack and its children?
Consider how StackFit.expand changes Stack's size behavior.
With StackFit.expand, the Stack fills its parent constraints. Non-positioned children are forced to fill the Stack's size.