Bird
Raised Fist0
Fluttermobile~20 mins

SizedBox and Padding in Flutter - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
SizedBox and Padding Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate
2: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))
  ]
)
AA red box 100x50 pixels overlapping a blue box 50x50 pixels
BA red box 100x50 pixels, then a blue box 90x90 pixels with padding inside
COnly a red box 100x50 pixels is visible; blue box is hidden
DA red box 100x50 pixels, then a blue box 50x50 pixels with 20 pixels space around it
Attempts:
2 left
💡 Hint
Remember that Padding adds space outside its child, while SizedBox sets fixed size.
❓ lifecycle
intermediate
1: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?
APadding does not change until app restart
BPadding causes a runtime error if changed dynamically
CThe widget rebuilds and the padding space updates immediately
DPadding value changes but layout stays the same
Attempts:
2 left
💡 Hint
Think about how Flutter rebuilds widgets on state change.
📝 Syntax
advanced
1: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')
  ]
)
ASizedBox(height: 30),
BSizedBox(width: 30),
CPadding(padding: EdgeInsets.symmetric(horizontal: 30)),
DContainer(margin: EdgeInsets.all(30)),
Attempts:
2 left
💡 Hint
Vertical space means height, not width.
🔧 Debug
advanced
1: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'))
ABecause EdgeInsets.zero means no padding is applied
BBecause Padding requires a Container child to work
CBecause Text widget ignores Padding always
DBecause Padding only works with SizedBox children
Attempts:
2 left
💡 Hint
Check the padding value used.
🧠 Conceptual
expert
2: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.
ASizedBox adds empty space around child; Padding forces child to fixed size
BSizedBox forces its child to a fixed size; Padding adds empty space around its child without changing child's size
CBoth SizedBox and Padding force child to fixed size but Padding adds color
DSizedBox and Padding both only add margin outside the child widget
Attempts:
2 left
💡 Hint
Think about size constraints vs spacing.

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

  1. Step 1: Understand SizedBox purpose

    SizedBox is used to create a box with fixed width and height to control space.
  2. Step 2: Compare with Padding

    Padding adds space inside a widget, not fixes size.
  3. Final Answer:

    It creates a box with a fixed width and height. -> Option B
  4. 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

  1. Step 1: Identify Padding syntax

    Padding uses padding: EdgeInsets.all(value) to add space inside.
  2. Step 2: Check other options

    SizedBox does not have padding property; margin is not valid in Padding widget.
  3. Final Answer:

    Padding(padding: EdgeInsets.all(20), child: Text('Hello')) -> Option A
  4. 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?
SizedBox(
  width: 100,
  height: 50,
  child: Container(color: Colors.red),
)
medium
A. Zero size because no child size set
B. Size depends on Container's content
C. Full screen size
D. 100 pixels wide and 50 pixels tall

Solution

  1. Step 1: Understand SizedBox effect

    SizedBox fixes the child's size to width 100 and height 50 pixels.
  2. Step 2: Container inside SizedBox

    Container will fill the SizedBox size, so red box is 100x50 pixels.
  3. Final Answer:

    100 pixels wide and 50 pixels tall -> Option D
  4. Quick Check:

    SizedBox fixes size = A [OK]
Hint: SizedBox sets fixed size regardless of child content [OK]
Common Mistakes:
  • Thinking Container size controls box size
  • Assuming full screen size
  • Believing zero size without explicit child size
4. Identify the error in this code snippet:
Padding(
  padding: EdgeInsets.symmetric(10),
  child: Text('Hello'),
)
medium
A. Missing comma after child widget
B. Padding widget cannot have Text as child
C. EdgeInsets.symmetric requires two parameters: horizontal and vertical
D. EdgeInsets.symmetric should be EdgeInsets.all

Solution

  1. Step 1: Check EdgeInsets.symmetric parameters

    EdgeInsets.symmetric requires named parameters horizontal and/or vertical, not a single number.
  2. Step 2: Validate other options

    Padding can have Text child; comma is present; EdgeInsets.all is different but not error.
  3. Final Answer:

    EdgeInsets.symmetric requires two parameters: horizontal and vertical -> Option C
  4. 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

  1. 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.
  2. Step 2: Analyze correct structure

    SizedBox(width: 150, height: 50, child: Padding(padding: EdgeInsets.all(10), child: Text('Click'))) fixes outer size, adds inner padding.
  3. Step 3: Check other options

    SizedBox(width: 150, height: 50, child: Text('Click')) lacks padding; Container(width: 150, height: 50, margin: EdgeInsets.all(10), child: Text('Click')) adds margin outside (total larger), no inner padding; Padding(padding: EdgeInsets.all(10), child: SizedBox(width: 150, height: 50, child: Text('Click'))) adds padding outside fixed box (total 170x70), no inner padding.
  4. Final Answer:

    SizedBox(width: 150, height: 50, child: Padding(padding: EdgeInsets.all(10), child: Text('Click'))) -> Option A
  5. Quick Check:

    SizedBox containing Padding = A [OK]
Hint: Padding inside SizedBox for fixed size with inner space [OK]
Common Mistakes:
  • Putting SizedBox inside Padding (adds outer space)
  • Using Container with margin
  • Forgetting to add padding
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard