In a Stack, which child appears on top?
Children are stacked in order - last child is on top.
Overlay widgets on top of each other
Passing the Quiz & Exercises is mandatory to earn FX and proceed. If you fail, try again to gain the required FX, then the Proceed button will become available.
You can read this lesson publicly. Sign in to unlock exercises, quiz, and FX progress tracking.
Having trouble? AI is here to help
Ask context-aware questions about this lesson. Free plan: 5 questions/day. Upgrade to Premium for higher daily limits.
Use the AI button at the bottom of the screen
The Stack widget places its children on top of each other in layers, similar to how layers work in a design tool. The first child is at the bottom and the last child is on top.
1Stack(2children: [3// Bottom layer (first)4Container(5width: 200,6height: 200,7color: Colors.blue,8),9// Top layer (last)10Container(11width: 100,12height: 100,13color: Colors.red,14),15],16)
The Positioned widget lets you place a child at specific coordinates within the Stack by setting top, right, bottom, or left values.
1Stack(2children: [3Container(color: Colors.grey[200]),4Positioned(5top: 10,6right: 10,7child: Icon(Icons.close),8),9Positioned(10bottom: 20,11left: 20,12child: Text('Hello'),13),14Positioned.fill( // Fills the entire stack15child: Center(child: CircularProgressIndicator()),16),17],18)
The alignment property controls where non-positioned children are placed within the Stack by default.
1Stack(2alignment: Alignment.center, // Aligns non-positioned children3children: [4Container(width: 200, height: 200, color: Colors.blue),5Text('Centered'), // Will be centered6],7)89// Alignment options:10// topLeft, topCenter, topRight11// centerLeft, center, centerRight12// bottomLeft, bottomCenter, bottomRight
- Badge on avatar - Text over image - Loading overlay - Floating action button position
Here is a common real-world pattern where Stack is used to overlay a verification badge on top of a profile avatar.
1Stack(2children: [3CircleAvatar(4radius: 40,5backgroundImage: NetworkImage('https://...'),6),7Positioned(8bottom: 0,9right: 0,10child: Container(11padding: EdgeInsets.all(4),12decoration: BoxDecoration(13color: Colors.green,14shape: BoxShape.circle,15border: Border.all(color: Colors.white, width: 2),16),17child: Icon(Icons.check, size: 16, color: Colors.white),18),19),20],21)
When using Stack, define a clear layer order:
If layering is unclear, users can miss actions or tap the wrong element. Design with visual and interaction clarity together.
Overlay widgets on top of each other. Widgets are reusable UI blocks. You combine them like LEGO pieces to build screens.
Build confidence with basics first; speed comes later.
Sketch the widget tree first, then code from top to bottom.
Most Flutter productivity comes from understanding layout rules and composing widgets cleanly.
Children are stacked in order - last child is on top.
Wrap the child in Positioned with top/left/right/bottom values.
Positioned.fill() sets all four edges to 0, filling the Stack.
Stack's alignment property controls the default alignment of non-positioned children.
Something seems incorrect, unclear, or missing? Let us know.
FlutterCraft editorial lessons are reviewed by experienced Flutter developers and updated to stay aligned with modern Flutter and Dart best practices.
Reference docs: Flutter Documentation, Dart Language Tour, and official package documentation where relevant.
Sign in to continue with exercises and quiz for this lesson.
Sign In to Continue