1.1. 操作系統(tǒng)選擇
學(xué)習(xí)階段: Windows或者macOS(蘋果操作系統(tǒng))都是可以的
開發(fā)階段: 一般需要使用macOS狡逢,因為我們需要針對iOS進行調(diào)試乾翔,通常方便起見還是選擇macOS
1.2. 安裝Flutter SDK
使用Flutter開發(fā),首先我們需要安裝一個Flutter的SDK途凫。
下載Flutter的SDK
來到Flutter的官網(wǎng)網(wǎng)站倍踪,選擇最新穩(wěn)定的Flutter SDK的版本
- 網(wǎng)站地址:flutter.dev/docs/develo…
- 選擇自己的操作系統(tǒng)和最新穩(wěn)定的版本(Stable版本)
安裝Flutter
1.解壓下載好的Flutter SDK
這個在Windows和macOS都是一樣的(選擇一個自己想要安裝的目錄)
2.配置Flutter的環(huán)境變量
因為我們之后需要在命令行執(zhí)行Flutter的命令匙瘪,所以需要配置環(huán)境變量
macOS或者Linux系統(tǒng),需要編輯~/.bash_profile文件
export PATH=$PATH:/Applications/flutter/bin
Windows用戶將所在路徑添加到環(huán)境變量的Path下
Windows環(huán)境變量修改:點擊計算機圖標 - 屬性 - 高級系統(tǒng)設(shè)置 - 高級 - 環(huán)境變量
找到Path窝撵,在其中添加Flutter SDK目錄下bin目錄
在終端中執(zhí)行flutter --version傀顾,出現(xiàn)如下內(nèi)容,說明安裝flutter成功
配置鏡像
flutter項目會依賴一些東西碌奉,在國內(nèi)下載這些依賴會有一些慢短曾,所以我們可以將它們的安裝源換成國內(nèi)的(也就是設(shè)置國內(nèi)的鏡像)
macOS或者Linux操作系統(tǒng)寒砖,依然是編輯~/.bash_profile文件
export PUB_HOSTED_URL=https://pub.flutter-io.cn //國內(nèi)用戶需要設(shè)置
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn //國內(nèi)用戶需要設(shè)置
export PATH= PATH_TO_FLUTTER_GIT_DIRECTORY/flutter/bin:$PATH
注意: 此鏡像為臨時鏡像,并不能保證一直可用嫉拐,大家可以參考詳情請參考 Using Flutter in China 以獲得有關(guān)鏡像服務(wù)器的最新動態(tài)哩都。
注意:PATH_TO_FLUTTER_GIT_DIRECTORY 為你flutter的路徑,比如“~/document/code”
export PATH= ~/document/code/flutter/bin:$PATH
運行 source $HOME/.bash_profile 刷新當(dāng)前終端窗口.
注意: 如果你使用的是zsh婉徘,終端啟動時 ~/.bash_profile 將不會被加載漠嵌,解決辦法就是修改 ~/.zshrc ,在其中添加:source ~/.bash_profile
? ~ cd ~
? ~ open .zshrc
此時打開了 zsh的配置文件盖呼,在最后一行添加 source ~/.bash_profile
此時再次運行 flutter doctor
? flutterDemo flutter doctor
Downloading Dart SDK from Flutter engine 1ed25ca7b7e3e3e8047df050bba4174074c9b336...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 58.6M 100 58.6M 0 0 429k 0 0:02:19 0:02:19 --:--:-- 486k
Building flutter tool...
╔════════════════════════════════════════════════════════════════════════════╗
║ WARNING: your installation of Flutter is 77 days old. ║
║ ║
║ To update to the latest version, run "flutter upgrade". ║
╚════════════════════════════════════════════════════════════════════════════╝
Downloading Material fonts... 2.8s
Downloading package sky_engine... 1.8s
Downloading common tools... 10.7s
Downloading darwin-x64 tools... 52.1s
Downloading android-arm-profile/darwin-x64 tools... 6.5s
Downloading android-arm-release/darwin-x64 tools... 6.2s
Downloading android-arm64-profile/darwin-x64 tools... 7.3s
Downloading android-arm64-release/darwin-x64 tools... 6.3s
Downloading android-x86 tools... 29.3s
Downloading android-x64 tools... 30.0s
Downloading android-arm tools... 22.3s
Downloading android-arm-profile tools... 14.5s
Downloading android-arm-release tools... 11.3s
Downloading android-arm64 tools... 16.6s
Downloading android-arm64-profile tools... 14.6s
Downloading android-arm64-release tools... 12.2s
Downloading ios tools... 67.1s
Downloading ios-profile tools... 103.0s
Downloading ios-release tools... 51.2s
Downloading Gradle Wrapper... 0.2s
Doctor summary (to see all details, run flutter doctor -v):
[?] Flutter (Channel beta, v0.5.1, on Mac OS X 10.13.4 17E199, locale zh-Hans-CN)
[?] Android toolchain - develop for Android devices
? Unable to locate Android SDK.
Install Android Studio from: https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK components.
(or visit https://flutter.io/setup/#android-setup for detailed instructions).
If Android SDK has been installed to a custom location, set $ANDROID_HOME to that location.
[!] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
? libimobiledevice and ideviceinstaller are not installed. To install, run:
brew install --HEAD libimobiledevice
brew install ideviceinstaller
? ios-deploy not installed. To install:
brew install ios-deploy
[?] Android Studio (not installed)
[!] VS Code (version 1.25.1)
[?] Connected devices (2 available)
! Doctor found issues in 4 categories.
該命令檢查您的環(huán)境并在終端窗口中顯示報告儒鹿。Dart SDK已經(jīng)在捆綁在Flutter里了,沒有必要單獨安裝Dart几晤。 仔細檢查命令行輸出以獲取可能需要安裝的其他軟件或進一步需要執(zhí)行的任務(wù)(以粗體顯示)
按照上面的提示挺身,一個一個的解決,最終出現(xiàn)下面的圖就表示全部安裝完成了