If you want to do a good job, you must first sharpen your tools. This section first introduces the installation of the Flutter SDK under Windows and macOS, and then introduces the use of the IDE and emulator.
Since Flutter builds release packages for both Android and IOS platforms at the same time, Flutter relies on both the Android SDK and the iOS SDK. When installing Flutter, you also need to install the build tools and SDKs for the corresponding platforms. Let's introduce the environment construction under Windows and macOS respectively.
Note: The installation method described in this section may change with the upgrade of Flutter. If the content described below is invalid when you install Flutter, please visit the official website of Flutter and install it according to the latest installation tutorial on the official website.
Since access to Flutter in China may sometimes be restricted, Flutter officially builds a temporary image for Chinese developers. You can add the following environment variables to the user environment variables:
|
Note: This mirror is a temporary mirror and cannot be guaranteed to be available all the time. Readers can refer to https://flutter.dev/community/china for the latest developments about the mirror server.
To install and run Flutter, your development environment must meet the following minimum requirements:
OS: Windows 7 or later (64-bit)
Disk space: 400 MB (disk space not including Android Studio).
Tools: Flutter relies on the following command-line tools.
PowerShell 5.0 (opens new window) or newer version
Git for Windows (opens new window) (Git command line tool);
If you have Git for Windows installed, make sure you can run the git command in Command Prompt or PowerShell
Go to flutter official website to download its latest available installation package, download address: https://flutter.dev/docs/development/tools/sdk/releases.
Note that the channel version of Flutter will keep changing, please refer to the official website of Flutter. In addition, in mainland China, if you want to get the installation package list or download the installation package normally, you may need to go over the wall. Readers can also go to the Flutter github project to download the installation package, address: https://github.com/flutter/flutter/ releases.
Unzip the installation package zip to the path where you want to install the Flutter SDK (such as: C:\src\flutter
; Note, do not install flutter to a path that requires some high permissions C:\Program Files\
).
flutter
Find it under the file in the Flutter installation directory flutter_console.bat
, double-click to run it and start the flutter command line . Next, you can run the flutter command on the Flutter command line.
If you want to run flutter commands on the Windows system's own command line, you need to add the following environment variables to the user PATH:
flutter\bin
the full path of as its value.Restart Windows to apply this change.
Run the following command on the Flutter command line to see if any other dependencies need to be installed, and if so, install them:
|
This command checks your environment and displays a report in the command window. The Dart SDK is already packaged in the Flutter SDK, there is no need to install Dart separately. Carefully examine the command line output for additional software that may need to be installed or further tasks to be performed.
For example:
|
The first time you run a flutter command (like flutter doctor
), it downloads it's own dependencies and compiles itself. It will be much faster to run later. The missing dependencies need to be installed, and after the installation is complete, run flutter doctor
the command to verify whether the installation is successful.
Flutter depends on the full installation of Android Studio. Android Studio can not only manage Android platform dependencies, SDK versions, etc., but it is also one of the recommended IDEs for Flutter development (of course, you can also use other editors or IDEs, which we will discuss later).
If you encounter problems during the installation process, you can go to the flutter official website to check whether the installation method has changed, or search for solutions on the Internet.
Android and iOS devices can be tested simultaneously under masOS.
To install and run Flutter, your development environment must meet the following minimum requirements:
bash、mkdir、rm、git、curl、unzip、which
1. Go to flutter official website to download its latest available installation package, official website address: https://flutter.dev/sdk-archive/#macos
Note that the channel version of Flutter will keep changing, please refer to the official website of Flutter. In addition, in mainland China, if you want to get the installation package list or download the installation package normally, you may need to go over the wall. Readers can also go to the Flutter github project to download the installation package, address: https://github.com/flutter/flutter/ releases.
2. Unzip the installation package to the directory you want to install, such as:
|
3. Add flutter
related tools to path:
|
This code can only temporarily set the PATH environment variable for the current command line window. If you want to permanently add Flutter to the PATH, please refer to the update environment variable section below.
This step is consistent with the steps under Windows, so I won’t repeat it here.
Add Flutter to your PATH to run flutter
commands in any terminal session.
The steps to permanently modify this variable for all terminal sessions are computer system specific. Typically you would add commands that set environment variables to the file that is executed when opening a new window. For example
1. Make sure the directory of your Flutter SDK is marked as "FLUTTER_INSTALL_PATH", which you will use in step 3.
2. Open (or create) $HOME/.bash_profile
. The file path and file name may be different on your computer.
3. Add the following paths:
|
For example, the author's Flutter installation directory is "~/code/flutter_dir", then the code is:
|
1. Run source $HOME/.bash_profile
to refresh the current terminal window.
Note: If the terminal you use is zsh, it will not be loaded when the terminal starts.
~/.bash_profile
The solution is to modify~/.zshrc
it and add: source ~/.bash_profile
2. Verify that "flutter/bin" is already in PATH:
|
To develop Flutter apps for iOS, you need the latest version of Xcode:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
for most cases when you want to use the latest version of Xcode. If you need to use a different version, please specify the corresponding path.sudo xcodebuild -license
agreed by opening Xcode once or by command.Using Xcode, you can run Flutter apps on an iOS device or simulator.
Like Window, to build and run a Flutter program on an Android device, you need to install Android Studio first. Readers can download and install Android Studio first, so I won’t go into details here.
The Flutter SDK has multiple branches, such as beta, dev, master, and stable. The stable branch is a stable branch (there may be new stable branches after a new stable version is released in the future, such as 1.0.0), and the dev and master are The development branch, after installing flutter, you can run it to flutter channel
view all branches. For example, after the author runs it locally, the results are as follows:
|
The branch with "*" is the branch tracked by your local Flutter SDK. To switch branches, you can use flutter channel beta
or flutter channel master
. Flutter officially recommends tracking the stable branch, but you can also track master
the branch so that you can view the latest changes, but this is not stable Much lower.
To upgrade flutter sdk, just one command:
|
This command will update the Flutter SDK and your flutter project dependencies at the same time. If you only want to update the project dependencies (not including the Flutter SDK), you can use the following command:
flutter packages get
Get all dependencies of the project.flutter packages upgrade
Get the latest versions of all dependencies of the project.In theory, any text editor and command-line tool can be used to build a Flutter application. However, Flutter officially recommends using one of Android Studio and VS Code for a better development experience. Flutter officially provides these two editor plug-ins. Through the IDE and the plug-in, you can obtain functions such as code completion, syntax highlighting, widget editing assistance, running and debugging support, which can help us greatly improve development efficiency. Let's introduce the configuration and use of Android Studio and VS Code respectively (readers of Android Studio and VS Code can get the latest installation on their official website, because the installation is relatively simple, so I won't go into details).
Since Android Studio is developed based on IntelliJ IDEA, readers can also use IntelliJ IDEA.
Two plugins need to be installed:
Flutter
Plugin: Supports Flutter development workflow (running, debugging, hot reloading, etc.).Dart
Plugin: Provides code analysis (validation when typing code, code completion, etc.).installation steps:
install
.