Flutter Boilerplate
一个使用 RiverPod、Dio、auto_route、Freezed 并通过 very_good_cli 生成的 Flutter Boilerplate 项目。
这是一个非常简单的 Boilerplate 应用程序,它具有以下功能。
- 用户可以注册和登录
- 登录后,他可以看到项目列表
它使用一个模拟的 JSON 服务器,该服务器不存储或验证任何内容,因此任何电子邮件和密码都可以用于登录/注册。
使用了 RiverPod 进行状态管理,但也有一个使用 Flutter bloc 的旧实现,您可以查看 bloc 分支,尽管该分支没有许多最新更改。
入门?
您可以参考这个 Flutter Starter Pack。
此项目包含 3 种风味
- 开发
- 测试
- 生产
要运行所需的风味,可以使用 VSCode/Android Studio 中的启动配置,或使用以下命令
# Development
$ flutter run --flavor development --target lib/main_development.dart
# Staging
$ flutter run --flavor staging --target lib/main_staging.dart
# Production
$ flutter run --flavor production --target lib/main_production.dart
*Flutter Boilerplate 适用于 iOS、Android 和 Web。
使用 MakeFile / Derry 避免编写自己的脚本。
您可以手动运行所有这些脚本,或者使用 MakeFile / Derry 并维护一个文件,您可以在其中定义所有这些脚本并以非常方便的方式运行。此项目的所有脚本都定义在此 derry 脚本和 makefile 脚本中。
示例
运行 make watch 或 derry watch 而不是
flutter pub run build_runner watch --delete-conflicting-outputs
或运行 make build_apk_dev 或 derry build_apk_dev 而不是
flutter build apk --flavor development -t lib/main_development.dart
运行测试?
要运行所有单元和 widget 测试,请使用以下命令
$ flutter test --coverage --test-randomize-ordering-seed random
要查看生成的覆盖率报告,您可以使用 lcov。
# Generate Coverage Report
$ genhtml coverage/lcov.info -o coverage/
# Open Coverage Report
$ open coverage/index.html
处理翻译?
此项目依赖于 flutter_localizations 并遵循 Flutter 的官方国际化指南。
添加字符串
- 要添加新的本地化字符串,请打开位于
lib/l10n/arb/app_en.arb的app_en.arb文件。
{
"@@locale": "en",
"counterAppBarTitle": "Counter",
"@counterAppBarTitle": {
"description": "Text shown in the AppBar of the Counter Page"
}
}
- 然后添加新的键/值和描述
{
"@@locale": "en",
"counterAppBarTitle": "Counter",
"@counterAppBarTitle": {
"description": "Text shown in the AppBar of the Counter Page"
},
"helloWorld": "Hello World",
"@helloWorld": {
"description": "Hello World Text"
}
}
- 使用新字符串
import 'package:flutter_boilerplate/l10n/l10n.dart';
@override
Widget build(BuildContext context) {
final l10n = context.l10n;
return Text(l10n.helloWorld);
}
添加支持的区域设置
如果您在翻译过程中遇到问题,请运行
flutter gen-l10n --template-arb-file=arb/app_en.arb
更新位于 ios/Runner/Info.plist 的 Info.plist 中的 CFBundleLocalizations 数组,以包含新的区域设置。
...
<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>es</string>
</array>
...
添加翻译
- 对于每个支持的区域设置,请在
lib/l10n/arb中添加一个新的 ARB 文件。
├── l10n
│ ├── arb
│ │ ├── app_en.arb
│ │ └── app_es.arb
- 将翻译后的字符串添加到每个
.arb文件中
app_en.arb
{
"@@locale": "en",
"counterAppBarTitle": "Counter",
"@counterAppBarTitle": {
"description": "Text shown in the AppBar of the Counter Page"
}
}
app_es.arb
{
"@@locale": "es",
"counterAppBarTitle": "Contador",
"@counterAppBarTitle": {
"description": "Texto mostrado en la AppBar de la página del contador"
}
}
其他平台上的相同实现
待办事项
- 尽可能每天更新,正在进行中 [WIP]。
觉得这个项目有用吗?❤️
- 请点击页面右上角的 ⭐ 按钮来支持。✌️