Flutter Riverpod Firebase


Getting Started πŸš€

This project contains 3 flavors:

  • development
  • staging
  • production

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

# 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 Riverpod Firebase works on iOS, Android, Web, and Windows.


Structure πŸ—

The project is structured as follows:

β”œβ”€β”€ lib
β”‚   β”œβ”€β”€ src
β”‚   β”‚   β”œβ”€β”€ app
β”‚   β”‚   β”‚   β”œβ”€β”€ app.dart
β”‚   β”‚   β”œβ”€β”€ configs
β”‚   β”‚   β”‚   β”œβ”€β”€ server.dart
β”‚   β”‚   β”œβ”€β”€ data
β”‚   β”‚   β”‚   β”œβ”€β”€ datasources
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ remote
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ auth_data_remote.dart
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ user_data_remote.dart
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ local
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ auth_data_local.dart
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ todo_data_local.dart
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ user_data_local.dart
β”‚   β”‚   β”‚   β”œβ”€β”€ entites
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ todo.dart
β”‚   β”‚   β”‚   β”œβ”€β”€ repositories
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ auth_repository.dart
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ auth_repository_impl.dart
β”‚   β”‚   β”œβ”€β”€ di
β”‚   β”‚   β”‚   β”œβ”€β”€ modules
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ auth_module.dart
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ routes_module.dart
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ storage_module.dart
β”‚   β”‚   β”‚   β”œβ”€β”€ injection.config.dart
β”‚   β”‚   β”‚   β”œβ”€β”€ injection.dart
β”‚   β”‚   β”œβ”€β”€ features
β”‚   β”‚   β”‚   β”œβ”€β”€ auth
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ view
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ login_form.dart
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ login_page.dart
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ view_model
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ auth_riverpod.dart
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ auth.dart
β”‚   β”‚   β”‚   β”œβ”€β”€ todo
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ view
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ todo_page.dart
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ view_model
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ todo_riverpod.dart
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ todo.dart
β”‚   β”‚   β”‚   β”œβ”€β”€ feature.dart
β”‚   β”‚   β”œβ”€β”€ l10n
β”‚   β”‚   β”‚   β”œβ”€β”€ arb
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ app_en.arb
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ app_ja.arb
β”‚   β”‚   β”‚   β”œβ”€β”€ l10n.dart
β”‚   β”‚   β”‚   β”œβ”€β”€ l10n_model.dart
β”‚   β”‚   β”œβ”€β”€ routes
β”‚   β”‚   β”‚   β”œβ”€β”€ app_router.dart
β”‚   β”‚   β”‚   β”œβ”€β”€ guards.dart
β”‚   β”‚   β”œβ”€β”€ shared
β”‚   β”‚   β”‚   β”œβ”€β”€ extensions
β”‚   β”‚   β”‚   β”œβ”€β”€ listeners
β”‚   β”‚   β”‚   β”œβ”€β”€ resources
β”‚   β”‚   β”‚   β”œβ”€β”€ storage
β”‚   β”‚   β”‚   β”œβ”€β”€ theme
β”‚   β”‚   β”‚   β”œβ”€β”€ widgets
β”‚   β”‚   β”‚   β”œβ”€β”€ utils
β”‚   β”œβ”€β”€ firebase_options.dart
β”‚   β”œβ”€β”€ main.dart
β”‚   β”œβ”€β”€ main_development.dart
β”‚   β”œβ”€β”€ main_staging.dart
β”‚   └── main_production.dart

Running Tests πŸ§ͺ

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

$ flutter test --coverage --test-randomize-ordering-seed random

To view the generated coverage report you can use lcov.

# Generate Coverage Report
$ genhtml coverage/lcov.info -o coverage/

# Open Coverage Report
$ open coverage/index.html

Working with Translations 🌐

This project relies on flutter_localizations and follows the official internationalization guide for Flutter.

Adding Strings

  1. To add a new localizable string, open the app_en.arb file at lib/src/l10n/arb/app_en.arb.
{
    "@@locale": "en",
    "counterAppBarTitle": "Counter",
    "@counterAppBarTitle": {
        "description": "Text shown in the AppBar of the Counter Page"
    }
}
  1. Then add a new key/value and description
{
    "@@locale": "en",
    "counterAppBarTitle": "Counter",
    "@counterAppBarTitle": {
        "description": "Text shown in the AppBar of the Counter Page"
    },
    "helloWorld": "Hello World",
    "@helloWorld": {
        "description": "Hello World Text"
    }
}
  1. Use the new string
import 'package:flutter_riverpod_firebase/l10n/src/l10n.dart';

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

Adding Supported Locales

Update the CFBundleLocalizations array in the Info.plist at ios/Runner/Info.plist to include the new locale.

    ...

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

    ...

Adding Translations

  1. For each supported locale, add a new ARB file in lib/src/l10n/arb.
β”œβ”€β”€ l10n
β”‚   β”œβ”€β”€ arb
β”‚   β”‚   β”œβ”€β”€ app_en.arb
β”‚   β”‚   └── app_es.arb
  1. Add the translated strings to each .arb file:

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"
    }
}

Generating Translations

To use the latest translations changes, you will need to generate them:

  1. Generate localizations for the current project:
flutter gen-l10n --arb-dir="lib/src/l10n/arb"

Alternatively, run flutter run and code generation will take place automatically.