用dart轉換C#版本的JsonToDart,最後打包的時候,發現官方沒有打包方式,而且還不支援快捷鍵,所以最後選擇使用go-flutter來打包(雖然打出來也是debug版本,但好歹有生成物)
網上有很多大佬都有了第一步的嘗試go-flutter攻略(進坑姿勢),比如Go Flutter Desktop (一) 初探以及 GO Flutter Desktop Mac版小白體驗,按照大佬的指示,我最終也成功地打出了mac的產物。
本應該很滿足的,但是我是一個軟粉,網上居然沒有go-flutter關於windows的環境配置的文章(全是mac的),所以週末抽空在家裡,嘗試了一下,遇到一些問題,最終也成功打出包 windows-x64-go-flutter.zip
下面跟著我按照流程走一遍。
go安裝和環境配置
go這是go的原始碼,如果你選擇從原始碼構建,請參考 從原始碼進行安裝
我們這裡選擇直接裝下載安裝包
我選擇的這個,可以根據自己的環境下載

下載好之後,我在D盤新建一個目錄,go/source作為go的安裝目錄 go/project作為go的工作目錄

接下來我們需要去配置環境變數,從小娜這裡輸入,快速進去環境變數設定,windows7的小夥伴自行百度。

新增一個環境變數GOROOT 和GOPAHT


然後在環境變數PATH新增 %GOROOT%\bin, 我記得windows7下面好像寫%GOROOT%\bin; 多一個;

記得重啟電腦,這樣環境才會生效。cmd或者powershell裡面輸入go,不報錯,說明我們的go環境就安裝配置好了

hover安裝和環境配置
hover is a simple build tool to create Flutter desktop applications. 就是說專門來拿建立flutter desktop應用的.
cmd或者powershell 執行
go get -u github.com/go-flutter-desktop/hover
稍等一會工具hover就會被下載到GOPATH制定的路徑下面了

hover init
接下來,我們到你的flutter專案的目錄下面

This is usualy the path for your project on github or a self-hosted git service. If you are unsure, just make something up, it can always be changed later. 這個路徑是你的flutter專案github路徑,如果你不確定,也沒關係,後面能修改,我這裡路徑 為github.com/fluttercandies/JsonToDart
執行 hover init github.com/fluttercandies/JsonToDart

完成之後就會在目錄下面生成desktop目錄。 desktop/assets/logo.png 這個是啟動的圖示,你可以更換 desktop/cmd/options.go 你可以在這裡新增外掛或者做一些設定 比如
flutter.WindowInitialDimensions(1920, 1080),
flutter.ForcePixelRatio(2), // retina set to 2
main_desktop.dart
你需要建立main_desktop.dart作為go-flutter編譯應用的入口 你可以直接呼叫你原來flutter專案的main.dart
import 'main.dart' as m;
void main() {
m.main();
}
複製程式碼
hover run
你可以通過該命令啟動desktop程式
hover build
執行 hover build github.com/fluttercandies/JsonToDart
第一次會去下載各種東西,執行指令的時候報了一個錯誤

在網上檢視了一下,需要下載MinGW
MinGW
下載對應的版本之後安裝,注意選擇,我是x64

記住安裝的地址,比如我的是

按照完畢之後,我們需要去配置下環境變數,在PATH變數中新增剛才安裝路徑的bin

記得重啟電腦,這樣環境才會生效。
再次執行 hover build github.com/fluttercandies/JsonToDart
如果是第一次,會下載一堆東西,執行好之後如圖

最後在目錄desktop下面,就能找到產物了,你可以把assets裡面的圖示換成自己的
windows下面執行hover build 生成的exe

mac下面執行hover build 生成的是exec

坑大概講完了,最後邀請,有心為Flutter生態做貢獻的小夥伴加入Flutter Candies,一起開心地寫bug,生產可愛的Flutter 小糖果(QQ群:181398081)

最最後放上Flutter Candies全家桶,真香。
