Flutter环境搭建以及快捷命令
Flutter环境搭建
-
配置环境变量
用户变量
FLUTTER_STORAGE_BASE_URL : https://storage.flutter-io.cn
PUB_HOSTED_URL : https://pub.flutter-io.cn
由于是在国内,所以需要配置一个可靠的镜像站点,也可以选择清华大学TUNA
FLUTTER_STORAGE_BASE_URL: https://mirrors.tuna.tsinghua.edu.cn/flutter
PUB_HOSTED_URL: https://mirrors.tuna.tsinghua.edu.cn/dart-pub
-
获取Flutter SDK
下载链接:https://flutter.dev/docs/development/tools/sdk/releases#windows
可以直接下载SDK然后解压,也可以从github下载,目前最新版v1.12.13+hotfix.7
在系统变量中编辑用户变量的Path条目,添加flutter SDK的bin目录
Path : D:\flutter\sdk\bin
-
运行 flutter doctor
1,安装Android Studio (为了安装Android SDK)
2,安装VS Code 和 Android Studio 的Dart,Flutter插件
3,(非必须)安装安卓模拟器Android Studio>Tools>AVD Manager
4,如果是真机调试,开启开发人员选项 和 USB调试。
5,安装java jdk,配置环境变量
终端运行flutter doctor,显示No issues found ,环境搭建ok。
创建flutter项目,获取pubspec.yaml中的依赖包,运行项目
flutter create 创建项目
flutter pub get 获取依赖
flutter run 运行项目
创建,查看,启动模拟器
flutter emulators --create --name 模拟器名称
flutter emulators 查看所有模拟器
flutter emulators --launch 模拟器名称
Android Studio > Tools > AVD Manager 手动删除或者创建模拟器
检查,更新flutter
flutter doctor 显示flutter相关状态
flutter upgrade 更新flutter
查看所有flutter命令
Manage your Flutter app development.
Common commands:
flutter create <output directory>
Create a new Flutter project in the specified directory.
flutter run [options]
Run your Flutter application on an attached device or in an emulator.
Usage: flutter <command> [arguments]
Global options:
-h, --help Print this usage information.
-v, --verbose Noisy logging, including all shell commands executed.
If used with --help, shows hidden options.
-d, --device-id Target device id or name (prefixes allowed).
--version Reports the version of this tool.
--suppress-analytics Suppress analytics reporting when this command runs.
--bug-report Captures a bug report file to submit to the Flutter team.
Contains local paths, device identifiers, and log snippets.
Available commands:
analyze Analyze the project's Dart code.
assemble Assemble and build flutter resources.
attach Attach to a running application.
bash-completion Output command line shell completion setup scripts.
build Flutter build commands.
channel List or switch flutter channels.
clean Delete the build/ and .dart_tool/ directories.
config Configure Flutter settings.
create Create a new Flutter project.
devices List all connected devices.
doctor Show information about the installed tooling.
drive Runs Flutter Driver tests for the current project.
emulators List, launch and create emulators.
format Format one or more dart files.
generate run code generators.
help Display help information for flutter.
install Install a Flutter app on an attached device.
logs Show log output for running Flutter apps.
make-host-app-editable Moves host apps from generated directories to non-generated directories so that they can be edited by
developers.
precache Populates the Flutter tool's cache of binary artifacts.
pub Commands for managing Flutter packages.
run Run your Flutter app on an attached device.
screenshot Take a screenshot from a connected device.
test Run Flutter unit tests for the current project.
upgrade Upgrade your copy of Flutter.
version List or switch flutter versions.
Run "flutter help <command>" for more information about a command.
Run "flutter help -v" for verbose help output, including less commonly used options.