Flutter

Flutter Mac环境配置(初学)

2020-08-22  本文已影响0人  CarrySniper

提示:
正式版FlutterSDK为1.20.2,.tar文件44.1 MB
最新FlutterSDK1.21.0-9.1.pre版完整的相关文件1.99GB

1、下载Flutter SDK

1.1终端cd 到想要安装Flutter SDK到目录
1.2执行下面指令就会下载SDK文件夹“flutter”

git clone https://github.com/flutter/flutter.git或者
git clone -b beta https://github.com/flutter/flutter.git使用beta分支。

经过等待终于下载完

Macbook@ % cd /Users/Macbook/Documents/Flutter 
Macbook@ Flutter % git clone https://github.com/flutter/flutter.git
Cloning into 'flutter'...
remote: Enumerating objects: 34, done.
remote: Counting objects: 100% (34/34), done.
remote: Compressing objects: 100% (34/34), done.
remote: Total 257017 (delta 11), reused 7 (delta 0), pack-reused 256983
Receiving objects: 100% (257017/257017), 110.01 MiB | 55.00 KiB/s, done.
Resolving deltas: 100% (197622/197622), done.
Updating files: 100% (4933/4933), done.

文件夹结构如下图:


Flutter SDK.png

2、配置.bash_profile

2.1打开根目录文件夹open ~或查看文件内容open -e .bash_profile
2.2创建/编辑文件:vim ~/.bash_profile,
2.3输入内容:
// 用户需要设置,不要照搬
export PATH=${PATH}:~/document/code/flutter/bin

// 再加上Flutter官方为中国开发者搭建了临时镜像:
export PUB_HOSTED_URL=https://pub.flutter-io.cn //国内用户需要设置
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn //国内用户需要设置

注意:PATH_TO_FLUTTER_GIT_DIRECTORY 为你flutter的路径,比如“~/document/code”,至内部bin文件夹

export PATH=${PATH}:PATH_TO_FLUTTER_GIT_DIRECTORY/flutter/bin或者
export PATH=PATH_TO_FLUTTER_GIT_DIRECTORY/flutter/bin:$PATH

户需要设置
export PATH=${PATH}:~/document/code/flutter/bin
//或者
export PATH=~/document/code/flutter/bin:$PATH

3、检测是否配置完成

3.1刷新当前终端窗口source ~/.bash_profile
3.2执行 flutter -hflutter doctor
-h成功会展示Flutter指令说明:
Manage your Flutter app development. 
doctor成功会展示Android和Xcode环境模拟器运行设备配置情况
Doctor summary (to see all details, run flutter doctor -v):
3.3结果用如图用勾叉表示,成功为打勾,错误为打叉。

正常情况下最近的MacOS下载的Xcode最新版,是成功的。
安卓的是配置失败的,已经下载有Android Studio。下图有提示解决方法:执行 flutter doctor --android-licenses授权,和插件PluginFlutterDart未安装,插件安装去Android Studio搜索安装就行。

flutter doctor结果.png
flutter doctor配置完成结果.png

如果是手动去下载SDK,执行flutter -hflutter doctor可能会报错,缺失文件,所以是建议用上面指令去下载SDK。

Error: The Flutter directory is not a clone of the GitHub project.
       The flutter tool requires Git in order to operate properly;
       to install Flutter, see the instructions at:
       https://flutter.dev/get-started

4、完成

后续可以创建项目flutter create FlutterDemo,需要权限就在前面加上sudo

创建项目指令完成.png iOS运行结果.png
上一篇下一篇

猜你喜欢

热点阅读