What is the purpose of the SizedBox widget in Flutter?
The SizedBox widget is used to create a box with a fixed width and height. It can add empty space or force a widget to have a specific size.
Click to reveal answer
beginner
How does the Padding widget affect its child widget?
The Padding widget adds empty space around its child inside the parent widget, pushing the child inward by the specified padding values.
Click to reveal answer
beginner
Which property of SizedBox controls its width and height?
The width and height properties control the size of the SizedBox. You can set either or both to fix the size.
Click to reveal answer
beginner
Can Padding be used without a child widget?
No, Padding requires a child widget to apply padding around. Without a child, it has no visible effect.
Click to reveal answer
intermediate
What is the difference between SizedBox and Padding?
SizedBox sets a fixed size or empty space, while Padding adds space inside around a child widget. SizedBox controls size, Padding controls space inside.
Click to reveal answer
What happens if you use SizedBox(width: 50, height: 50) without a child widget?
ACreates an empty box of 50x50 pixels
BThrows an error
CCreates a box that fills the screen
DIgnores the size and collapses
✗ Incorrect
SizedBox with width and height but no child creates an empty box of that size.
Which widget would you use to add space inside a button around its label?
ASizedBox
BPadding
CContainer
DExpanded
✗ Incorrect
Padding adds space inside around the child widget, perfect for spacing inside buttons.
If you want to add 10 pixels of space between two widgets vertically, which widget can you use?
ASizedBox with height: 10
BPadding with EdgeInsets.all(10)
CContainer with margin 10
DExpanded with flex 10
✗ Incorrect
SizedBox with height 10 creates vertical space between widgets.
What does Padding(padding: EdgeInsets.symmetric(horizontal: 20)) do?
AAdds 20 pixels padding on all sides
BAdds 20 pixels padding on top and bottom
CAdds no padding
DAdds 20 pixels padding on left and right sides
✗ Incorrect
EdgeInsets.symmetric(horizontal: 20) adds padding only on left and right sides.
Which widget can force a child widget to have a fixed size?
APadding
BFlexible
CSizedBox
DAlign
✗ Incorrect
SizedBox can force its child to have a fixed width and height.
Explain how you would use SizedBox and Padding together to create space around a button.
Think about space outside the button and space inside the button label.
You got /3 concepts.
Describe the visual difference between using SizedBox and Padding in a Flutter layout.
Consider how each affects the child's size and position.
You got /3 concepts.
Practice
(1/5)
1. What does the SizedBox widget do in Flutter?
easy
A. It adds space inside a widget around its content.
B. It creates a box with a fixed width and height.
C. It changes the color of a widget.
D. It handles user input events.
Solution
Step 1: Understand SizedBox purpose
SizedBox is used to create a box with fixed width and height to control space.
Step 2: Compare with Padding
Padding adds space inside a widget, not fixes size.
Final Answer:
It creates a box with a fixed width and height. -> Option B
Quick Check:
SizedBox fixes size = A [OK]
Hint: SizedBox fixes size; Padding adds inner space [OK]
Common Mistakes:
Confusing Padding with SizedBox
Thinking SizedBox adds inner space
Assuming SizedBox changes color
2. Which of the following is the correct syntax to add 20 pixels of padding on all sides of a widget?
easy
A. Padding(padding: EdgeInsets.all(20), child: Text('Hello'))
B. SizedBox(padding: EdgeInsets.all(20), child: Text('Hello'))
C. Padding(margin: EdgeInsets.all(20), child: Text('Hello'))
D. SizedBox(width: 20, height: 20, child: Text('Hello'))
Solution
Step 1: Identify Padding syntax
Padding uses padding: EdgeInsets.all(value) to add space inside.
Step 2: Check other options
SizedBox does not have padding property; margin is not valid in Padding widget.
Final Answer:
Padding(padding: EdgeInsets.all(20), child: Text('Hello')) -> Option A
Quick Check:
Padding with EdgeInsets.all = B [OK]
Hint: Padding uses EdgeInsets.all for uniform space [OK]
Common Mistakes:
Using SizedBox with padding property
Confusing margin with padding
Using SizedBox to add padding
3. What will be the size of the red box on screen in this code?
C. EdgeInsets.symmetric requires two parameters: horizontal and vertical
D. EdgeInsets.symmetric should be EdgeInsets.all
Solution
Step 1: Check EdgeInsets.symmetric parameters
EdgeInsets.symmetric requires named parameters horizontal and/or vertical, not a single number.
Step 2: Validate other options
Padding can have Text child; comma is present; EdgeInsets.all is different but not error.
Final Answer:
EdgeInsets.symmetric requires two parameters: horizontal and vertical -> Option C
Quick Check:
EdgeInsets.symmetric needs named params = C [OK]
Hint: EdgeInsets.symmetric needs horizontal and/or vertical named args [OK]
Common Mistakes:
Passing single number to EdgeInsets.symmetric
Confusing EdgeInsets.symmetric with EdgeInsets.all
Thinking Padding can't wrap Text
5. You want to create a button with fixed width 150, height 50, and 10 pixels padding inside around the text. Which widget tree achieves this correctly?
hard
A. SizedBox(width: 150, height: 50, child: Padding(padding: EdgeInsets.all(10), child: Text('Click')))
B. SizedBox(width: 150, height: 50, child: Text('Click'))
C. Container(width: 150, height: 50, margin: EdgeInsets.all(10), child: Text('Click'))
D. Padding(padding: EdgeInsets.all(10), child: SizedBox(width: 150, height: 50, child: Text('Click')))
Solution
Step 1: Understand padding inside fixed size
To have fixed outer size with padding inside around text, use SizedBox containing Padding containing Text. SizedBox constrains total to 150x50; Padding adds space within that.