前言,Flutter的熱重載(hot reload)功能能夠幫助您在無需從新啓動應用的狀況下快速、輕鬆地進行測試、構建用戶界面、添加功能以及修復錯誤。html
經過將更新後的源代碼文件注入正在運行的Dart虛擬機(VM)中來實現熱重載。bash
在虛擬機使用新的的字段和函數更新類後,Flutter框架會自動從新構建widget樹,以便您快速查看更改的效果。框架
要熱重載一個Flutter應用程序:函數
-
從受支持的IntelliJ IDE 、Android Studio 或終端窗口運行應用程序。物理機或虛擬器均可以運行。工具
-
修改項目中的一個Dart文件。大多數類型的代碼更改能夠從新加載; 有關須要徹底從新啓動的更改列表,請參閱限制。post
-
若是您使用的是IntelliJ IDE 、Android Studio ,請選擇Save All (cmd-s
/ctrl-s
)),或者單擊工具欄上的Hot Reload按鈕。測試
1、現象:
Flutter 不能熱加載 熱重載按鈕灰色,沒法點擊。url

2、分析緣由:
終端
flutter doctor 顯示 NO_PROXY is not setspa
沒有設置無代理的端口3d
終端:flutter doctor
➜ ~ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.7.8, on Mac OS X 10.14.3 18D109, locale
zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 10.2.1)
[✓] iOS tools - develop for iOS devices
[✓] Android Studio (version 3.5)
[✓] VS Code (version 1.41.1)
[!] Proxy Configuration
! NO_PROXY is not set
[✓] Connected device (1 available)
! Doctor found issues in 1 category.
重點在於:NO_PROXY is not set
3、解決方案:
設置 NO_PROXY便可
1.啓動終端
2.進入當前用戶的home目錄
cd ~ 或者 cd /users/YourMacUserName
3.輸入touch .bash_profile
查看和編輯.bash_profile文件
1.終端輸入open -e .bash_profile
2.編輯文件,新增
export no_proxy="localhost,127.0.0.1"
3.關閉保存
最後更新配置的環境變量
輸入:source .bash_profile
不懂這塊的話,看這裏設置Mac 終端走代理
操做以下:
➜ ~ cd ~
➜ ~ touch .bash_profile
➜ ~ open -e .bash_profile
➜ ~ source .bash_profile
➜ ~ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.7.8, on Mac OS X 10.14.3 18D109, locale
zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 10.2.1)
[✓] iOS tools - develop for iOS devices
[✓] Android Studio (version 3.5)
[✓] VS Code (version 1.41.1)
[✓] Proxy Configuration
[✓] Connected device (1 available)
• No issues found!
➜ ~
4、驗證
運行時,熱重載按鈕變爲橙色,能夠點擊。
快捷鍵保存編輯時,自動重載。
