What if you could build your first app that runs everywhere with just a few lines of code?
Why First Flutter app (Hello World)? - Purpose & Use Cases
Imagine you want to create a simple app that shows "Hello World" on your phone screen. Without Flutter, you might have to write a lot of complicated code for Android and iOS separately, each with different languages and tools.
This manual way is slow and confusing. You spend hours just setting up, and small mistakes can break your app. It's like trying to build two houses at once with different blueprints and tools.
Flutter lets you write one simple code that works on both Android and iOS. It handles all the hard parts for you, so you can focus on making your app show "Hello World" quickly and easily.
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView tv = findViewById(R.id.textView); tv.setText("Hello World"); } }
import 'package:flutter/material.dart'; void main() => runApp(MaterialApp(home: Scaffold(body: Center(child: Text('Hello World')))));
With Flutter, you can build beautiful apps for multiple devices fast, using one simple code.
Think of a small business owner who wants an app to greet customers. Flutter lets them create that app quickly without learning two different programming languages.
Manual app building for each platform is slow and complex.
Flutter simplifies this by using one codebase for all platforms.
Starting with a "Hello World" app shows how easy and fast Flutter development can be.
Practice
Solution
Step 1: Identify the Flutter app entry point
Flutter apps always start by calling the runApp() function to load the widget tree.Step 2: Confirm the correct function name
The function runApp() is the official way to start the app and display widgets on screen.Final Answer:
runApp() -> Option BQuick Check:
App start function = runApp() [OK]
- Using startApp() instead of runApp()
- Confusing with main() function
- Trying to use launchApp()
Solution
Step 1: Understand widget nesting in Flutter
Widgets are nested by passing child widgets as parameters, so Center(child: Text('Hello World')) is correct.Step 2: Check syntax correctness
Options A, B and C are invalid: A misses the named parameter 'child', B and C use invalid methods.Final Answer:
Center(child: Text('Hello World')) -> Option CQuick Check:
Center widget uses child: Text(...) [OK]
- Omitting 'child:' label
- Using invalid method calls on Text
- Trying to call center() on Text widget
void main() {
runApp(MaterialApp(
home: Scaffold(
body: Center(
child: Text('Hello Flutter'),
),
),
));
}Solution
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.Step 2: Determine the visible output
The Text widget with 'Hello Flutter' is centered on the screen inside Scaffold's body.Final Answer:
Centered text 'Hello Flutter' -> Option AQuick Check:
Center widget centers Text = centered text [OK]
- Thinking Scaffold body is empty
- Assuming default alignment is top-left
- Expecting error without syntax issues
void main() {
runApp(MaterialApp(
home: Scaffold(
body: Center(
child: Text('Hello World')
),
),
));
}Solution
Step 1: Check widget parameter separators
In Flutter, Center has only one named parameter (child: Text(...)); no comma is needed after a single parameter.Step 2: Verify parentheses and semicolons
Parentheses are balanced and semicolons are correctly placed after runApp call. Code runs fine.Final Answer:
No error, code is correct -> Option AQuick Check:
Single named param needs no trailing comma [OK]
- Thinking comma is required after single child
- Confusing semicolon with comma
- Ignoring Dart's flexible comma syntax
Solution
Step 1: Understand Scaffold background color property
Scaffold uses backgroundColor property to set the screen background color. It must be inside Scaffold's constructor.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).Final Answer:
runApp(MaterialApp(home: Scaffold(backgroundColor: Colors.blue, body: Center(child: Text('Hello World'))))); -> Option DQuick Check:
Scaffold backgroundColor = Colors.blue [OK]
- Putting backgroundColor in MaterialApp
- Using invalid color names
- Forgetting to wrap Text in Center
Ready to prove it?
Pass the test and this pattern moves unknown
