D. Missing @override annotation before build method
Solution
Step 1: Check for @override annotation
The build method should have @override to indicate it overrides the parent method.
Step 2: Verify other parts
Returning a Text widget is valid, and no constructor is required if no parameters.
Final Answer:
Missing @override annotation before build method -> Option D
Quick Check:
build method needs @override annotation [OK]
Hint: Always add @override before build method in widgets [OK]
Common Mistakes:
Ignoring missing @override warning
Thinking build must return Container only
Assuming constructor is mandatory without parameters
5. You want to create a static welcome screen using StatelessWidget that shows a centered title and a subtitle below it. Which code snippet correctly implements this?
hard
A. class WelcomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Welcome'),
Text('Enjoy your stay')
],
),
);
}
}
B. class WelcomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Welcome'),
Text('Enjoy your stay')
],
);
}
}
C. class WelcomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Row(
children: [
Text('Welcome'),
Text('Enjoy your stay')
],
);
}
}
D. class WelcomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Text('Welcome'),
subtitle: Text('Enjoy your stay'),
);
}
}
Solution
Step 1: Understand layout requirements
The title and subtitle should be centered vertically and horizontally, stacked vertically.
Step 2: Analyze options
class WelcomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Welcome'),
Text('Enjoy your stay')
],
),
);
}
} wraps a Column inside a Center widget, centering the whole column on screen. This matches the requirement.
Step 3: Check other options
class WelcomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Welcome'),
Text('Enjoy your stay')
],
);
}
} lacks Center, so column aligns top-left. class WelcomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Row(
children: [
Text('Welcome'),
Text('Enjoy your stay')
],
);
}
} uses Row which arranges horizontally. class WelcomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Text('Welcome'),
subtitle: Text('Enjoy your stay'),
);
}
} misuses Scaffold properties.
Final Answer:
Correctly centers a column with title and subtitle. -> Option A
Quick Check:
Center + Column = vertical centered texts [OK]
Hint: Use Center widget to center Column vertically and horizontally [OK]
Common Mistakes:
Forgetting to wrap Column with Center
Using Row instead of Column for vertical layout
Misusing Scaffold properties like subtitle
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.