Flutter has become a popular framework for cross-platform app development. In this lesson, we'll introduce you to the basic concepts and advantages of Flutter, and guide you through the detailed steps to set up a complete development environment on different operating systems, laying the foundation for your future Flutter development journey.
I. What is Flutter?
Flutter is an open-source UI software development kit (SDK) launched by Google in 2017. It is used to build high-performance, high-fidelity cross-platform applications. It allows developers to use a single codebase to create apps that run on Android, iOS, Windows, macOS, Linux, and the web.
The core features of Flutter include:
- Single codebase: Write once, run on multiple platforms.
- Self-painted UI: Instead of relying on platform-native controls, it renders the interface itself, ensuring consistency across platforms.
- High performance: Near-native app performance with smooth scrolling at 60fps (frames per second).
- Hot Reload: Quickly view the effects of code changes, significantly improving development efficiency.
- Rich component library: Offers a large number of ready-to-use Material Design and Cupertino (iOS-style) components.
II. Cross-platform Advantages and Application Scenarios
Advantages of Cross-platform Development
- High development efficiency
- One set of code runs on multiple platforms, reducing development and maintenance costs.
- The Hot Reload feature allows developers to see the effects of code changes almost in real-time.
- UI consistency
- Maintains a consistent user experience and visual effect across different platforms.
- Avoids interface inconsistencies caused by differences in platform-native controls.
- Excellent performance
- Compared to bridging technologies like React Native, Flutter compiles directly to native code.
- The self-painting UI engine reduces cross-platform communication overhead.
- Strong community support
- Officially supported and continuously updated by Google.
- A rich ecosystem of third-party libraries and plugins.
Typical Application Scenarios
- Startup products: Quickly validate product ideas and reduce initial development costs.
- Internal enterprise applications: Tools that need to be deployed across multiple platforms with relatively fixed functions.
- Content display apps: News, e-commerce, blogs, and other apps focused on UI display.
- MVP (Minimum Viable Product): Rapidly develop product prototypes for market testing.
- Apps requiring highly customized UI: Flutter's self-painting engine can achieve complex UI effects.
Well-known apps such as Alibaba, Tencent, Google Ads, and BMW have adopted Flutter for part or all of their functions.
III. Development Environment Configuration
Setting up a Flutter development environment requires installing multiple components, and the configuration steps vary slightly across operating systems.
1. Configuration for Windows
Step 1: Install Flutter SDK
- Visit the Flutter official download page: https://flutter.dev/docs/get-started/install/windows
- Download the latest Flutter SDK zip package.
- Extract it to the directory where you want to install Flutter (e.g., C:\src\flutter).
- Configure environment variables:
- Open "Control Panel > System and Security > System > Advanced system settings > Environment Variables".
- Find Path in the user variables and click "Edit".
- Click "New" and add the path to the bin directory of Flutter (e.g., C:\src\flutter\bin).
- Click "OK" to save the settings.
Step 2: Install Android Studio
- Download Android Studio: https://developer.android.com/studio
- Run the installer and follow the wizard to install.
- On first launch, you'll be prompted to install components like Android SDK, Android SDK Platform, and Android Virtual Device. Check all and install them.
Step 3: Configure Android Environment
- Launch Android Studio.
- Open "File > Settings > Appearance & Behavior > System Settings > Android SDK".
- Ensure that the Android version corresponding to your target device is installed.
- Configure Android environment variables:
- Create a new system variable ANDROID_HOME with the value being your Android SDK path (usually C:\Users\YourUsername\AppData\Local\Android\Sdk).
- Add %ANDROID_HOME%\platform-tools to the Path variable.
2. Configuration for macOS
Step 1: Install Flutter SDK
- Visit the Flutter official download page: https://flutter.dev/docs/get-started/install/macos
- Download the latest Flutter SDK zip package.
- Extract it to the directory where you want to install Flutter (e.g., ~/development/flutter).
- Configure environment variables:
- Open the terminal and enter open ~/.bash_profile or open ~/.zshrc (depending on the shell you use).
- Add the following content: export PATH="$PATH:~/development/flutter/bin".
- Save the file and run source ~/.bash_profile or source ~/.zshrc to make the configuration take effect.
Step 2: Install Android Studio
- Download Android Studio: https://developer.android.com/studio
- Open the downloaded android-studio-ide-xxx-mac.dmg file and drag it to the Applications folder.
- On first launch, install the recommended components.
Step 3: Install Xcode (Required for iOS Development)
- Open the App Store, search for and install Xcode (over 10GB, requires an Apple ID).
- After installation, open Xcode and agree to the license agreement.
- Install Xcode command-line tools:
xcode-select --install
4 . Ensure the Xcode license agreement is signed:
sudo xcodebuild -license accept
IV. Configure Emulator / Real Device Debugging Environment
Configure Android Emulator
- Launch Android Studio.
- Click "Configure > AVD Manager" on the welcome screen.
- Click "Create Virtual Device".
- Select a device model (e.g., Pixel 6) and click "Next".
- Choose a system image (it's recommended to select a version with Google APIs), click "Download" to download it.
- After the download is complete, click "Next" and then "Finish" to create the emulator.
- Click the "Launch" button in the emulator's action bar to run the emulator.
Configure iOS Simulator (macOS Only)
- Open Xcode.
- Click "Xcode > Open Developer Tool > Simulator".
- The first launch may take a few minutes.
- You can select different devices and iOS versions through the "Hardware > Device" menu.
Configure Real Device Debugging
Android Real Device
- On your Android device, open "Settings > About Phone".
- Tap "Build Number" 7 times continuously to enable developer mode.
- Return to Settings and enter "Developer Options".
- Enable "USB Debugging" and "Install via USB" options.
- Connect your phone to the computer using a USB cable.
- On the authorization prompt that appears on your phone, check "Always allow this computer" and click "Allow".
iOS Real Device (macOS Only)
- Connect your iPhone to your Mac using a USB cable.
- Open Xcode and click "Xcode > Preferences > Accounts".
- Add your Apple ID (a free account can also be used for debugging).
- In Xcode, open the ios directory of the Flutter project (ios/Runner.xcworkspace).
- In the project settings, select your device as the run target.
- For the first run, you need to trust the developer certificate on your iPhone:
- Open "Settings > General > Device Management" on your iPhone.
- Select your Apple ID and click "Trust".
V. Verify Environment: flutter doctor Command Analysis and Troubleshooting
flutter doctor is a very useful command provided by Flutter to check if the development environment is configured correctly.
Run flutter doctor
- Open the terminal (use Command Prompt or PowerShell on Windows).
- Enter the following command:
flutter doctor
3 . The command will check all necessary components and display the results.
Output Analysis
The command output will show the status of each component in a list:
- ✅ Indicates that the component is installed and configured correctly.
- ❌ Indicates that the component is missing or misconfigured.
- ⚠️ Indicates a warning, which may affect some functions.
A typical successful output is as follows:
[✓] Flutter (Channel stable, 3.10.0, on macOS 13.3.1 22E261 darwin-arm64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.2)
[✓] Connected device (3 available)
[✓] Network resources
Common Issues and Solutions
- Android license status unknown
flutter doctor --android-licenses
Then enter y as prompted to accept all license agreements.
2 . Android Studio-related issues
- Ensure the Flutter and Dart plugins are installed:
In Android Studio, go to "File > Settings > Plugins", search for and install the "Flutter" plugin (which will automatically install the Dart plugin).
3 . Xcode-related issues
- Ensure Xcode is installed correctly and updated to the latest version.
- Run sudo xcode-select -s /Applications/Xcode.app/Contents/Developer to configure the Xcode path.
4 . Connected device not detected
- Ensure the device has debugging mode enabled.
- Try reconnecting the device.
- Restart the adb service (Android):
adb kill-server
adb start-server
5 . Network issues
- Flutter may need access to Google services. If network access is restricted, you can configure a mirror:
# Temporary configuration
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
# Permanent configuration (macOS/Linux)
echo 'export PUB_HOSTED_URL=https://pub.flutter-io.cn' >> ~/.bash_profile
echo 'export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn' >> ~/.bash_profile
source ~/.bash_profile
VI. Integrated Development Environment (IDE) Selection
Although Flutter can be developed using any text editor, the following IDEs are recommended for a better development experience:
- Android Studio
- Google's official IDE with comprehensive support for Flutter.
- Built-in emulator management and debugging tools.
- Offers features like code completion, refactoring, and syntax highlighting.
- Visual Studio Code
- A lightweight editor with fast startup speed.
- Requires the installation of Flutter and Dart plugins.
- Supports core features such as Hot Reload and debugging.
- Cross-platform with a consistent experience on Windows, macOS, and Linux.
- IntelliJ IDEA
- Based on the same platform as Android Studio, with similar features.
- The Community Edition is free, while the Ultimate Edition requires payment.
- Also requires the installation of Flutter and Dart plugins.
Top comments (0)