Praxis Flutter Playground

以以下平台为目标的最小 Flutter 项目

平台

  • Android ✅ 完成
  • iOS ✅ 完成
  • Web ✅ 完成

截图

drawing

drawing

drawing

drawing

入门?

此项目包含 3 种风味

  • 开发
  • 测试
  • 生产

To generate code for injectable

```sh
$ flutter packages pub run build_runner build --delete-conflicting-outputs

---

To run the desired flavor either use the launch configuration in VSCode/Android Studio or use the following commands:

```sh
# 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

---

## Running Tests ?

To run all unit and widget tests use the following command:

```sh
$ 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 官方国际化指南

添加字符串

  1. 要添加新的本地化字符串,请打开位于 lib/l10n/arb/app_en.arbapp_en.arb 文件。

{
    "@@locale": "en",
    "counterAppBarTitle": "Counter",
    "@counterAppBarTitle": {
        "description": "Text shown in the AppBar of the Counter Page"
    }
}
  1. 然后添加新的键/值和描述

{
    "@@locale": "en",
    "counterAppBarTitle": "Counter",
    "@counterAppBarTitle": {
        "description": "Text shown in the AppBar of the Counter Page"
    },
    "helloWorld": "Hello World",
    "@helloWorld": {
        "description": "Hello World Text"
    }
}
  1. 运行命令更新翻译

# Generate Translations.
$ flutter gen-l10n --template-arb-file=arb/app_en.arb
  1. 运行后使用新的字符串

import 'package:flutter_praxis/l10n/l10n.dart';

@override
Widget build(BuildContext context) {
  final l10n = context.l10n;
  return Text(l10n.helloWorld);
}

添加支持的区域设置

更新位于 ios/Runner/Info.plistInfo.plist 中的 CFBundleLocalizations 数组,以包含新的区域设置。

    ...

    <key>CFBundleLocalizations</key>
	<array>
		<string>en</string>
		<string>es</string>
	</array>

    ...

添加翻译

  1. 对于每个支持的区域设置,请在 lib/l10n/arb 中添加一个新的 ARB 文件。

├── l10n
│   ├── arb
│   │   ├── app_en.arb
│   │   └── app_es.arb
  1. 将翻译后的字符串添加到每个 .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"
    }
}

GitHub

查看 Github