What is the purpose of the Wrap widget in Flutter?
The Wrap widget arranges its children in horizontal or vertical runs and automatically moves to the next line or column when there is no more space, similar to how words wrap in a paragraph.
Click to reveal answer
beginner
Which property of the Wrap widget controls the spacing between the children horizontally?
The spacing property controls the horizontal space between the children inside a Wrap widget.
Click to reveal answer
intermediate
How does the Wrap widget differ from the Row widget in Flutter?
Unlike Row, which places children in a single horizontal line and may overflow, Wrap automatically moves children to the next line when space runs out, preventing overflow.
Click to reveal answer
beginner
What does the runSpacing property do in a Wrap widget?
The runSpacing property sets the vertical space between the lines (runs) of children in the Wrap widget.
Click to reveal answer
intermediate
Can the Wrap widget arrange children vertically instead of horizontally? If yes, how?
Yes, by setting the direction property to Axis.vertical, the Wrap widget arranges children vertically and wraps horizontally.
Click to reveal answer
What happens when children in a Wrap widget exceed the available horizontal space?
AThey automatically wrap to the next line.
BThey overflow and cause an error.
CThey get clipped and hidden.
DThey resize to fit in one line.
✗ Incorrect
The Wrap widget automatically moves children to the next line when there is no more horizontal space.
Which property controls the vertical spacing between lines in a Wrap widget?
Aspacing
BrunSpacing
Calignment
DcrossAxisAlignment
✗ Incorrect
The runSpacing property sets the vertical space between the runs (lines) of children.
How do you change the direction of wrapping from horizontal to vertical in a Wrap widget?
ASet <code>direction: Axis.vertical</code>
BSet <code>verticalWrap: true</code>
CSet <code>orientation: vertical</code>
DSet <code>wrapDirection: vertical</code>
✗ Incorrect
The direction property controls the main axis; setting it to Axis.vertical makes children wrap vertically.
Which widget would you use to prevent overflow when placing many buttons in a horizontal line?
ARow
BColumn
CWrap
DStack
✗ Incorrect
The Wrap widget automatically moves children to the next line to avoid overflow.
What does the spacing property in a Wrap widget affect?
AVertical space between runs
BMargin outside the widget
CPadding inside children
DHorizontal space between children
✗ Incorrect
The spacing property sets the horizontal space between children.
Explain how the Wrap widget manages layout differently from a Row widget in Flutter.
Think about what happens when you have many items in a row that don't fit on screen.
You got /4 concepts.
Describe the roles of spacing and runSpacing properties in the Wrap widget.
One controls space between items in a line, the other between lines.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of the Wrap widget in Flutter?
easy
A. To arrange child widgets in lines and wrap them when space runs out
B. To create a scrollable list of items vertically
C. To stack widgets on top of each other
D. To display a single widget centered on the screen
Solution
Step 1: Understand Wrap widget behavior
The Wrap widget arranges children in horizontal or vertical lines and wraps them to the next line when there is no more space.
Step 2: Compare options with Wrap's purpose
Only To arrange child widgets in lines and wrap them when space runs out describes this behavior correctly. Options A, B, and C describe other widgets or layouts.
Final Answer:
To arrange child widgets in lines and wrap them when space runs out -> Option A
Quick Check:
Wrap = arrange and wrap children [OK]
Hint: Wrap arranges children and moves to next line when needed [OK]
Common Mistakes:
Confusing Wrap with ListView (scrollable list)
Thinking Wrap stacks widgets like Stack widget
Assuming Wrap centers a single widget
2. Which of the following is the correct syntax to create a Wrap widget with spacing of 10 pixels between children?
easy
A. Wrap(childSpacing: 10, children: [Text('A'), Text('B')])
B. Wrap(space: 10, children: [Text('A'), Text('B')])
C. Wrap(padding: 10, children: [Text('A'), Text('B')])
D. Wrap(spacing: 10, children: [Text('A'), Text('B')])
Solution
Step 1: Identify the correct property for spacing
The Wrap widget uses the property spacing to set horizontal gaps between children.
Step 2: Check the options for correct property name
Only Wrap(spacing: 10, children: [Text('A'), Text('B')]) uses spacing correctly. Options A, B, and D use incorrect property names.
Final Answer:
Wrap(spacing: 10, children: [Text('A'), Text('B')]) -> Option D
Quick Check:
Spacing property = spacing [OK]
Hint: Use 'spacing' property for gaps between children in Wrap [OK]
Common Mistakes:
Using 'space' or 'childSpacing' instead of 'spacing'
Confusing padding with spacing
Omitting the children list
3. What will be the visual output of this Flutter code snippet?
A. Two rows: first row with 2 containers, second row with 2 containers, with 8px horizontal and 12px vertical spacing
B. One row with all 4 containers side by side with 8px spacing
C. Four rows with one container each stacked vertically
D. Two rows: first row with 3 containers, second row with 1 container, no spacing
Solution
Step 1: Calculate how many containers fit per row
Each container is 100px wide, spacing between is 8px. Two containers plus spacing: 100 + 8 + 100 = 208px, which fits in 220px width. Three containers would be 100 + 8 + 100 + 8 + 100 = 316px, too wide.
Step 2: Determine rows and spacing
So, Wrap places 2 containers in first row, then wraps to second row for next 2 containers. Horizontal spacing is 8px, vertical runSpacing is 12px.
Final Answer:
Two rows: first row with 2 containers, second row with 2 containers, with 8px horizontal and 12px vertical spacing -> Option A
Quick Check:
Wrap fits 2 per row with spacing [OK]
Hint: Add widths plus spacing to check fit per row [OK]
Common Mistakes:
Assuming all containers fit in one row
Ignoring spacing when calculating width
Confusing runSpacing with spacing
4. Identify the error in this Flutter code using Wrap:
D. The runSpacing property is placed after children, causing a syntax error
Solution
Step 1: Check property order in Wrap widget
In Flutter, the order of named parameters does not matter. runSpacing can be placed after children without error.
Step 2: Verify brackets and property usage
The children list is properly closed, and spacing is correctly used as a property, not inside children.
Final Answer:
There is no error; the code is correct -> Option C
Quick Check:
Named parameters order doesn't cause errors [OK]
Hint: Named parameters order doesn't matter in Flutter [OK]
Common Mistakes:
Thinking property order causes syntax errors
Misreading brackets in children list
Confusing property placement inside children
5. You want to create a responsive tag list using Wrap that automatically moves tags to the next line when they don't fit horizontally. Which combination of properties should you set to control the horizontal space between tags and vertical space between lines?
hard
A. Use padding for horizontal gaps and margin for vertical gaps
B. Use spacing for horizontal gaps and runSpacing for vertical gaps
C. Use mainAxisSpacing for horizontal gaps and crossAxisSpacing for vertical gaps
D. Use horizontalSpacing for horizontal gaps and verticalSpacing for vertical gaps
Solution
Step 1: Identify correct properties for Wrap spacing
The Wrap widget uses spacing to set horizontal gaps between children and runSpacing to set vertical gaps between lines.
Step 2: Eliminate incorrect property names
Properties like padding, margin, mainAxisSpacing, crossAxisSpacing, horizontalSpacing, and verticalSpacing are not valid for Wrap.
Final Answer:
Use spacing for horizontal gaps and runSpacing for vertical gaps -> Option B