Bird
Raised Fist0
Fluttermobile~10 mins

First Flutter app (Hello World) - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to show the text 'Hello World' in the center of the screen.

Flutter
import 'package:flutter/material.dart';

void main() {
  runApp([1]());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Text('Hello World'),
        ),
      ),
    );
  }
}
Drag options to blanks, or click blank then click option'
AText
BMyApp
CCenter
DMaterialApp
Attempts:
3 left
💡 Hint
Common Mistakes
Using a widget like Text or Center directly in runApp instead of the root widget class.
Forgetting to call the root widget as a function with parentheses.
2fill in blank
medium

Complete the code to make the app title appear in the app bar.

Flutter
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: [1]('Hello Flutter'),
        ),
        body: Center(
          child: Text('Welcome!'),
        ),
      ),
    );
  }
}
Drag options to blanks, or click blank then click option'
ACenter
BScaffold
CText
DAppBar
Attempts:
3 left
💡 Hint
Common Mistakes
Using AppBar or Scaffold instead of Text for the title.
Forgetting to wrap the string in a widget.
3fill in blank
hard

Fix the error in the code to correctly display 'Hello Flutter' in the center.

Flutter
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: [1](
          child: Text('Hello Flutter'),
        ),
      ),
    );
  }
}
Drag options to blanks, or click blank then click option'
ACenter
BText
CScaffold
DMaterialApp
Attempts:
3 left
💡 Hint
Common Mistakes
Putting Text directly without Center causes text to align top-left.
Using Scaffold or MaterialApp inside body causes errors.
4fill in blank
hard

Fill both blanks to create a button that shows 'Click me' and prints a message when pressed.

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: ElevatedButton(
            onPressed: [1]() {
              print('Button pressed');
            },
            child: [2]('Click me'),
          ),
        ),
      ),
    );
  }
}
Drag options to blanks, or click blank then click option'
A()
BText
Cprint
DonPressed
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting parentheses in the function declaration.
Using print instead of Text for the button label.
5fill in blank
hard

Fill all three blanks to create a Scaffold with an AppBar titled 'Home' and a centered text 'Welcome'.

Flutter
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: [1]('Home'),
        ),
        body: [2](
          child: [3]('Welcome'),
        ),
      ),
    );
  }
}
Drag options to blanks, or click blank then click option'
AText
BCenter
DScaffold
Attempts:
3 left
💡 Hint
Common Mistakes
Using Scaffold inside body instead of Center.
Using wrong widget for title or child.

Practice

(1/5)
1. What is the main function used to start a Flutter app?
easy
A. startApp()
B. runApp()
C. beginApp()
D. launchApp()

Solution

  1. Step 1: Identify the Flutter app entry point

    Flutter apps always start by calling the runApp() function to load the widget tree.
  2. Step 2: Confirm the correct function name

    The function runApp() is the official way to start the app and display widgets on screen.
  3. Final Answer:

    runApp() -> Option B
  4. Quick Check:

    App start function = runApp() [OK]
Hint: Remember Flutter apps always start with runApp() [OK]
Common Mistakes:
  • Using startApp() instead of runApp()
  • Confusing with main() function
  • Trying to use launchApp()
2. Which of the following is the correct way to display the text 'Hello World' centered on the screen in Flutter?
easy
A. Center(Text('Hello World'))
B. Text('Hello World').center()
C. Center(child: Text('Hello World'))
D. Text.center('Hello World')

Solution

  1. Step 1: Understand widget nesting in Flutter

    Widgets are nested by passing child widgets as parameters, so Center(child: Text('Hello World')) is correct.
  2. Step 2: Check syntax correctness

    Options A, B and C are invalid: A misses the named parameter 'child', B and C use invalid methods.
  3. Final Answer:

    Center(child: Text('Hello World')) -> Option C
  4. Quick Check:

    Center widget uses child: Text(...) [OK]
Hint: Use Center(child: Text('...')) to center text [OK]
Common Mistakes:
  • Omitting 'child:' label
  • Using invalid method calls on Text
  • Trying to call center() on Text widget
3. What will be displayed on the screen when running this Flutter code?
void main() {
  runApp(MaterialApp(
    home: Scaffold(
      body: Center(
        child: Text('Hello Flutter'),
      ),
    ),
  ));
}
medium
A. Centered text 'Hello Flutter'
B. A blank screen
C. An error message
D. Text 'Hello Flutter' aligned to top-left

Solution

  1. Step 1: Analyze widget tree structure

    The MaterialApp provides app structure, Scaffold gives a page layout, Center centers its child, and Text shows the string.
  2. Step 2: Determine the visible output

    The Text widget with 'Hello Flutter' is centered on the screen inside Scaffold's body.
  3. Final Answer:

    Centered text 'Hello Flutter' -> Option A
  4. Quick Check:

    Center widget centers Text = centered text [OK]
Hint: Center widget centers its child widget on screen [OK]
Common Mistakes:
  • Thinking Scaffold body is empty
  • Assuming default alignment is top-left
  • Expecting error without syntax issues
4. Identify the error in this Flutter code snippet:
void main() {
  runApp(MaterialApp(
    home: Scaffold(
      body: Center(
        child: Text('Hello World')
      ),
    ),
  ));
}
medium
A. No error, code is correct
B. Missing semicolon after Text widget
C. Missing closing parenthesis for Center widget
D. Missing comma after Text widget

Solution

  1. Step 1: Check widget parameter separators

    In Flutter, Center has only one named parameter (child: Text(...)); no comma is needed after a single parameter.
  2. Step 2: Verify parentheses and semicolons

    Parentheses are balanced and semicolons are correctly placed after runApp call. Code runs fine.
  3. Final Answer:

    No error, code is correct -> Option A
  4. Quick Check:

    Single named param needs no trailing comma [OK]
Hint: No comma needed for single widget param [OK]
Common Mistakes:
  • Thinking comma is required after single child
  • Confusing semicolon with comma
  • Ignoring Dart's flexible comma syntax
5. You want to create a Flutter app that shows 'Hello World' in the center with a blue background. Which code snippet correctly achieves this?
hard
A. runApp(MaterialApp(home: Scaffold(body: Center(child: Text('Hello World'))), backgroundColor: Colors.blue)));
B. runApp(MaterialApp(home: Scaffold(body: Center(child: Text('Hello World')), backgroundColor: Colors.blueAccent)));
C. runApp(MaterialApp(home: Scaffold(body: Center(child: Text('Hello World')), backgroundColor: Colors.blueGrey)));
D. runApp(MaterialApp(home: Scaffold(backgroundColor: Colors.blue, body: Center(child: Text('Hello World')))));

Solution

  1. Step 1: Understand Scaffold background color property

    Scaffold uses backgroundColor property to set the screen background color. It must be inside Scaffold's constructor.
  2. Step 2: Check correct color usage

    runApp(MaterialApp(home: Scaffold(backgroundColor: Colors.blue, body: Center(child: Text('Hello World'))))); correctly uses Colors.blue inside Scaffold. A places backgroundColor on MaterialApp (invalid). C uses blueGrey (greyish), D uses blueAccent (bright accent).
  3. Final Answer:

    runApp(MaterialApp(home: Scaffold(backgroundColor: Colors.blue, body: Center(child: Text('Hello World'))))); -> Option D
  4. Quick Check:

    Scaffold backgroundColor = Colors.blue [OK]
Hint: Set backgroundColor inside Scaffold, not MaterialApp [OK]
Common Mistakes:
  • Putting backgroundColor in MaterialApp
  • Using invalid color names
  • Forgetting to wrap Text in Center
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard