Challenge - 5 Problems
Flutter Hello World Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What will this Flutter app display?
Look at this Flutter code. What text will appear in the center of the screen when you run this app?
Flutter
import 'package:flutter/material.dart'; void main() => runApp(const MyApp()); class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return const MaterialApp( home: Scaffold( body: Center( child: Text('Hello Flutter!'), ), ), ); } }
Attempts:
2 left
💡 Hint
Look at the Text widget inside Center. It shows the exact string displayed.
✗ Incorrect
The Text widget inside Center displays 'Hello Flutter!'. This is what appears in the app's center.
📝 Syntax
intermediate2:00remaining
Which option fixes the syntax error in this Flutter code?
This Flutter code has a syntax error. Which option fixes it so the app runs and shows 'Hello World!'?
Flutter
import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Center( child: Text('Hello World!'), widthFactor: 2.0, ), ), ); } }
Attempts:
2 left
💡 Hint
Check commas after widgets inside widget trees.
✗ Incorrect
In Flutter, commas separate widget parameters. Missing a comma after Text widget causes syntax error.
❓ lifecycle
advanced2:00remaining
What happens if you replace StatelessWidget with StatefulWidget in this app?
If you change MyApp to extend StatefulWidget but keep the same build method, what will happen when you run the app?
Flutter
import 'package:flutter/material.dart'; void main() => runApp(const MyApp()); class MyApp extends StatefulWidget { const MyApp({super.key}); @override State<MyApp> createState() => _MyAppState(); } class _MyAppState extends State<MyApp> { @override Widget build(BuildContext context) { return const MaterialApp( home: Scaffold( body: Center( child: Text('Hello World!'), ), ), ); } }
Attempts:
2 left
💡 Hint
StatefulWidget requires a State class with build method.
✗ Incorrect
Replacing StatelessWidget with StatefulWidget and providing State with build method works fine. The app shows 'Hello World!'.
advanced
2:00remaining
What happens when you add Navigator.push to this Flutter app?
This app has a button that pushes a new screen. What will the user see after tapping the button?
Flutter
import 'package:flutter/material.dart'; void main() => runApp(const MyApp()); class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Center( child: ElevatedButton( child: const Text('Go'), onPressed: () { Navigator.push( context, MaterialPageRoute(builder: (context) => const SecondScreen()), ); }, ), ), ), ); } } class SecondScreen extends StatelessWidget { const SecondScreen({super.key}); @override Widget build(BuildContext context) { return Scaffold( body: Center( child: Text('Second Screen'), ), ); } }
Attempts:
2 left
💡 Hint
Navigator.push adds a new screen on top of the current one.
✗ Incorrect
When the button is tapped, Navigator.push shows the SecondScreen widget with text 'Second Screen'.
🔧 Debug
expert2:00remaining
Why does this Flutter app throw a runtime error?
This Flutter app throws an error when run. What is the cause?
Flutter
import 'package:flutter/material.dart'; void main() => runApp(const MyApp()); class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Center( child: Text('Hello World!'), ), ), ); } } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return Container(); } }
Attempts:
2 left
💡 Hint
Check if any class names are repeated in the code.
✗ Incorrect
Defining two classes with the same name MyApp causes a compile-time error due to duplicate class definitions.