Flutter: Flutter Introduction and Environment Setup
Flutter lets you build iOS, Android, Web, and Desktop apps with a single Dart codebase — like using a master key to open four doors.
📋 Prerequisites: No prior experience required
1. What You Will Learn
- Flutter framework architecture and its relationship with the Dart language
- Widget tree rendering principles (Everything is a Widget)
- Flutter 3.x new features: Impeller rendering engine, Foldable support
- Flutter SDK installation and PATH configuration on Windows/macOS/Linux
- Full workflow verification with
flutter create,flutter run, andflutter doctor
2. A Real Story from an Entrepreneur
(1) The Pain: Four Platforms, Four Codebases
Bob is an entrepreneur whose ShopApp e-commerce project needs to cover iOS, Android, Web, and Desktop simultaneously. If each platform requires its own native codebase, he would need 4 development teams and 4 codebases, with personnel costs exceeding 500 thousand USD/year. Worse yet, a promotional campaign takes 6 weeks from requirements to launch — because each team must implement it independently.
(2) Flutter's Solution
Flutter adopts a "write once, run anywhere" strategy, using Dart to write the UI layer and rendering pixels directly through its custom paint engine, without relying on native UI components.
import 'package:flutter/material.dart';
// One codebase, four platforms
void main() => runApp(const ShopApp());
class ShopApp extends StatelessWidget {
const ShopApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'ShopApp',
home: Scaffold(
appBar: AppBar(title: const Text('ShopApp')),
body: const Center(child: Text('Hello, Bob!')),
),
);
}
}
> Output: Run locally with Flutter SDK (Flutter 3.x / Dart 3.x). The Piston server does not have Flutter installed; use `flutter run` on your local machine for comparison. Actual UI/state may vary slightly across platforms.
(3) The Result: 1 Team Replaces 4
After adopting Flutter, Bob's single team maintains one codebase, launching simultaneously on all 4 platforms. Promotional campaigns shrank from 6 weeks to 1 week, and annual development costs dropped from 500 thousand USD to 150 thousand USD.
3. Flutter Technical Architecture
Flutter uses a layered architecture, from the upper Framework to the lower Engine, each with its own responsibilities.
graph TD
A[Flutter SDK] --> B[Dart SDK]
A --> C[Framework Layer]
A --> D[Engine Layer]
C --> E[Material Library]
C --> F[Cupertino Library]
D --> G[Skia / Impeller]
D --> H[Platform Embedder]
H --> I[Android]
H --> J[iOS]
H --> K[Web]
H --> L[Windows/macOS/Linux]
> Output: Run locally with Flutter SDK (Flutter 3.x / Dart 3.x). The Piston server does not have Flutter installed; use `flutter run` on your local machine for comparison. Actual UI/state may vary slightly across platforms.
(1) Framework Layer
The Framework layer is what developers interact with directly, written entirely in Dart:
- Widget layer: Declarative UI descriptions (StatelessWidget / StatefulWidget)
- Element layer: Instantiated objects of Widgets, managing tree structure
- RenderObject layer: Responsible for measurement, layout, and painting
| Layer | Responsibility | Language |
|---|---|---|
| Widget | Declare UI configuration | Dart |
| Element | Manage Widget tree diff | Dart |
| RenderObject | Layout and painting | Dart |
| Engine | Render and I/O | C++ |
(2) Engine Layer
The Engine layer is written in C++, with core components:
- Skia / Impeller: 2D graphics rendering engine, converting Dart UI instructions to GPU instructions
- Dart Runtime: JIT (development) and AOT (release) compilation
- Platform Embedder: Platform-specific embedding layer, managing event loops and threads
(3) Platform Embedder
Each platform has a different Embedder implementation, responsible for:
| Platform | Embedder | Rendering Method |
|---|---|---|
| Android | flutter_shell (Java/Kotlin) |
GPU (Vulkan/OpenGL) |
| iOS | FlutterViewController (Swift/ObjC) |
GPU (Metal) |
| Web | HTML Canvas / WebGL | CanvasKit / HTML renderer |
| Desktop | GLFW / Win32 / Cocoa | GPU |
4. Everything is a Widget
Flutter's core philosophy: everything is a Widget. Buttons, fonts, spacing, and even layout constraints are all Widgets.
(1) Widget Categories
| Type | Description | Examples |
|---|---|---|
| StatelessWidget | Immutable, builds once | Text, Icon, Image |
| StatefulWidget | Mutable state, can rebuild | TextField, Checkbox |
| RenderObjectWidget | Controls layout and painting | Flex, Stack, Positioned |
| ProxyWidget | Passes data to subtree | InheritedWidget, Provider |
▶ Example
> Output: Run locally with Flutter SDK (Flutter 3.x / Dart 3.x). The Piston server does not have Flutter installed; use `flutter run` on your local machine for comparison. Actual UI/state may vary slightly across platforms.
: StatelessWidget product card
import 'package:flutter/material.dart';
class ProductCard extends StatelessWidget {
final String name;
final double price;
const ProductCard({
super.key,
required this.name,
required this.price,
});
@override
Widget build(BuildContext context) {
return Card(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(name, style: const TextStyle(fontSize: 18)),
Text('\$${price.toStringAsFixed(2)}',
style: const TextStyle(color: Colors.green, fontSize: 16)),
],
),
),
);
}
}
> Output: Run locally with Flutter SDK (Flutter 3.x / Dart 3.x). The Piston server does not have Flutter installed; use `flutter run` on your local machine for comparison. Actual UI/state may vary slightly across platforms.
▶ Example
> Output: Run locally with Flutter SDK (Flutter 3.x / Dart 3.x). The Piston server does not have Flutter installed; use `flutter run` on your local machine for comparison. Actual UI/state may vary slightly across platforms.
: StatefulWidget counter
import 'package:flutter/material.dart';
class QuantitySelector extends StatefulWidget {
const QuantitySelector({super.key});
@override
State<QuantitySelector> createState() => _QuantitySelectorState();
}
class _QuantitySelectorState extends State<QuantitySelector> {
int _count = 1;
@override
Widget build(BuildContext context) {
return Row(
children: [
IconButton(
icon: const Icon(Icons.remove),
onPressed: () => setState(() => _count = (_count - 1).clamp(1, 99)),
),
Text('$_count', style: const TextStyle(fontSize: 20)),
IconButton(
icon: const Icon(Icons.add),
onPressed: () => setState(() => _count++),
),
],
);
}
}
> Output: Run locally with Flutter SDK (Flutter 3.x / Dart 3.x). The Piston server does not have Flutter installed; use `flutter run` on your local machine for comparison. Actual UI/state may vary slightly across platforms.
5. Environment Setup
(1) Flutter SDK Installation
| Step | Windows | macOS | Linux |
|---|---|---|---|
| Download SDK | flutter.dev/docs/get-started/install/windows | flutter.dev/docs/get-started/install/macos | flutter.dev/docs/get-started/install/linux |
| Extract path | C:\flutter |
~/development/flutter |
~/development/flutter |
| PATH config | Add to system environment variables | Add to ~/.zshrc |
Add to ~/.bashrc |
▶ Example
> Output: Run locally with Flutter SDK (Flutter 3.x / Dart 3.x). The Piston server does not have Flutter installed; use `flutter run` on your local machine for comparison. Actual UI/state may vary slightly across platforms.
: PATH configuration (macOS/Linux)
# Add Flutter to PATH in ~/.zshrc or ~/.bashrc
export PATH="$HOME/development/flutter/bin:$PATH"
# Verify installation
flutter --version
# Output: Flutter 3.x.x • channel stable
> Output: Run locally with Flutter SDK (Flutter 3.x / Dart 3.x). The Piston server does not have Flutter installed; use `flutter run` on your local machine for comparison. Actual UI/state may vary slightly across platforms.
▶ Example
> Output: Run locally with Flutter SDK (Flutter 3.x / Dart 3.x). The Piston server does not have Flutter installed; use `flutter run` on your local machine for comparison. Actual UI/state may vary slightly across platforms.
: flutter doctor check
# Run doctor to check all dependencies
flutter doctor
# Expected output:
# [✓] Flutter (Channel stable, 3.x.x)
# [✓] Android toolchain
# [✓] Chrome - develop for the web
# [✓] Android Studio
# [!] VS Code (install Flutter extension)
> Output: Run locally with Flutter SDK (Flutter 3.x / Dart 3.x). The Piston server does not have Flutter installed; use `flutter run` on your local machine for comparison. Actual UI/state may vary slightly across platforms.
(2) IDE Configuration
| IDE | Required Plugins | Recommended Plugins |
|---|---|---|
| VS Code | Flutter, Dart | Flutter Widget Snippets, Error Lens |
| Android Studio | Flutter, Dart | Flutter Intl, Riverpod Snippet |
▶ Example
> Output: Run locally with Flutter SDK (Flutter 3.x / Dart 3.x). The Piston server does not have Flutter installed; use `flutter run` on your local machine for comparison. Actual UI/state may vary slightly across platforms.
: Create your first project
# Create a new Flutter project
flutter create shop_app
# Navigate to project directory
cd shop_app
# Run on connected device or emulator
flutter run
> Output: Run locally with Flutter SDK (Flutter 3.x / Dart 3.x). The Piston server does not have Flutter installed; use `flutter run` on your local machine for comparison. Actual UI/state may vary slightly across platforms.
6. First Hello World
▶ Example
> Output: Run locally with Flutter SDK (Flutter 3.x / Dart 3.x). The Piston server does not have Flutter installed; use `flutter run` on your local machine for comparison. Actual UI/state may vary slightly across platforms.
: ShopApp Hello World
import 'package:flutter/material.dart';
void main() {
runApp(const ShopApp());
}
class ShopApp extends StatelessWidget {
const ShopApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'ShopApp',
theme: ThemeData(
colorSchemeSeed: Colors.blue,
useMaterial3: true,
),
home: const HomePage(),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('ShopApp')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.shopping_bag, size: 80, color: Colors.blue),
const SizedBox(height: 16),
const Text('Welcome to ShopApp!',
style: TextStyle(fontSize: 24)),
const SizedBox(height: 8),
Text('Million-level products, USD settlement',
style: TextStyle(fontSize: 14, color: Colors.grey[600])),
const SizedBox(height: 24),
ElevatedButton(
onPressed: () {},
child: const Text('Start Shopping'),
),
],
),
),
);
}
}
> Output: Run locally with Flutter SDK (Flutter 3.x / Dart 3.x). The Piston server does not have Flutter installed; use `flutter run` on your local machine for comparison. Actual UI/state may vary slightly across platforms.
▶ Example
> Output: Run locally with Flutter SDK (Flutter 3.x / Dart 3.x). The Piston server does not have Flutter installed; use `flutter run` on your local machine for comparison. Actual UI/state may vary slightly across platforms.
: Hot reload experience
# Start app with hot reload support
flutter run
# After modifying code, press:
# r - Hot reload (keep state, update UI)
# R - Hot restart (reset state, rebuild)
# q - Quit
# Hot reload updates UI in <1 second
# Try: change 'Welcome to ShopApp!' to 'Hello Bob!'
# Press r → UI updates instantly
> Output: Run locally with Flutter SDK (Flutter 3.x / Dart 3.x). The Piston server does not have Flutter installed; use `flutter run` on your local machine for comparison. Actual UI/state may vary slightly across platforms.
7. Flutter 3.x New Features
| Feature | Description | Impact |
|---|---|---|
| Impeller engine | Pre-compiled shaders, eliminates first-frame jank | 30%+ rendering performance improvement |
| Foldable support | Adaptive layout for foldable screens | Expanded device coverage |
| Material 3 | New design specification, dynamic color | More modern UI |
| macOS / Linux stable | Official Desktop platform support | Full 4-platform coverage |
| Rendering Engine | First Frame Time | Shader Compilation | Applicable Version |
|---|---|---|---|
| Skia | 200-500ms | Runtime JIT compilation | Flutter 2.x |
| Impeller | <50ms | Build-time AOT compilation | Flutter 3.x |
❓ FAQ
flutter doctor reports "Android licenses not accepted"?flutter doctor --android-licenses and accept each license one by one.📖 Summary
- Flutter uses a Framework + Engine layered architecture: Framework in Dart, Engine in C++
- Everything is a Widget: StatelessWidget (immutable) and StatefulWidget (mutable)
- Environment setup in three steps: install SDK → configure PATH → run
flutter doctor flutter createto create projects,flutter runto start debugging, hot reload for sub-second updates- Flutter 3.x Impeller engine eliminates first-frame jank, Material 3 provides modern design
📝 Exercises
- Basic (difficulty ⭐): Install the Flutter SDK on your computer, run
flutter doctor, and ensure at least 4 items pass. - Intermediate (difficulty ⭐⭐): Modify the Hello World example to add a Text widget that displays the current date.
- Challenge (difficulty ⭐⭐⭐): Create a Column with 3 product cards, each showing a product name and USD price. Clicking a card should display product information using a SnackBar.
← Previous | Next →