首先给大家介绍一个学习Flutter的网站
前沿
工欲善其事必先利其器。学习一门语言的开始,环境的搭建是很重要的,以下是整个流程,并不复杂,但是需要仔细,一步出错即无法搭建成功。
1.下载安装Android Studio
2.Android Studio配置
推荐一个很详细的配置文档
如果还需要额外的配置或者期间有什么疑问可以去Android官网查阅
到这里Android环境我们已经搭建完毕,下面我们来安装Flutter
3.检查安装 HomeBrew
我们在去配置
Flutter
的环境之前,需要先检查一下HomeBrew
是不是最新的! 如果没有的话就去 HomeBrew官网下载
4: 下载 Flutter SDK
官网SDK下载地址
当然也可以选择git clone -b beta https://github.com/flutter/flutter.git
去克隆
因为Flutter的SDK中包含了很多命令行工具。我们需要配置环境变量,所以建议你安装到你平时放命令行工具程序的地方! 我这里安装在了桌面
../Desktop/FlutterSDK/flutter
5.配置环境变量
来到你对应
Shell
的配置文件进行配置。
如果你使用默认的bash
那么配置~/.bash_profile
如果你使用zsh
(Mac新系统默认是zsh)那么配置~/.zshrc
#Flutter 镜像配置
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
#Flutter 配置
export FLUTTER=/opt/flutter/bin
export PATH=$FLUTTER:$PATH
配置完成就执行 source ~/.bash_profile
我们也可以通过下面命令检测flutter环境
flutter docter
检测之后会出现以下内容
[✓] Flutter (Channel stable, 3.3.4, on macOS 12.5.1 21G83 darwin-x64, locale zh-Hans-CN)
• Flutter version 3.3.4 on channel stable at /Users/soul/Desktop/FlutterSDK/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision eb6d86ee27 (7 weeks ago), 2022-10-04 22:31:45 -0700
• Engine revision c08d7d5efc
• Dart version 2.18.2
• DevTools version 2.15.0
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /Users/soul/Library/Android/sdk
✗ cmdline-tools component is missing
Run `path/to/sdkmanager --install "cmdline-tools;latest"`
See https://developer.android.com/studio/command-line for more details.
✗ Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[!] Xcode - develop for iOS and macOS (Xcode 14.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14B47b
✗ CocoaPods not installed.
CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins
To install see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2020.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
[✓] Connected device (3 available)
• iPhone 14 Pro Max (mobile) • C554884B-17E8-4A21-BBF6-F45D75065A69 • ios • com.apple.CoreSimulator.SimRuntime.iOS-16-1 (simulator)
• macOS (desktop) • macos • darwin-x64 • macOS 12.5.1 21G83 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 107.0.5304.110
根据是否有红X解决对应平台的问题
6.配置各个平台
1. Android
1.Android-licenses
flutter doctor --android-licenses
点击y就行
2.Android Studio 去安装 Flutter 插件
Android -> configure -> Plugins 或者直接在搜索栏搜索就好
2. iOS
需要通过homebrew
安装用于将Flutter应用程序部署到iOS设备的环境和工具:
brew install --HEAD libimobiledevice
brew install ideviceinstaller ios-deploy cocoapods
不同情况下回 遇到很多不同情况,如果不成功可以通过flutter doctor来定位问题
我们Flutter的开发环境基本搭建完毕,相对来说还是挺便利的
那么后面会和大家一起来探索Flutter