Hint: Column stacks vertically, Row stacks horizontally inside it [OK]
Common Mistakes:
Thinking Row inside Column causes error
Assuming all texts are horizontal
Ignoring nested Row layout
4. Identify the error in this Flutter code snippet:
Row(
children: Text('Hello'),
)
medium
A. children should be a list of widgets, not a single widget
B. Row cannot have Text widgets as children
C. Missing comma after Text widget
D. Row requires a child parameter, not children
Solution
Step 1: Check the children parameter type
The children parameter expects a list of widgets, but here it is given a single Text widget without list brackets.
Step 2: Understand correct syntax
It should be children: [Text('Hello')] to be valid.
Final Answer:
children should be a list of widgets, not a single widget -> Option A
Quick Check:
children = list of widgets [OK]
Hint: Always wrap children widgets in square brackets [OK]
Common Mistakes:
Passing single widget without list
Confusing child and children
Forgetting brackets around children
5. You want to create a layout with three buttons arranged horizontally, each spaced evenly across the screen width. Which Flutter widget combination is best to achieve this?
hard
A. Use a Stack with Positioned widgets for each button
B. Use a Column with MainAxisAlignment.spaceEvenly and three ElevatedButton children
C. Use a Row with CrossAxisAlignment.stretch and three ElevatedButton children
D. Use a Row with MainAxisAlignment.spaceEvenly and three ElevatedButton children
Solution
Step 1: Understand horizontal arrangement
Row arranges children horizontally, which fits the requirement for buttons side by side.
Step 2: Use MainAxisAlignment.spaceEvenly
This property spaces children evenly along the main axis (horizontal for Row), distributing buttons evenly.
Step 3: Evaluate other options
Column arranges vertically, CrossAxisAlignment.stretch stretches vertically, Stack overlays widgets which is not desired.
Final Answer:
Use a Row with MainAxisAlignment.spaceEvenly and three ElevatedButton children -> Option D