FlutterApp实战·第01天:Flutter装置和装备
Flutter装置文档:
- 官方文档:https://docs.flutter.dev/get-started/install
- 中文文档:https://flutter.cn/docs/get-started/install
Dart晋级
- Dart装置参阅前面文章(Dart装置和初体验):https://ntopic.cn/p/2023092301
- 后续学习咱们选用最新Flutter版别,因而主张晋级Dart最新版别(当时:3.2.0):
brew upgrade dart
$ brew info dart
==> dart-lang/dart/dart: stable 3.2.0, HEAD
SDK
https://dart.dev
Conflicts with:
dart-beta (because dart-beta ships the same binaries)
/usr/local/Cellar/dart/3.2.0 (1,022 files, 560.8MB) *
Built from source on 2023-11-19 at 10:04:05
From: https://github.com/dart-lang/homebrew-dart/blob/HEAD/Formula/dart.rb
==> Options
--HEAD
Install HEAD version
==> Caveats
Please note the path to the Dart SDK:
/usr/local/opt/dart/libexec
VS Code装置
VS Code是免费的,支撑Flutter的研制、调试和运转,没有理由不运用它作为Flutter的研制IDE(IntelliJ IDEA十分强壮,惋惜是收费)。
下载和装置VS Code下载:
- 首要经过官网下载VS Code:https://code.visualstudio.com/docs/?dv=win
- 点击下载之后,发现下载速度很慢:右键仿制下载链接,然后把域名换成 “vscode.cdn.azure.cn”,从头经过浏览器翻开进行下载,速度杠杠的
VS Code装置成功之后,就进行Flutter装置和装备。
Flutter SDK装置
咱们能够从GitHub原始库房和Gitee镜像库房下载,因为我国拜访GitHub网速太慢,主张从Gitee镜像库房下载:
# 源代码目录 [/Users/obullxl/FlutterSpace]
$ cd /Users/obullxl/FlutterSpace
# Gitee下载 [引荐方法]
$ git clone -b stable https://gitee.com/mirrors/Flutter.git flutter
# GitHub下载 [网速或许较慢]
$ git clone -b stable https://github.com/flutter/flutter.git flutter
Flutter SDK有多个版别,如beta
、master
、stable
等,其间beta/master为开发分支,stable
为安稳分支,主张运用安稳分支:
- 检查一切分支:
flutter channel
- 切换本地分支:
flutter channel xxx
- 检查当时版别:
flutter --version
- 晋级最新版别:
flutter upgrade
- 检测Flutter装备:
flutter doctor
# 切换到Flutter源代码目录
$ cd /Users/obullxl/FlutterSpace/flutter
# 检查Flutter一切分支 [主张stable分支]
$ flutter channel
Flutter channels:
master
main
beta
* stable
# 切换到stable分支
$ flutter channel stable
# 检查当时版别,因为我的Flutter是之前装置的版别[3.7.1]
$ flutter --version
Flutter 3.7.1 • channel stable • https://gitee.com/mirrors/Flutter.git
Framework • revision 7048ed95a5 (10 months ago) • 2023-02-01 09:07:31 -0800
Engine • revision 800594f1f4
Tools • Dart 2.19.1 • DevTools 2.20.1
# 晋级Flutter版别
$ flutter upgrade
# 再次检查Flutter版别,现已是终究版别[3.16.0]
$ flutter --version
Flutter 3.16.0 • channel stable • https://gitee.com/mirrors/Flutter.git
Framework • revision db7ef5bf9f (3 days ago) • 2023-11-15 11:25:44 -0800
Engine • revision 74d16627b9
Tools • Dart 3.2.0 • DevTools 2.28.2
# 检测Flutter装备状况
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[!] Flutter (Channel stable, 3.16.0, on macOS 12.6.7 21G651 darwin-x64, locale zh-Hans-CN)
! Warning: `dart` on your path resolves to
/usr/local/Cellar/dart/3.1.2/libexec/bin/dart, which is not inside your current
Flutter SDK checkout at /Users/obullxl/FlutterSpace/flutter. Consider adding
/Users/obullxl/FlutterSpace/flutter/bin to the front of your path.
[!] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
✗ 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.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] IntelliJ IDEA Ultimate Edition (version 2021.1.3)
[✓] VS Code (version 1.84.0)
[✓] Connected device (2 available)
[✓] Network resources
! Doctor found issues in 2 categories.
Flutter 库房装备
和Java编程需求装备Maven国内库房相同,Flutter也需求装备国内库房,不然拜访国外库房要么拜访不了,要么网速太慢。
在环境变量中,添加如下装备:
# 建软衔接 [便于后边统一管理]
$ cd /opt
$ sudo ln -s /Users/obullxl/FlutterSpace/flutter ./flutter
# 体系变量
$ sudo vi /etc/profile
# 添加内容
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
export FLUTTER_GIT_URL=https://gitee.com/mirrors/Flutter.git
export PATH=$PATH:/opt/flutter/bin
# 收效环境变量
$ source /etc/profile
最终
至此,Flutter装置和装备现已完成了,接下来咱们就经过VS Code编写Flutter App了!
我的本博客原地址:https://ntopic.cn/p/2023112001