01-搭建Flutter开发环境

1.1. 操作系统选择

学习阶段: Windows或者macOS(苹果操作系统)都是可以的

开发阶段: 一般需要使用macOS,因为我们需要针对iOS进行调试,通常方便起见还是选择macOS

1.2. 安装Flutter SDK

使用Flutter开发,首先我们需要安装一个Flutter的SDK。

下载Flutter的SDK

来到Flutter的官网网站,选择最新稳定的Flutter SDK的版本

  • 网站地址:flutter.dev/docs/develo…
  • 选择自己的操作系统和最新稳定的版本(Stable版本)

安装Flutter

1.解压下载好的Flutter SDK

这个在Windows和macOS都是一样的(选择一个自己想要安装的目录)

flutterSDK目录

2.配置Flutter的环境变量

因为我们之后需要在命令行执行Flutter的命令,所以需要配置环境变量

macOS或者Linux系统,需要编辑~/.bash_profile文件

export PATH=$PATH:/Applications/flutter/bin

Windows用户将所在路径添加到环境变量的Path下

Windows环境变量修改:点击计算机图标 - 属性 - 高级系统设置 - 高级 - 环境变量
找到Path,在其中添加Flutter SDK目录下bin目录

在终端中执行flutter --version,出现如下内容,说明安装flutter成功


flutter--version

配置镜像

flutter项目会依赖一些东西,在国内下载这些依赖会有一些慢,所以我们可以将它们的安装源换成国内的(也就是设置国内的镜像)

macOS或者Linux操作系统,依然是编辑~/.bash_profile文件

export PUB_HOSTED_URL=https://pub.flutter-io.cn //国内用户需要设置
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn //国内用户需要设置
export PATH= PATH_TO_FLUTTER_GIT_DIRECTORY/flutter/bin:$PATH

注意: 此镜像为临时镜像,并不能保证一直可用,大家可以参考详情请参考 Using Flutter in China 以获得有关镜像服务器的最新动态。

注意:PATH_TO_FLUTTER_GIT_DIRECTORY 为你flutter的路径,比如“~/document/code”

 export PATH= ~/document/code/flutter/bin:$PATH

运行 source $HOME/.bash_profile 刷新当前终端窗口.

注意: 如果你使用的是zsh,终端启动时 ~/.bash_profile 将不会被加载,解决办法就是修改 ~/.zshrc ,在其中添加:source ~/.bash_profile

➜  ~ cd ~ 
➜  ~ open .zshrc
此时打开了 zsh的配置文件,在最后一行添加 source ~/.bash_profile

此时再次运行 flutter doctor

➜  flutterDemo flutter doctor                                        
Downloading Dart SDK from Flutter engine 1ed25ca7b7e3e3e8047df050bba4174074c9b336...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 58.6M  100 58.6M    0     0   429k      0  0:02:19  0:02:19 --:--:--  486k
Building flutter tool...
  ╔════════════════════════════════════════════════════════════════════════════╗
  ║ WARNING: your installation of Flutter is 77 days old.                      ║
  ║                                                                            ║
  ║ To update to the latest version, run "flutter upgrade".                    ║
  ╚════════════════════════════════════════════════════════════════════════════╝


Downloading Material fonts...                                2.8s
Downloading package sky_engine...                            1.8s
Downloading common tools...                                 10.7s
Downloading darwin-x64 tools...                             52.1s
Downloading android-arm-profile/darwin-x64 tools...          6.5s
Downloading android-arm-release/darwin-x64 tools...          6.2s
Downloading android-arm64-profile/darwin-x64 tools...        7.3s
Downloading android-arm64-release/darwin-x64 tools...        6.3s
Downloading android-x86 tools...                            29.3s
Downloading android-x64 tools...                            30.0s
Downloading android-arm tools...                            22.3s
Downloading android-arm-profile tools...                    14.5s
Downloading android-arm-release tools...                    11.3s
Downloading android-arm64 tools...                          16.6s
Downloading android-arm64-profile tools...                  14.6s
Downloading android-arm64-release tools...                  12.2s
Downloading ios tools...                                    67.1s
Downloading ios-profile tools...                            103.0s
Downloading ios-release tools...                            51.2s
Downloading Gradle Wrapper...                                0.2s
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, v0.5.1, on Mac OS X 10.13.4 17E199, locale zh-Hans-CN)
[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.io/setup/#android-setup for detailed instructions).
      If Android SDK has been installed to a custom location, set $ANDROID_HOME to that location.
[!] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
    ✗ libimobiledevice and ideviceinstaller are not installed. To install, run:
        brew install --HEAD libimobiledevice
        brew install ideviceinstaller
    ✗ ios-deploy not installed. To install:
        brew install ios-deploy
[✗] Android Studio (not installed)
[!] VS Code (version 1.25.1)
[✓] Connected devices (2 available)

! Doctor found issues in 4 categories.

该命令检查您的环境并在终端窗口中显示报告。Dart SDK已经在捆绑在Flutter里了,没有必要单独安装Dart。 仔细检查命令行输出以获取可能需要安装的其他软件或进一步需要执行的任务(以粗体显示)

按照上面的提示,一个一个的解决,最终出现下面的图就表示全部安装完成了

最终

你可能感兴趣的:(01-搭建Flutter开发环境)