リリース・改善中
Flutter ガイド · 1/6
この章は現在、英語でのみ提供しています。
This chapter walks through installing the Flutter SDK, checking your environment, and creating and running a first app. Flutter apps are written in Dart, an object-oriented language from Google whose syntax will feel familiar if you know Java, TypeScript or Kotlin. The Dart SDK ships inside the Flutter SDK, so there is nothing extra to install.
There are two common ways to install it:
Flutter: New Project from the command palette, and if no SDK is found the extension offers to download and set it up for you. This is the quickest path for beginners.bin folder to your PATH.If you are comfortable with Git, you can also clone the stable channel directly:
# Clone the stable channel
git clone https://github.com/flutter/flutter.git -b stable
# macOS/Linux: add Flutter to PATH in your shell profile (~/.zshrc, ~/.bashrc)
export PATH="$HOME/flutter/bin:$PATH"
# Verify
flutter --versionOn Windows, add the bin folder of the extracted SDK (for example C:\src\flutter\bin) to the Path environment variable and open a new terminal. To move to the latest stable release later, run flutter upgrade.
One Flutter codebase can target Android, iOS, web, Windows, macOS and Linux, but each target needs its own platform tooling. flutter doctor reports what is installed and what is missing.
flutter doctor
# More detail
flutter doctor -v
# Accept the Android SDK licenses (once, for Android development)
flutter doctor --android-licensesYou only need the tools for the platforms you plan to build for:
| Target | Required tooling |
|---|---|
| Android | Android Studio (Android SDK and emulator) |
| iOS and macOS | A Mac with Xcode and CocoaPods |
| Web | Chrome |
| Windows | Visual Studio with the "Desktop development with C++" workload |
| Linux | clang, CMake, GTK development headers and related packages |
iOS apps can only be built on macOS. If you are on Windows or Linux, start with the Android emulator, Chrome or a desktop target.
Create a project with flutter create. Project names follow Dart package naming: lowercase letters and underscores.
flutter create hello_app
cd hello_app
# List connected devices, emulators and browsers
flutter devices
# Run on the default device
flutter run
# Pick a specific device
flutter run -d chrome
flutter run -d windowsUse --org com.example to set the prefix of the Android package name and iOS bundle identifier, and --platforms=android,ios to generate only the platforms you need.
The generated project is a counter app. Its entry point is the main function in lib/main.dart, and the widget passed to runApp becomes the whole screen. A minimal version looks like this:
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!')),
),
);
}
}While flutter run is active, saving a file in your editor triggers hot reload. In a terminal session, use these keys:
| Key | Action |
|---|---|
r | Hot reload: apply code changes and keep the app state |
R | Hot restart: reset the state and restart the app |
q | Quit |
Hot reload works in debug mode and is the heart of the Flutter workflow: change a widget, see the result in about a second. Changes to main or to initial state values need a hot restart.
flutter doctor to check the tooling for each target platform.flutter create and run it with flutter run.
コメント 0件
ログイン · ログインするとコメントできます。
最初のコメントを書いてみましょう。