Flutter 环境搭建

要学Flutter必须先学Dart

因为开发Flutter用的就是Dart语言

Dart官网

https://dart.dev/

下载地址

https://dart.dev/get-dart

命令安装

1
2
brew tap dart-lang/dart
brew install dart

下载FlutterSDK

配置环境变量

1
2
3
4
5
vim ~/.bash_profile
export PATH=/Users/yz/Desktop/Flutter/SDK/flutter/bin:$PATH
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
source ~/.bash_profile

检查环境变量是否正确安装

1
flutter doctor

因为Flutter是直接可以生成androidiOS的代码

所以电脑要有XcodeAndroid Studio

配置Flutter iOS环境

首先下载Xcode

1
2
3
4
5
6
7
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer brew update
brew install --HEAD usbmuxd
brew link usbmuxd
brew install --HEAD libimobiledevice brew install ideviceinstaller
brew install ios-deploy
brew install cocoapods
pod setup

配置安卓环境

下载JAVASDK

1
2
链接: https://pan.baidu.com/s/1we2Y6xtUKCV_9HNQmOByvQ
提取码: dean

下载Android Studio

https://developer.android.google.cn/studio

用命令行创建项目

1
sudo flutter create flutterdemo

运行 flutterdemo 项目

1
flutter run

不出意外会报错

1
Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user.

简单点来说就是没有权限

需要修改文件夹的权限

修改SDK的权限和修改项目的权限

进入到和文件夹同级的目录

然后

1
sudo chmod -R 777 *