使用与配置

flutter 开发的使用与配置相关内容

Author: huyikai

flutter

常用命令

环境

Terminal window
flutter --version #查看当前安装的flutter 版本
flutter upgrade #升级当前的flutter 版本
flutter doctor #检查环境安装是否完成

创建新项目

Terminal window
flutter create project_name

获取依赖

Terminal window
flutter pub get

升级依赖

Terminal window
flutter pub upgrade

运行应用

Terminal window
flutter run --设备名称 #运行项目到指定设备

构建 APK

Terminal window
flutter build apk --release --target-platform android-arm64 #生成指定CPU架构的apk

构建 iOS 应用

Terminal window
flutter build ios #iOS打包 这一步并不能生成ipa文件,需要使用Xcode 打包

清理构建文件

Terminal window
flutter clean

分析代码

Terminal window
flutter analyze

运行测试

Terminal window
flutter test

生成本地化文件

Terminal window
flutter gen-l10n

快捷键

在 VSCode 中开发 Flutter 时,如果你想要快速修复或者是应用建议(类似 IntelliJ 或 Android Studio 中的 Alt+Enter),你可以使用以下快捷键:

Windows/Linux: Ctrl+. (Control 加点)

macOS: Cmd+. (Command 加点)

analyze

添加 very_good_analysis 依赖

Terminal window
dart pub add --dev very_good_analysis

替换 analysis_options.yaml 文件

include: package:very_good_analysis/analysis_options.yaml
linter:
rules:
always_use_package_imports: false
prefer_relative_imports: true
always_put_required_named_parameters_first: false
flutter_style_todos: false
public_member_api_docs: false
sort_pub_dependencies: false
analyzer:
language:
strict-casts: true
strict-inference: true
strict-raw-types: true
exclude:
- lib/generated/**
- _flutter/**
- '**/*.g.dart'
- '**/*.freezed.dart'
errors:
invalid_annotation_target: ignore