CLI (Command-line tool)
Flutter 是 Google 开发的一个跨平台移动应用程序开发框架,它可以让开发者使用一种代码库开发 iOS 和 Android 应用。在使用 Flutter 开发应用程序时,需要掌握一些常用的命令,下面是这些命令的详细介绍:
1.flutter create [projectName]
创建新的 Flutter 项目,需要指定项目名称。例如:flutter create my_app。
2.flutter run
运行 Flutter 应用程序,可以将应用程序运行在 iOS 模拟器、Android 模拟器或真实的设备上。例如:flutter run -d emulator-1。
3.flutter doctor
检查 Flutter 安装是否正确以及是否需要安装其他依赖项。例如:flutter doctor -v。
4.flutter build
构建 Flutter 应用程序,可以将应用程序构建成 Release 或 Debug 版本。例如:flutter build apk。
5.flutter clean
清除 Flutter 应用程序的构建缓存和临时文件。例如:flutter clean。
6.flutter packages get
获取应用程序依赖项的最新版本。例如:flutter packages get。
7.flutter packages upgrade
将应用程序依赖项升级到最新版本。例如:flutter packages upgrade。
8.flutter upgrade
将 Flutter 框架升级到最新版本。例如:flutter upgrade。
9.flutter format
格式化 Flutter 代码,可以使用该命令对代码进行自动格式化。例如:flutter format .。
10.flutter analyze
分析 Flutter 代码并输出警告和错误信息。例如:flutter analyze .。
11.flutter test
运行 Flutter 单元测试,可以使用该命令执行应用程序的测试。例如:flutter test。
以上是一些常用的 Flutter 命令,掌握这些命令可以更加高效地开发 Flutter 应用程序。
Command | Example of use | More information |
---|---|---|
analyze | flutter analyze -d <DEVICE_ID> |
Analyzes the project’s Dart source code. Use instead of dartanalyzer. |
assemble | flutter assemble -o <DIRECTORY> |
Assemble and build flutter resources. |
attach | flutter attach -d <DEVICE_ID> |
Attach to a running application. |
bash-completion | flutter bash-completion |
Output command line shell completion setup scripts. |
build | flutter build <DIRECTORY> |
Flutter build commands. |
channel | flutter channel <CHANNEL_NAME> |
List or switch flutter channels. |
config | flutter config --build-dir=<DIRECTORY> |
Configure Flutter settings. To remove a setting, configure it to an empty string. |
create | flutter create <DIRECTORY> |
Creates a new project. |
devices | flutter devices -d <DEVICE_ID> |
List all connected devices. |
doctor | flutter doctor |
Show information about the installed tooling. |
downgrade | flutter downgrade |
Downgrade Flutter to the last active version for the current channel. |
drive | flutter drive |
Runs Flutter Driver tests for the current project. |
emulators | flutter emulators |
List, launch and create emulators. |
format | flutter format <DART_FILE> |
Format one or more dart files. |
gen-l10n | flutter gen-l10n <DIRECTORY> |
Generate localizations for the Flutter project. |
install | flutter install -d <DEVICE_ID> |
Install a Flutter app on an attached device. |
logs | flutter logs |
Show log output for running Flutter apps. |
precache | flutter precache <ARGUMENTS> |
Populates the Flutter tool’s cache of binary artifacts. |
pub | flutter pub <PUB_COMMAND> |
Works with packages. Use instead of pub. |
run | flutter run <DART_FILE> |
Runs a Flutter program. |
symbolize | flutter symbolize --input=<STACK_TRACK_FILE> |
Symbolize a stack trace from the AOT compiled flutter application. |
test | flutter test [<DIRECTORYⅠDART_FILE>] |
Runs tests in this package. Use instead of pub run test. |
upgrade | flutter upgrade |
Upgrade your copy of Flutter. |