Challenge - 5 Problems
Container Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What is the output of this Container widget code?
Consider this Flutter code snippet. What will you see on the screen?
Flutter
Container( width: 100, height: 100, color: Colors.red, child: Text('Hi'), )
Attempts:
2 left
💡 Hint
Think about the color property and the child widget inside Container.
✗ Incorrect
The Container has width and height 100, color red, and contains a Text widget showing 'Hi'. So you see a red square with 'Hi' text inside.
📝 Syntax
intermediate2:00remaining
Which option causes a syntax error in Container usage?
Look at these Container widget declarations. Which one will cause a syntax error?
Attempts:
2 left
💡 Hint
Check the commas between parameters.
✗ Incorrect
Option D is missing a comma between width and height parameters, causing a syntax error.
❓ lifecycle
advanced2:00remaining
What happens if you set both color and decoration in a Container?
Consider this Container code:
Container(
color: Colors.blue,
decoration: BoxDecoration(color: Colors.red),
width: 50,
height: 50,
)
What color will the Container show?
Attempts:
2 left
💡 Hint
Check Flutter docs about Container's color and decoration properties.
✗ Incorrect
If decoration is set, Container's color property is ignored. The decoration's color is used, so the Container is red.
advanced
2:00remaining
How to make a Container respond to taps and navigate to a new screen?
You want a Container that when tapped, opens a new screen. Which code snippet achieves this?
Attempts:
2 left
💡 Hint
Container itself does not have onTap or onPressed properties.
✗ Incorrect
Container has no onTap property. Wrapping it with GestureDetector and using Navigator.push inside onTap is correct.
🔧 Debug
expert2:00remaining
Why does this Container not show the expected background color?
This code:
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.yellow,
),
child: Text('Hello'),
)
shows no yellow background. Why?
Attempts:
2 left
💡 Hint
Think about Container size when no width or height is set.
✗ Incorrect
Container has no width or height and child Text has no background, so Container shrinks to Text size and color is not visible as background.