flutter doctor: 检查flutter状态,很重要能知道自己环境配置的问题。
flutter emulators: 获取模拟器列表(iOS、Android模拟器)
例如:
available emulators:
Pixel_2_API_29 • Pixel 2 API 29 • Google • android
apple_ios_simulator • iOS Simulator • Apple • iOS
flutter emulators --launch xx:启动模拟器
例如:
flutter emulators --launch Pixel_2_API_29
flutter emulators --launch apple_ios_simulator
iOS 模拟器也可以直接使用open -a Simulator
flutter devices: 获取所有真机设备列表包括iOS模拟器
flutter run -d
flutter run -d all: 运行所有模拟器 注意:run的时候,必须要要先启动模拟器完成。
flutter build apk: 打包apk
flutter build ios: 打包ipa
flutter config -xx: 配置打包等信息。
flutter channel: 查看 flutter sdk 的所有分支
flutter channel stable: 切换sdk分支
flutter packages get: 获取flutter项目中以来的包,不包括 flutter sdk
flutter packages upgrade: 更新flutter项目所有依赖包,不包括flutter sdk
flutter analyze: 分析代码
flutter: 获取flutter所有命令,如果其他的都没记住,这个一定要记住。
flutter help: 查看命令的帮助信息
更重要的一点热加载,搞了好久不知道怎么热加载,各种 Command+R都不行(原来在RN中是Command+R),原来是需要在控制台输入R就可以。
以上就是flutter经常使用的命令。
Flutter开发-使用命令创建 Flutter App/Module/Plugin/Package
标准的Flutter App工程,包含标准的Dart层与Native平台层 创建命令
flutter create xxapp
//默认Android使用Java,iOS使用Objective-C。
//如果要指定语言,比如安卓使用Kotlin,iOS使用Swift
flutter create -i swift -a kotlin xxapp
Flutter 创建 Module,然后将Flutter 代码混编到已有的 Android/iOS 项目中
flutter create -t module xxapp_module
Flutter 创建 Plugin 插件工程,包含Dart层与Native平台层的实现,目的是Flutter利用原生功能
flutter create --template=plugin xxapp_plugin
Flutter 创建纯Dart插件工程,仅包含Dart层的实现,往往定义一些公共Widget,目的是组件化
flutter create --template=package xxapp_package
Flutter 组件化 创建 package package 可以视作一个组件,可以用作其他项目复用
zfz:flutter_bilibili zhangfengzhou$ cd component/
zfz:component zhangfengzhou$ flutter create --template=package hi_net
创建好 Package之后,就可以在原有的Flutter项目上引入,操作如下:
dependencies:
flutter:
sdk: flutter
#组件化配置
hi_net:
path: ./component/hi_net
首先明确一点,就是Dart SDK是包含在Flutter SDK 中的,路径如下:
/Users/zhangfengzhou/Develop/Flutter/flutter/bin/cache/dart-sdk
目录下的内容如下:
zfz:dart-sdk zhangfengzhou$ ls -l
total 40
-rw-r--r-- 1 zhangfengzhou staff 1502 4 16 2021 LICENSE
-rw-r--r-- 1 zhangfengzhou staff 981 4 16 2021 README
drwxr-xr-x 14 zhangfengzhou staff 448 4 16 2021 bin
-rw-r--r-- 1 zhangfengzhou staff 189 4 16 2021 dartdoc_options.yaml
drwxr-xr-x 3 zhangfengzhou staff 96 4 16 2021 include
drwxr-xr-x 28 zhangfengzhou staff 896 4 16 2021 lib
-rw-r--r-- 1 zhangfengzhou staff 41 4 16 2021 revision
-rw-r--r-- 1 zhangfengzhou staff 7 4 16 2021 version
lib 目录下存放的就是我们常用的一些Dart 库
zfz:lib zhangfengzhou$ ls -l
total 40
drwxr-xr-x 13 zhangfengzhou staff 416 4 16 2021 _http
drwxr-xr-x 19 zhangfengzhou staff 608 4 16 2021 _internal
-rw-r--r-- 1 zhangfengzhou staff 1322 4 16 2021 api_readme.md
drwxr-xr-x 17 zhangfengzhou staff 544 4 16 2021 async
drwxr-xr-x 5 zhangfengzhou staff 160 4 16 2021 cli
drwxr-xr-x 17 zhangfengzhou staff 544 4 16 2021 collection
drwxr-xr-x 17 zhangfengzhou staff 544 4 16 2021 convert
drwxr-xr-x 38 zhangfengzhou staff 1216 4 16 2021 core
drwxr-xr-x 4 zhangfengzhou staff 128 4 16 2021 dev_compiler
drwxr-xr-x 8 zhangfengzhou staff 256 4 16 2021 developer
drwxr-xr-x 9 zhangfengzhou staff 288 4 16 2021 ffi
drwxr-xr-x 6 zhangfengzhou staff 192 4 16 2021 html
drwxr-xr-x 3 zhangfengzhou staff 96 4 16 2021 indexed_db
drwxr-xr-x 16 zhangfengzhou staff 512 4 16 2021 internal
drwxr-xr-x 32 zhangfengzhou staff 1024 4 16 2021 io
drwxr-xr-x 5 zhangfengzhou staff 160 4 16 2021 isolate
drwxr-xr-x 8 zhangfengzhou staff 256 4 16 2021 js
drwxr-xr-x 4 zhangfengzhou staff 128 4 16 2021 js_util
-rw-r--r-- 1 zhangfengzhou staff 14792 4 16 2021 libraries.json
drwxr-xr-x 7 zhangfengzhou staff 224 4 16 2021 math
drwxr-xr-x 4 zhangfengzhou staff 128 4 16 2021 mirrors
drwxr-xr-x 3 zhangfengzhou staff 96 4 16 2021 svg
drwxr-xr-x 5 zhangfengzhou staff 160 4 16 2021 typed_data
drwxr-xr-x 3 zhangfengzhou staff 96 4 16 2021 web_audio
drwxr-xr-x 3 zhangfengzhou staff 96 4 16 2021 web_gl
drwxr-xr-x 3 zhangfengzhou staff 96 4 16 2021 web_sql
明确了Dart SDK 和 Flutter SDK 之间的关系之后,我们看下如何管理 Flutter SDK ,首先切换到如下目录:
/Users/zhangfengzhou/Develop/Flutter/flutter
查看项目的远程仓库地址:
zfz:flutter zhangfengzhou$ git remote -v
origin https://github.com/flutter/flutter.git (fetch)
origin https://github.com/flutter/flutter.git (push)
更新远程仓库代码的版本信息到本地
zfz:flutter zhangfengzhou$ git fetch --all --tags --progress
查看所有的版本
zfz:flutter zhangfengzhou$ git tag -l
1.17.1
1.17.2
1.17.3
1.17.4
1.17.5
....
2.0.0
2.0.1
2.0.2
2.0.3
2.0.4
2.0.5
2.0.6
...
可以通过 tag 来检出对应的 Flutter SDK 版本
zfz:flutter zhangfengzhou$ git checkout 2.0.4
Previous HEAD position was adc687823a Roll engine cherrypicks (#80570)
HEAD is now at b1395592de [flutter_releases] Flutter Stable 2.0.4 Framework Cherrypicks (#79486)
然后通过 flutter doctor 来下载对应的版本到本地
zfz:flutter zhangfengzhou$ flutter doctor
Downloading Dart SDK from Flutter engine 2dce47073a378673f6ca095e91b8065544c3a881...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 245 100 245 0 0 3756 0 --:--:-- --:--:-- --:--:-- 4375
22 194M 22 44.3M 0 0 3923k 0 0:00:50 0:00:11 0:00:39 4218k
下载完成之后,确定下是否已经切换到指定的版本
zfz:flutter zhangfengzhou$ flutter --version
Flutter 2.0.4 • channel unknown • unknown source
Framework • revision b1395592de (9 months ago) • 2021-04-01 14:25:01 -0700
Engine • revision 2dce47073a
Tools • Dart 2.12.2
最后补充一点就是设置 Flutter SDK 的镜像地址
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
export PATH=/Users/zhangfengzhou/Develop/Flutter/flutter/bin:$PATH