Challenge - 5 Problems
SizedBox and Padding Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What is the output of this Flutter widget tree?
Consider this Flutter code snippet. What will you see on the screen?
Flutter
Column(
children: [
SizedBox(width: 100, height: 50, child: Container(color: Colors.red)),
Padding(padding: EdgeInsets.all(20), child: Container(width: 50, height: 50, color: Colors.blue))
]
)Attempts:
2 left
💡 Hint
Remember that Padding adds space outside its child, while SizedBox sets fixed size.
✗ Incorrect
SizedBox sets the size of its child container exactly. Padding adds empty space around its child, so the blue box remains 50x50 but has 20 pixels space around it.
❓ lifecycle
intermediate1:30remaining
How does Padding affect layout during Flutter widget rebuild?
If you change the padding value dynamically in a StatefulWidget, what happens to the layout?
Attempts:
2 left
💡 Hint
Think about how Flutter rebuilds widgets on state change.
✗ Incorrect
When padding changes and setState is called, Flutter rebuilds the widget tree and updates the layout immediately to reflect new padding.
📝 Syntax
advanced1:30remaining
Which option correctly uses SizedBox to add vertical space between widgets?
You want to add 30 pixels of vertical space between two Text widgets. Which code is correct?
Flutter
Column(
children: [
Text('Hello'),
// Add vertical space here
Text('World')
]
)Attempts:
2 left
💡 Hint
Vertical space means height, not width.
✗ Incorrect
SizedBox with height adds vertical space. Width adds horizontal space. Padding with horizontal adds side space, not vertical. Container margin adds space around container but not specifically vertical between widgets.
🔧 Debug
advanced1:30remaining
Why does this Padding widget not add space around the child?
Given this code, why is there no visible space around the Text widget?
Padding(padding: EdgeInsets.zero, child: Text('Hi'))
Attempts:
2 left
💡 Hint
Check the padding value used.
✗ Incorrect
EdgeInsets.zero means zero padding, so no space is added around the child widget.
🧠 Conceptual
expert2:30remaining
What is the difference between SizedBox and Padding in Flutter layout?
Choose the best explanation of how SizedBox and Padding differ in affecting widget size and layout.
Attempts:
2 left
💡 Hint
Think about size constraints vs spacing.
✗ Incorrect
SizedBox sets exact width and height constraints on its child, changing child's size. Padding adds empty space around child but does not change child's size.