一、系統環境
flutter最低要求
1,windows7 SP1 64位版本以上,我的系統就是windows 7 sp1 64bit
2,git for windows ,沒有安裝的需要到這里下載 並安裝
3,powershell 5.0及以上,這個據說只有windows10和2016版windows server滿足要求
window7 sp1以及自帶Powershell,但是版本較低,我的系統中版本居然是2.0

啟動:系統左下角-開始-點擊搜索框-輸入powershell-回車鍵 在powershell中輸入 $PSVersionTable 然后回車,查看其中的PSVersion一行 Windows PowerShell 版權所有 (C) 2009 Microsoft Corporation。保留所有權利。 PS C:\Users\gzg> $PSVersionTable Name Value ---- ----- CLRVersion 2.0.50727.8793 BuildVersion 6.1.7601.17514 PSVersion 2.0 WSManStackVersion 2.0 PSCompatibleVersions {1.0, 2.0} SerializationVersion 1.1.0.1 PSRemotingProtocolVersion 2.1 PS C:\Users\gzg>
由於PS沒有單獨的發行包,只能下載WMF5.1的發行包
下載后展開,包含如下兩個文件,右鍵點擊Install-WMF5.1.ps1,選擇用powershell運行安裝,過程不贅述。
4,安裝配置好android SDK,並建立一個模擬器
5,Android Studio,如果沒有請安裝http://www.androiddevtools.cn/。
二、下載安裝flutter sdk
1,進入預存放flutter目錄的父目錄中,從github克隆flutter beta版
git clone -b beta https://github.com/flutter/flutter.git
2,設置環境變量
1)將 *\flutter\bin目錄加入到環境變量path中
2)添加ANDROID_HOME環境變量,指向android SDK所在目錄
3, 設置國內鏡像代理,然后執行flutter doctor
打開dos窗口,設置國內鏡像
set PUB_HOSTED_URL=https://pub.flutter-io.cn set FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
備注:或者也可以直接添加系統變量,以備以后升級安裝方便。
4,進行下一步之前,首先關閉殺毒殺木馬程序,例如360之類,否則“flutter\bin\cache\artifacts\engine\android-arm64-release\windows-x64\gen_snapshot.exe” 會被認成木馬,造成運行失敗!
我這里的報錯信息如下:
K:\Android\flutter>flutter doctor Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source! Oops; flutter has exited unexpectedly. Sending crash report to Google.
或者,給目錄“flutter\bin”添加到信任白名單。如果還有問題,看一看flutter目錄下的“flutter_##.log”文件查找原因,然后在解決即可。
5,運行flutter設置命令
flutter doctor
flutter會檢測flutter SDK安裝情況,然后下載dart SDK和其他依賴項目,由於網絡問題運行時間較長,期間不免發生失敗情況,需要多運行幾次。
PS C:\Users\gzg> flutter doctor Downloading android-arm-release/windows-x64 tools... Download failed -- attempting retry 1 in 1 second... Download failed -- attempting retry 2 in 2 seconds... Download failed -- attempting retry 3 in 4 seconds... Download failed -- attempting retry 4 in 8 seconds... Download failed -- attempting retry 5 in 16 seconds... Download failed -- attempting retry 6 in 32 seconds... Download failed -- attempting retry 7 in 64 seconds... Download failed -- attempting retry 8 in 64 seconds... 365.2s Downloading android-arm64-profile/windows-x64 tools... 8.2s Downloading android-arm64-release/windows-x64 tools... 7.6s Downloading android-x86 tools... Download failed -- attempting retry 1 in 1 second... Download failed -- attempting retry 2 in 2 seconds... 142.8s Downloading android-x64 tools... 53.4s Downloading android-arm tools... 24.4s Downloading android-arm-profile tools... Oops; flutter has exited unexpectedly. Sending crash report to Google. Failed to send crash report due to a network error: SocketException: OS Error: ä¿¡å·ç¯è¶…时时间已到 , errno = 121, address = clients2.google.com, port = 60527 Crash report written to C:\Users\gzg\flutter_03.log; please let us know at https://github.com/flutter/flutter/issues. PS C:\Users\gzg> flutter doctor Downloading android-arm-profile tools... Download failed -- attempting retry 1 in 1 second... Download failed -- attempting retry 2 in 2 seconds... Download failed -- attempting retry 3 in 4 seconds... Download failed -- attempting retry 4 in 8 seconds... Download failed -- attempting retry 5 in 16 seconds... Download failed -- attempting retry 6 in 32 seconds... 254.5s Downloading android-arm-release tools... Download failed -- attempting retry 1 in 1 second... 61.0s Downloading android-arm64 tools... 27.6s Downloading android-arm64-profile tools... Download failed -- attempting retry 1 in 1 second... 71.0s Downloading android-arm64-release tools... Download failed -- attempting retry 1 in 1 second... Download failed -- attempting retry 2 in 2 seconds... Download failed -- attempting retry 3 in 4 seconds... Download failed -- attempting retry 4 in 8 seconds... Download failed -- attempting retry 5 in 16 seconds...
6,最后,flutter doctor命令會給出環境檢測結果,如果有些項目有問題,則按照其中說明修正,例如,我這里有兩項有問題:
Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel unknown, v0.0.0-unknown, on Microsoft Windows [Version 6.1.7601], locale zh-CN) [!] Android toolchain - develop for Android devices (Android SDK 28.0.3) ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses [√] Android Studio (version 3.2) [√] IntelliJ IDEA Community Edition (version 2018.2) [!] Connected device ! No devices available ! Doctor found issues in 2 categories.
第二項問題依照藍色提示操作即可解決。最后一項虛擬機,建立一個虛擬機並啟動,再次運行檢測,沒問題了!
C:\Users\gzg>flutter doctor Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel unknown, v0.0.0-unknown, on Microsoft Windows [Version 6.1.7601], locale zh-CN) [√] Android toolchain - develop for Android devices (Android SDK 28.0.3) [√] Android Studio (version 3.2) [√] IntelliJ IDEA Community Edition (version 2018.2) [√] Connected device (1 available) • No issues found!
三、開始flutter之旅
在android studio中建立flutter項目
菜單“File--New--New Flutter Project...”,第一步選擇“Flutter Application”,第二部輸入項目名稱,注意一定要選中下面的選項“create project offline”,否則在我的網絡環境下就進行不下去了。