Lesson 2 of 51 beginner

Meet Flutter & Dart

One Code, Beautiful Apps Everywhere

Open interactive version (quiz + challenge)

Real-world analogy

Dart is like learning to speak a language (say, English). Flutter is like having a magical art kit that lets you paint beautiful pictures using that language. You need the language (Dart) to give instructions, and the art kit (Flutter) to build gorgeous apps that work on phones, tablets, computers, and the web -- all from ONE painting!

What is it?

Flutter is Google's free toolkit for building beautiful, fast apps for mobile, web, and desktop from a single codebase. Dart is the programming language Flutter uses. Together, they let you write code once and deploy it everywhere -- Android, iOS, web, Windows, Mac, and Linux.

Real-world relevance

Companies like Google, BMW, Alibaba, eBay, and Toyota use Flutter for their apps. Flutter developers are in high demand because companies love that one team can build for ALL platforms. Learning Flutter opens doors to mobile, web, and desktop development all at once.

Key points

Code example

// Your first look at a Flutter app structure
import 'package:flutter/material.dart';

void main() {
  // runApp starts your Flutter application
  runApp(const MyApp());
}

// Every Flutter app is built from widgets
class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'My First App',
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Hello Flutter!'),
        ),
        body: const Center(
          child: Text(
            'Welcome to Flutter!',
            style: TextStyle(fontSize: 24),
          ),
        ),
      ),
    );
  }
}

Line-by-line walkthrough

  1. 1. We import Flutter's material design library -- this gives us all the widgets
  2. 2.
  3. 3. The main() function is where EVERY Dart and Flutter app starts
  4. 4. runApp() tells Flutter to start displaying our app on screen
  5. 5.
  6. 6. A comment explaining Flutter apps are made of widgets
  7. 7. MyApp is a widget class that extends StatelessWidget (does not change)
  8. 8. The constructor with super.key (required boilerplate)
  9. 9.
  10. 10. The @override annotation says we are providing our own version of build
  11. 11. The build method returns what this widget looks like on screen
  12. 12. Opening the return statement
  13. 13. MaterialApp is the root widget -- sets up Material Design styling
  14. 14. Setting the app title to 'My First App'
  15. 15. Scaffold provides the basic visual structure (app bar + body)
  16. 16. AppBar creates the top navigation bar
  17. 17. Setting the AppBar title to 'Hello Flutter!'
  18. 18. Closing the AppBar
  19. 19. The body is the main content area of the screen
  20. 20. Center widget places its child in the middle of the screen
  21. 21. Text widget displays 'Welcome to Flutter!'
  22. 22. TextStyle sets the font size to 24
  23. 23. Closing the Center, body, Scaffold, MaterialApp, and return

Spot the bug

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  Widget build(BuildContext context) {
    return Text('Hello');
  }
}
Need a hint?
When a class extends StatelessWidget and provides its own build method, what annotation is needed?
Show answer
Missing the @override annotation before the build method, and missing the const constructor. Fix: add 'const MyApp({super.key});' and add '@override' before 'Widget build'.

Explain like I'm 5

Imagine you want to draw the same picture on 6 different types of paper -- phone paper, tablet paper, computer paper, and more. Normally you would have to draw it 6 times! Flutter is like a magic photocopier: you draw your picture once (using Dart as your pencil), and Flutter automatically copies it perfectly onto all 6 types of paper. One drawing, everywhere!

Fun fact

Flutter was originally called 'Sky' and was first shown in 2015. It was renamed to Flutter and officially released in December 2018. The name 'Dart' was chosen because it is short, sharp, and hits the target -- just like the language itself!

Hands-on challenge

Go to dartpad.dev in your browser. Type: void main() { print('I am going to build amazing apps with Flutter!'); } and click Run. You just ran your first Dart code!

More resources

Open interactive version (quiz + challenge) ← Back to course: Flutter & Dart