搭建 Flutter 开发环境
Flutter SDK
配置 Flutter 中国镜像
配置环境变量FLUTTER_STORAGE_BASE_URL和PUB_HOSTED_URL
- Flutter 社区
- FLUTTER_STORAGE_BASE_URL: https://storage.flutter-io.cn
- PUB_HOSTED_URL: https://pub.flutter-io.cn
- 上海交通大学 Linux 用户组
- FLUTTER_STORAGE_BASE_URL: https://mirrors.sjtug.sjtu.edu.cn
- PUB_HOSTED_URL: https://dart-pub.mirrors.sjtug.sjtu.edu.cn
window:
- 计算机 ->属性 -> 高级系统配置 -> 环境变量
- 在用户变量下,选择新建环境变量,添加如下的两个环境变量和值: | 变量名 | 值 | | —- | —- | | FLUTTER_STORAGE_BASE_URL | https://storage.flutter-io.cn | | PUB_HOSTED_URL | https://pub.flutter-io.cn |
linux:
# 编辑~/.bashrcvi ~/.bashrc# 添加环境变量export PUB_HOSTED_URL=https://pub.flutter-io.cnexport FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn# 应用环境变量文件source ~/.bashrc
Mac:
# 编辑~/.bashrcvi ~/.bash_profile# 添加环境变量export PUB_HOSTED_URL=https://pub.flutter-io.cnexport FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn# 应用环境变量文件source ~/.bash_profile
下载Android Studio
为了flutter生成Android apk ,安装Android Studio。
下载SDK
为了方便切换版本直接克隆Gitee上的Flutter库:
git clone https://gitee.com/mirrors/Flutter.git
项目使用版本:2.10.5
检查环境
# 检查环境flutter doctor# 输出结果Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!Doctor summary (to see all details, run flutter doctor -v):[√] Flutter (Channel unknown, 2.10.5, on Microsoft Windows [Version 10.0.22000.556], locale zh-CN)[√] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)[√] Chrome - develop for the web[X] Visual Studio - develop for WindowsX Visual Studio not installed; this is necessary for Windows development.Download at https://visualstudio.microsoft.com/downloads/.Please install the "Desktop development with C++" workload, including all of its default components[√] Android Studio (version 2021.2)[√] IntelliJ IDEA Ultimate Edition (version 2021.3)[√] Connected device (4 available)[!] HTTP Host AvailabilityX HTTP host https://maven.google.com/ is not reachable. Reason: An error occurred while checking the HTTP host: 信号灯超时时间已到
IDE
开发第一个Flutter程序
# 在当前目录创建flutter程序flutter create .# 运行flutter run
