The Golden Rule: Constraints go ____, Sizes go ____
Parents pass constraints DOWN, children report sizes UP.
How Flutter widgets negotiate their size
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 Golden Rule of Flutter layout is: Constraints go down, sizes go up, and the parent sets the position.
1// LayoutBuilder shows you the constraints!2LayoutBuilder(3builder: (context, constraints) {4print('Max width: ${constraints.maxWidth}');5print('Max height: ${constraints.maxHeight}');6return Container(7width: constraints.maxWidth * 0.8, // 80% of available width8child: Text('Responsive!'),9);10},11)
Tight constraints mean that the minimum and maximum sizes are equal, so the widget must be an exact size. Loose constraints mean the minimum is zero, so the widget can be any size up to the maximum.
1// Tight constraints - SizedBox enforces exact size2SizedBox(3width: 100,4height: 100,5child: Container(6// Parent says: "be exactly 100x100"7color: Colors.blue,8child: Text('I have tight constraints'),9),10)1112// Loose constraints - Center lets child pick its own size13Center(14child: Container(15// Parent says: "be any size you want, up to max"16child: Text('I have loose constraints'),17),18)1920// Also loose - Column gives freedom21Column(22children: [23Container(24// Parent says: "be any width you want, up to max"25child: Text('Column child'),26),27],28)
"RenderBox was not laid out" usually means unbounded constraints. Fix: Wrap in SizedBox, Expanded, or give explicit size.
Some widgets like ListView have infinite constraints in their scroll direction. This can cause layout errors if the child also tries to expand infinitely.
1// ERROR: Column expands infinitely, ListView expects bounded height2Column(3children: [4ListView(...), // ERROR! Unbounded height in unbounded parent5],6)78// FIX: Give ListView bounded constraints9Column(10children: [11Expanded( // Takes remaining space12child: ListView(...),13),14],15)1617// Or explicit height18Column(19children: [20SizedBox(21height: 300,22child: ListView(...),23),24],25)
Most layout bugs are constraint misunderstandings, not widget bugs.
Debug by asking:
Use LayoutBuilder and temporary colored boxes to visualize space boundaries quickly.
How Flutter widgets negotiate their size. 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.
Parents pass constraints DOWN, children report sizes UP.
LayoutBuilder provides the constraints passed to your widget.
ListView needs bounded height. In a Column, wrap it with Expanded or SizedBox to give it constraints.
Tight constraints force a specific size because min and max are equal. SizedBox creates tight constraints.
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