本文尝试搭建Windows10下的Flutter for Windows桌面应用,记录步骤以及遇到的坑,方便参考。
配置国内镜像源
FLUTTER_STORAGE_BASE_URL https://storage.flutter-io.cn
PUB_HOSTED_URL https://pub.flutter-io.cn
下载:flutter_windows_v1.12.13+hotfix.8-stable.zip
将.flutterin添加到系统环境变量Path
flutter doctor检查版本
更新到主线版本(主线版本支持桌面,一定要更新到master版本):可能会比较慢,耐心等待
flutter channel master
flutter upgrade
再次执行flutter doctor检查环境
设置环境变量:ENABLE_FLUTTER_DESKTOP = true
执行:flutter config --enable-windows-desktop
执行:flutter devices查看当前连接设备
下载flutter-desktop-embedding
和flutter SDK放在同一级目录:
执行git clone https://github.com/google/flutter-desktop-embedding.git
cd ./flutter-desktop-embedding
VS Code打开./flutter-desktop-embedding/testbed文件夹
Ctrl+~打开终端执行flutter doctor提示缺少Visual Studio工具链
安装VS 2019企业版vs_community__1874668239.1578475388.exe
工作负载中Windows下的全选,右边组件Win10 SDK也全选,确保不会遗漏环境。
成功安装VS2019后,再次执行flutter doctor
环境依赖应该没问题了~
执行flutter pub get
最后执行运行:flutter run
应用窗口被打开: