Flutter环境搭建——mac版

1: Flutter 依赖⼯工具 bash , mkdir , rm , git , curl , unzip , which

  • For bash —— 查看、切换shell命令:
//查看当前shell
echo $SHELL  // 或者echo $0
//查看已安装的shells
cat /etc/shells
//例如切换bash
chsh -s /bin/bash

切换若提示 chsh: no changes made
尝试 sudo chsh -s /bin/bash
若还是不行, 则执行:
dscl . -read /Users/$USER/ UserShell
exec su - $USER
输入密码即可切换成功

2: 使用镜像, 将如下代码添加到 .bash_profile

export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn

打开.bash_profile文件:
open -e .bash_profile
编辑后保存.bash_profile文件:
source .bash_profile

3: 配置Flutter SDK

S1. 官网下载SDK;
S2. 解压安装包到/Users/$USER/;
S3. 添加 flutter 相关工具到 path中:

//在 .bash_profile 文件中加上
export PATH=/Users/$USER/flutter-1.24.0-10.2.pre/bin:$PATH

S4. 运⾏ flutter doctor 查看安装结果;

若报错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
/Users/$USER/flutter-1.24.0-10.2.pre目录下运行git init,再执行fluuter doctor

4: 开发环境安装

ios: Xcode
android: Android Studio

设置安卓模拟器器:启动 Android Studio>Tools>Android>AVD Manager 并选择;
安装插件Dart、Flutter(Create Virtual Device Perference>Plugins), 安装完成重启

5: 创建项目:

S1. 命令行 flutter create flutterProject

报错: "flutterProject" is not a valid Dart package name. See https://dart.dev/tools/pub/pubspec#name for more information.
命名不符合规范, 要用下划线方式, 如 “ flutter_project ”

S2. Android Studio中快捷方式:
“Start a new Flutter project”

S3. VsCode中, Command+Shift+P 选择 Flutter: New Project

6: 在线编译平台

DartPad

7: JSON数据在线转换

json_to_dart

8: 拉取新项目后, 安装依赖执行:

flutter create .
flutter pub get

9: 快捷键

vscode中 : 快捷引入 command+.

你可能感兴趣的:(Flutter环境搭建——mac版)