What does Expanded do?
Expanded forces its child to fill all remaining space in a Row or Column.
Control how widgets share space
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 Expanded widget forces its child to fill all available space inside a Row or Column. This is essential when you want widgets to share horizontal or vertical space proportionally.
1Row(2children: [3Container(width: 100, color: Colors.red),4Expanded(5child: Container(color: Colors.blue), // Takes remaining space6),7],8)910// Multiple Expanded widgets share space equally11Row(12children: [13Expanded(child: Container(color: Colors.red)),14Expanded(child: Container(color: Colors.blue)),15Expanded(child: Container(color: Colors.green)),16],17) // Each gets 1/3 of the width
The flex property controls the ratio of space each Expanded widget receives. By default, every Expanded widget has a flex value of 1, meaning they share space equally.
1Row(2children: [3Expanded(4flex: 2, // Gets 2 parts5child: Container(color: Colors.red),6),7Expanded(8flex: 1, // Gets 1 part9child: Container(color: Colors.blue),10),11],12)13// Red gets 2/3, Blue gets 1/3 of the width
Flexible is similar to Expanded, but the child is allowed to be smaller than the available space. This is useful when a widget has a preferred size but should shrink if needed.
1Row(2children: [3Flexible(4child: Container(5width: 100, // Will be 100px if space allows6color: Colors.red,7),8),9Expanded(10child: Container(color: Colors.blue),11),12],13)1415// Expanded = must fill space (FlexFit.tight)16// Flexible = can be smaller (FlexFit.loose)
Use Expanded when the widget should fill all available space. Use Flexible when the widget has a preferred size but can shrink if there is not enough room.
Here are some frequently used patterns that combine Expanded and Flexible with other widgets.
1// Search bar with button2Row(3children: [4Expanded(5child: TextField(6decoration: InputDecoration(hintText: 'Search...'),7),8),9SizedBox(width: 8),10ElevatedButton(onPressed: () {}, child: Text('Search')),11],12)1314// 70-30 split15Row(16children: [17Expanded(flex: 7, child: Image.network('https://example.com/image.jpg')),18Expanded(flex: 3, child: Text('Description')),19],20)
Use flex ratios to express product priority:
This approach creates adaptive layouts that still preserve business priorities on smaller screens.
Control how widgets share space. 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.
Expanded forces its child to fill all remaining space in a Row or Column.
Flex values create ratios: 2 parts vs 3 parts = 2:3.
Flexible uses FlexFit.loose - child can be smaller. Expanded uses FlexFit.tight - must fill.
Default flex is 1, meaning all Expanded widgets share space equally unless specified otherwise.
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