A Container widget is a box that can hold a child widget. It lets you add padding, margins, borders, background color, and size to that child.
Click to reveal answer
beginner
How do you add space inside a Container around its child?
Use the padding property to add space inside the Container around its child widget.
Click to reveal answer
beginner
Which property of Container controls its background color?
The color property sets the background color of the Container.
Click to reveal answer
intermediate
What happens if you set both width and height in a Container?
The Container will have the fixed size you set with width and height, regardless of its child's size.
Click to reveal answer
intermediate
How can you add rounded corners to a Container?
Use the decoration property with BoxDecoration and set borderRadius to add rounded corners.
Click to reveal answer
Which property of Container adds space outside the Container?
Amargin
Bpadding
Ccolor
Dchild
✗ Incorrect
Margin adds space outside the Container, separating it from other widgets.
What type of widget can a Container hold inside it?
AOnly Text widgets
BOnly Image widgets
CMultiple widgets directly
DAny single widget
✗ Incorrect
Container can hold any single widget as its child. To hold multiple widgets, use a layout widget like Column.
How do you make a Container have a circular shape?
AUse padding equal to width
BSet color to circular
CSet width and height equal and use borderRadius with half the size
DSet margin to circle
✗ Incorrect
To make a Container circular, set equal width and height and use borderRadius with half that size.
Which property lets you add a border to a Container?
Adecoration with BoxDecoration and border
BborderRadius
Ccolor
Dpadding
✗ Incorrect
Borders are added inside the decoration property using BoxDecoration's border property.
If you want a Container to fill all available space, what should you do?
AUse padding
BSet width and height to double.infinity
CSet color to fill
DSet margin to zero
✗ Incorrect
Setting width and height to double.infinity makes the Container expand to fill available space.
Explain how you would use a Container widget to add padding, background color, and rounded corners around a Text widget.
Think about how Container wraps a child and how decoration customizes appearance.
You got /4 concepts.
Describe the difference between padding and margin in the context of a Container widget.
Imagine putting a box inside another box and spacing around or inside it.
You got /3 concepts.
Practice
(1/5)
1. What is the primary purpose of the Container widget in Flutter?
easy
A. To manage app navigation between screens
B. To handle user input events like taps and swipes
C. To fetch data from the internet
D. To hold and style a single child widget with size, color, and padding
Solution
Step 1: Understand Container's role
The Container widget is designed to hold one child widget and apply styling like size, color, padding, and margin.
Step 2: Compare with other options
Navigation, data fetching, and input handling are done by other widgets or classes, not Container.
Final Answer:
To hold and style a single child widget with size, color, and padding -> Option D
Quick Check:
Container = styling box for one child [OK]
Hint: Container styles one child widget visually [OK]
Common Mistakes:
Confusing Container with navigation widgets
Thinking Container handles user input
Assuming Container manages data fetching
2. Which of the following is the correct way to set a fixed width and height of 100 pixels for a Container?
easy
A. Container(constraints: BoxConstraints(width: 100, height: 100))
B. Container(size: Size(100, 100))
C. Container(width: 100.0, height: 100.0)
D. Container(dimensions: {width: 100, height: 100})
Solution
Step 1: Recall Container size properties
Container uses width and height properties inside a BoxConstraints via constraints or directly in width and height parameters.
Step 2: Check syntax correctness
Width and height expect double values, so 100.0 is correct. Other options use invalid syntax: no size property, constraints: BoxConstraints(width: 100, height: 100) is wrong as BoxConstraints uses minWidth/maxWidth, no dimensions.
Final Answer:
Container(width: 100.0, height: 100.0) -> Option C
Quick Check:
Width and height use double values [OK]
Hint: Use width and height as doubles for Container size [OK]
Common Mistakes:
Using non-existent 'size' or 'dimensions' properties
Using BoxConstraints with invalid 'width'/'height' parameters
Confusing Container size with padding
3. What will be the background color of this Container?
A. EdgeInsets.symmetric requires vertical parameter
B. Cannot use both color and decoration properties together
C. Text widget cannot be child of Container
D. width and height must be inside decoration
Solution
Step 1: Check Container property rules
Container's color and decoration cannot be used together because color should be inside BoxDecoration if decoration is used.
Step 2: Verify other properties
EdgeInsets.symmetric with only horizontal is valid, Text can be child, width and height are direct Container properties, not inside decoration.
Final Answer:
Cannot use both color and decoration properties together -> Option B
Quick Check:
color and decoration are mutually exclusive [OK]
Hint: Use color inside decoration or alone, not both [OK]
Common Mistakes:
Using color and decoration simultaneously
Misunderstanding EdgeInsets.symmetric usage
Placing width/height inside decoration
5. You want to create a Container with a red border of 3 pixels, rounded corners of 12 pixels, padding of 16 pixels inside, and a fixed size of 150x150. Which code snippet correctly achieves this?
Width and height are set directly on Container. Padding is set with EdgeInsets.all(16) to add space inside the border.
Step 2: Define border and rounded corners in decoration
Use BoxDecoration with border: Border.all(color: Colors.red, width: 3) for red border 3 pixels thick, and borderRadius.circular(12) for rounded corners.