本文主要是介绍Flutter Win桌面应用环境配置,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
因为iOS和MacOS最终都是用XCode构建的,所以Flutter运行在Mac桌面上非常容易。
要让Flutter运行在Windows上,还是比较麻烦的。
环境
- 目前稳定版不支持Windows,可以新建个文件夹,下载master分支的Flutter
git clone -b master https://github.com/flutter/flutter.git
- 如果你已经安装过Flutter SDK,则需要修改你原来安装的时候配置的环境变量,让他指向master分支的Flutter SDK
- 开启Windows支持: flutter config --enable-windows-desktop
然后就可以创建项目了,执行命令flutter create desktop_flutter
运行Flutter的Windows项目
开启windows支持后,重启AS后,会有下面的下拉选项
直接运行会出错,因为Windows应用编译需要Visual Studio工具,
可以执行一下flutter doctor看看情况
点击链接下载visualstudio
,安装选择桌面应用程序,如下图:
安装完成必须重启电脑,否则会报如下错误。
全部完成再次点击运行即可。
官方示例:
遇到的坑
因为我原来就有Flutter开发环境,针对Flutter桌面开发是从新修改的SDK路径,修改完成以后我在桌面直接查看Flutter版本号是正确的,就是我修改过的master分支的版本,但是我在AS里面用命令行查看Flutter版本号一直不对,还是我原来开发APP的版本号。并且我在AS配置里面也已经修改过Flutter和Dart的默认SDK路径了,在AS里面执行flutter --version一直报错:
Warning! The ‘flutter’ tool you are currently running is from a different Flutter repository than the one last used by this package. The repository from which the ‘flutter’ tool is currently executing will be used instead.
running Flutter tool: G:\Flutter\flutter
previous reference : G:\Flutter\Flutter_desktop\flutter
This can happen when you have multiple copies of flutter installed. Please check your system path to verify that you are running the expected version (run ‘flutter --version’ to see which flutter is on your path).
在网上搜基本上都是说让修改环境变量,然后执行Flutter clean —> flutter pub get,但是我环境变量没问题,并且也clean了,依然报这个错,最后实在没招了,重启了一下电脑,结果好了
,心里默念一万遍CNM~~~,折腾了我大半天时间
这篇关于Flutter Win桌面应用环境配置的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!