搭建 Flutter 开发环境

Flutter SDK

配置 Flutter 中国镜像

配置环境变量FLUTTER_STORAGE_BASE_URL和PUB_HOSTED_URL

window:

  1. 计算机 ->属性 -> 高级系统配置 -> 环境变量
  2. 在用户变量下,选择新建环境变量,添加如下的两个环境变量和值: | 变量名 | 值 | | —- | —- | | FLUTTER_STORAGE_BASE_URL | https://storage.flutter-io.cn | | PUB_HOSTED_URL | https://pub.flutter-io.cn |

linux:

  1. # 编辑~/.bashrc
  2. vi ~/.bashrc
  3. # 添加环境变量
  4. export PUB_HOSTED_URL=https://pub.flutter-io.cn
  5. export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
  6. # 应用环境变量文件
  7. source ~/.bashrc

Mac:

  1. # 编辑~/.bashrc
  2. vi ~/.bash_profile
  3. # 添加环境变量
  4. export PUB_HOSTED_URL=https://pub.flutter-io.cn
  5. export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
  6. # 应用环境变量文件
  7. source ~/.bash_profile

下载Android Studio

为了flutter生成Android apk ,安装Android Studio

下载SDK

为了方便切换版本直接克隆Gitee上的Flutter库:

git clone https://gitee.com/mirrors/Flutter.git

项目使用版本:2.10.5

检查环境

  1. # 检查环境
  2. flutter doctor
  3. # 输出结果
  4. Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
  5. Doctor summary (to see all details, run flutter doctor -v):
  6. [√] Flutter (Channel unknown, 2.10.5, on Microsoft Windows [Version 10.0.22000.556], locale zh-CN)
  7. [√] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
  8. [√] Chrome - develop for the web
  9. [X] Visual Studio - develop for Windows
  10. X Visual Studio not installed; this is necessary for Windows development.
  11. Download at https://visualstudio.microsoft.com/downloads/.
  12. Please install the "Desktop development with C++" workload, including all of its default components
  13. [√] Android Studio (version 2021.2)
  14. [√] IntelliJ IDEA Ultimate Edition (version 2021.3)
  15. [√] Connected device (4 available)
  16. [!] HTTP Host Availability
  17. X HTTP host https://maven.google.com/ is not reachable. Reason: An error occurred while checking the HTTP host: 信号灯超时时间已到

IDE

安装VScode ;
添加插件Flutter
image.png

开发第一个Flutter程序

  1. # 在当前目录创建flutter程序
  2. flutter create .
  3. # 运行
  4. flutter run