0
0
Fluttermobile~20 mins

Container widget in Flutter - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Container Mastery
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 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'),
)
AA 100x100 red square with no text visible.
BA 100x100 blue square with the text 'Hi' inside it.
CA 100x100 red square with the text 'Hi' inside it.
DAn error because Text widget cannot be a child of Container.
Attempts:
2 left
💡 Hint
Think about the color property and the child widget inside Container.
📝 Syntax
intermediate
2:00remaining
Which option causes a syntax error in Container usage?
Look at these Container widget declarations. Which one will cause a syntax error?
AContainer(width: 100, height: 100, color: Colors.green);
BContainer(width: 100, height: 100, color: Colors.green, child: Text('Hi'));
CContainer(width: 100, height: 100, child: Text('Hello'));
DContainer(width: 100 height: 100, color: Colors.green);
Attempts:
2 left
💡 Hint
Check the commas between parameters.
lifecycle
advanced
2: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?
ABlue, because color property overrides decoration.
BRed, because decoration's color overrides color property.
CPurple, a mix of blue and red colors.
DTransparent, because setting both causes an error.
Attempts:
2 left
💡 Hint
Check Flutter docs about Container's color and decoration properties.
navigation
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?
AWrap Container with GestureDetector and use Navigator.push inside onTap.
BAdd onTap property directly to Container with Navigator.push call.
CUse Container's onPressed property to call Navigator.push.
DWrap Container with InkWell but do not provide onTap callback.
Attempts:
2 left
💡 Hint
Container itself does not have onTap or onPressed properties.
🔧 Debug
expert
2: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?
ABecause Container has no size, so color is not visible.
BBecause borderRadius cannot be used with color in BoxDecoration.
CBecause Text widget covers the entire Container hiding the color.
DBecause color property must be set directly on Container, not in decoration.
Attempts:
2 left
💡 Hint
Think about Container size when no width or height is set.