Setting Up Flutter Environment
1. Installing Flutter SDK
Example: Download and Extract Flutter SDK
# Download the latest stable Flutter SDK
wget https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_3.19.0-stable.tar.xz
# Extract to your desired location
tar -xvf flutter_linux_3.19.0-stable.tar.xz -C /opt/
# Set up environment variables (add to ~/.bashrc or ~/.zshrc)
export PATH="/opt/flutter/bin:$PATH"
| Step | Description | Command |
|---|---|---|
| 1. Download SDK | Get the latest stable release from Flutter's official site | wget https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_3.19.0-stable.tar.xz |
| 2. Extract Archive | Unpack the downloaded archive to a directory of choice | tar -xvf flutter_linux_3.19.0-stable.tar.xz -C /opt/ |
| 3. Update PATH | Add Flutter to your system's PATH for global access | export PATH="/opt/flutter/bin:$PATH" |
Note: Ensure you have
unzip and curl installed on your system before downloading.Warning: The Flutter SDK requires a minimum of 2GB of free disk space to install and run.
2. Configuring Path Variables
Example: Setting PATH on macOS/Linux
# Add to ~/.zshrc or ~/.bashrc
export PATH="$PATH:/Users/<username>/flutter/bin"
# Reload shell config
source ~/.zshrc
Example: Setting PATH on Windows
# Using PowerShell
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\src\flutter\bin", "User")
# Using Command Prompt
setx PATH "%PATH%;C:\src\flutter\bin"
| Variable | Value | Description |
|---|---|---|
| PATH | /Users/<username>/flutter/bin |
Path to Flutter SDK binaries |
Note: Ensure the path matches your actual Flutter installation directory.
3. Running Flutter Doctor
| Command | Description | Output |
|---|---|---|
| flutter doctor | Checks your Flutter installation for issues and missing dependencies | Lists all detected issues, warnings, and setup status |
| flutter doctor -v | Verbose mode, provides detailed logs and diagnostics | Shows extended output including version info and environment details |
Note: The
flutter doctor command is essential for identifying and resolving setup issues in your Flutter environment.Common Issues Detected
- Missing Android Studio or Xcode
- Incorrect SDK paths
- Missing Flutter or Dart plugins
- Outdated Flutter version
4. Setting Up IDE Extensions
| Extension | Features | Installation |
|---|---|---|
| Flutter | flutter doctor, code completion, debugging |
VS Code: ext install Dart |
| Dart | Language support, formatting | VS Code: ext install Dart |
Note: Ensure
flutter doctor shows no issues before proceeding.
Setup Steps
- Install Flutter SDK
- Install Dart and Flutter extensions in VS Code
- Run
flutter doctorto verify setup
5. Configuring Android SDK and Emulators
| Component | Description | Notes |
|---|---|---|
| Android SDK | Software development kit for Android platform | Required for building Android apps with Flutter |
| Android Studio | IDE for Android development, includes SDK | Recommended for managing SDK and emulators |
| AVD (Android Virtual Device) | Emulator for testing Flutter apps | Can be created via Android Studio or command line |
Example: Setting up Android SDK Path
export ANDROID_HOME=/Users/<username>/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools
Note: Ensure Android SDK and platform tools are installed before creating AVDs.
Key Steps to Configure Android SDK and Emulators
- Install Android Studio or SDK manually
- Set ANDROID_HOME environment variable
- Add required paths to system PATH
- Create AVD using Flutter or Android Studio tools
6. Configuring iOS Simulator and Xcode
Setting up the iOS simulator and Xcode is a critical step for Flutter development on macOS. This section outlines how to configure and use the iOS simulator with Xcode.
| Step | Description | Action |
|---|---|---|
| 1 | Install Xcode | Download and install Xcode from the Mac App Store or Apple Developer Portal. |
| 2 | Install Command Line Tools | Open Terminal and run: xcode-select --install |
| 3 | Accept Xcode License | Run sudo xcodebuild -license and accept the license agreement. |
| 4 | Open Xcode | Launch Xcode and navigate to Preferences → Locations → Command Line Tools. |
| 5 | Install iOS Simulators | Go to Xcode → Preferences → Platforms and install the desired iOS SDKs. |
Note: Ensure that Xcode is updated to the latest stable version for full compatibility with Flutter.
Warning: If you encounter issues launching the iOS simulator, verify that your Flutter SDK is correctly configured and that the
ios directory in your project has proper configuration files.
Summary of iOS Simulator Setup
- Install Xcode and Command Line Tools
- Accept the Xcode license agreement
- Install iOS SDKs via Xcode Preferences
- Launch simulator using
flutter emulators --launch ios_simulator
7. Enabling Web Support
Flutter supports web development as a secondary platform, allowing you to build and deploy Flutter apps to the web using the same codebase.
| Step | Description | Action |
|---|---|---|
| 1 | Ensure Flutter SDK is installed | Run flutter doctor to verify the installation. |
| 2 | Enable web support | Run flutter config --enable-web |
| 3 | Verify web support | Run flutter devices and look for web. |
Example: Creating a Web-Enabled Flutter App
flutter create my_web_app
cd my_web_app
flutter config --enable-web
flutter run -d web
Note: Web support is in beta as of Flutter 3.19. Ensure you're using a compatible version.
8. Enabling Desktop Support
Flutter supports desktop development for Windows, macOS, and Linux. Desktop support is currently in beta as of Flutter 3.19.
Note: Desktop support requires enabling the desktop feature flag in your Flutter SDK.
| Platform | Status | Notes |
|---|---|---|
| Windows | BETA | Available since Flutter 3.19 |
| macOS | BETA | Available since Flutter 3.19 |
| Linux | BETA | Available since Flutter 3.19 |
Example: Enabling Desktop Support
flutter config --enable-windows
flutter config --enable-macos
flutter config --enable-linux
Example: Creating a Desktop Project
flutter create desktop_app
cd desktop_app
flutter config --enable-desktop
flutter build windows
Desktop Support Setup Summary
- Run
flutter config --enable-windows,--enable-macos, or--enable-linux - Recreate or update your project with
flutter config --enable-desktop - Use
flutter buildto compile for desktop platforms
9. Managing Flutter Channels
Flutter channels are branches of the Flutter SDK that contain different versions of the framework. The three main channels are stable, beta, and master. Each channel serves a different purpose:
| Channel | Description | Status | Release Frequency |
|---|---|---|---|
| stable | Most stable version with long-term support | STABLE | Every 6-8 weeks |
| beta | Pre-release version with new features, tested for stability | BETA | Every 2-3 weeks |
| master | Latest development version with experimental features | EXPERIMENTAL | As new features are added |
Note: Switching channels may require running
flutter upgrade to update the SDK to match the selected channel.
10. Upgrading Flutter SDK
Note: Ensure you have a stable internet connection during the upgrade process.
| Command | Description | Notes |
|---|---|---|
| flutter upgrade | Upgrades the Flutter SDK to the latest stable version. | Runs git pull in the Flutter repository to fetch the latest changes. |
| flutter upgrade --force | Forces an upgrade even if the current version is already the latest. | Useful for resolving issues with corrupted or outdated local files. |