The Expanded widget tells its child to fill the available space in the main axis of a Row, Column, or Flex. It expands the child to use all leftover space.
Click to reveal answer
intermediate
How does the Flexible widget differ from Expanded?
Flexible lets its child be smaller than the available space if it wants, while Expanded forces the child to fill all the available space. Flexible gives more control over child's size.
Click to reveal answer
beginner
What is the role of the flex property in Expanded and Flexible?
The flex property is a number that tells how much space this widget should take relative to its siblings. For example, flex: 2 means twice as much space as flex: 1.
Click to reveal answer
intermediate
Can Flexible widget shrink its child smaller than its intrinsic size?
Yes, Flexible can shrink its child smaller than its intrinsic size if the child allows it. This helps when you want flexible but not forced expansion.
Click to reveal answer
beginner
Why use Expanded or Flexible inside a Row or Column?
They help control how children share space. Without them, children take only the space they need. With them, you can make children grow or shrink to fill or share leftover space nicely.
Click to reveal answer
What happens if you wrap a widget with Expanded inside a Row?
AThe widget fills all remaining horizontal space.
BThe widget shrinks to its minimum size.
CThe widget disappears.
DThe widget fills all vertical space.
✗ Incorrect
Expanded makes the child fill all leftover space along the main axis, which is horizontal in a Row.
Which widget allows its child to be smaller than the available space if it wants?
AFlexible
BExpanded
CContainer
DSizedBox
✗ Incorrect
Flexible lets the child be smaller or bigger, depending on child's size and constraints.
If two Expanded widgets have flex values 1 and 3, how is space divided?
A3/4 for first, 1/4 for second
BEqual space for both
C1/4 for first, 3/4 for second
DOnly the first gets space
✗ Incorrect
The space is divided in ratio 1:3, so first gets 1/4 and second gets 3/4 of leftover space.
Which widget forces its child to fill all available space?
AFlexible
BExpanded
CPadding
DAlign
✗ Incorrect
Expanded forces the child to fill all available space along the main axis.
What is the main axis in a Column?
AHorizontal
BDiagonal
CNone
DVertical
✗ Incorrect
The main axis of a Column is vertical, so Expanded expands vertically.
Explain the difference between Expanded and Flexible widgets in Flutter.
Think about how much space the child widget takes inside a Row or Column.
You got /3 concepts.
Describe a real-life scenario where you would use Expanded inside a Row.
Imagine a toolbar with a search box that should grow to fill space.
You got /3 concepts.
Practice
(1/5)
1. What does the Expanded widget do inside a Row or Column in Flutter?
easy
A. It makes the child widget scrollable.
B. It makes the child widget ignore available space and keep its size.
C. It makes the child widget fill all the available space tightly.
D. It adds padding around the child widget.
Solution
Step 1: Understand Expanded behavior
The Expanded widget forces its child to fill the available space tightly inside a Row or Column.
Step 2: Compare with other options
Other options describe unrelated behaviors like padding or scrolling, which Expanded does not do.
Final Answer:
It makes the child widget fill all the available space tightly. -> Option C
Quick Check:
Expanded = fills space tightly [OK]
Hint: Expanded fills space tightly inside Row or Column [OK]
Common Mistakes:
Confusing Expanded with Flexible
Thinking Expanded adds padding
Assuming Expanded makes widget scrollable
2. Which of the following is the correct syntax to use Flexible with a child widget in Flutter?
easy
A. Flexible(child: Text('Hello'))
B. Flexible(Text('Hello'))
C. Flexible = Text('Hello')
D. Flexible: Text('Hello')
Solution
Step 1: Recall Flexible widget syntax
The correct syntax requires the child widget passed as a named parameter: Flexible(child: ...).
Step 2: Identify incorrect syntax
Options B, C, and D miss the named parameter or use invalid assignment syntax.
Final Answer:
Flexible(child: Text('Hello')) -> Option A
Quick Check:
Flexible uses child: parameter [OK]
Hint: Flexible requires child: parameter for its widget [OK]
What will be the relative widths of the red and blue containers on screen?
medium
A. Red fills 1/3, blue fills 2/3 of the row width
B. Red fills half the row, blue fills the other half
C. Red and blue both have fixed width 50 pixels
D. Red fills all space, blue is ignored
Solution
Step 1: Understand Expanded and Expanded with flex
Expanded takes available space tightly with default flex=1. Expanded(flex:2) takes twice the space tightly.
Step 2: Calculate relative widths
Total flex = 1 (first Expanded) + 2 (second Expanded) = 3. Red gets 1/3, blue gets 2/3 of the row width. The width: 50 is overridden by the tight constraints.
Final Answer:
Red fills 1/3, blue fills 2/3 of the row width -> Option A
Quick Check:
Flex ratio 1:2 means widths 1/3 and 2/3 [OK]
Hint: Sum flex values, divide space proportionally [OK]
Common Mistakes:
Ignoring flex values
Thinking width property overrides flex
Assuming equal widths without flex
4. This Flutter code throws an error. What is the problem?
Flexible requires a child widget to display. Here, it is missing.
Step 2: Validate other options
Container can be inside Row, flex can be 1, and Row can have any number of children.
Final Answer:
Flexible widget is missing a child widget. -> Option D
Quick Check:
Flexible must have child [OK]
Hint: Flexible always needs a child widget [OK]
Common Mistakes:
Omitting child in Flexible
Thinking flex must be >1
Assuming Row needs 3 children
5. You want two buttons side by side in a Row. The first button should take 1/4 of the width, the second button 3/4. Which Flutter widget setup achieves this best?
hard
A. Row(children: [Expanded(child: Button1), Expanded(child: Button2)])
B. Row(children: [Flexible(flex: 1, child: Button1), Flexible(flex: 3, child: Button2)])
C. Row(children: [Button1, Button2]) with fixed widths
D. Column(children: [Flexible(flex: 1, child: Button1), Flexible(flex: 3, child: Button2)])
Solution
Step 1: Understand flex distribution in Row
Using Flexible with flex values 1 and 3 divides the Row width into 4 parts, assigning 1/4 and 3/4 respectively.
Step 2: Evaluate other options
Row(children: [Expanded(child: Button1), Expanded(child: Button2)]) gives equal widths (1/2 each). Row(children: [Button1, Button2]) with fixed widths is less flexible. Column(children: [Flexible(flex: 1, child: Button1), Flexible(flex: 3, child: Button2)]) uses Column, which stacks vertically, not side by side.