Skip to content

Authentication flutter app example for Android and iOS. Implementation of a clean architecture with riverpod and 180 tests.

Notifications You must be signed in to change notification settings

PKeviin/flutter-login-example

Repository files navigation

Template Auth App

Authentication flutter app example for Android and iOS.
Implementation of a clean architecture with riverpod and 180 tests (+95% code coverage without UI, provider & go_router).
The objective of this project is to make the best use of good practices and to provide a template for a new project.


πŸ“Œ Table of Contents


✨ Demo

Demo


πŸš€ Getting Started

This project contains 3 flavors:

  • development
  • staging
  • production

Editing .env.dev, .env.stg, .env.prod files and add .env* to .gitignore file.

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

# Run Development
$ flutter run --flavor development --target lib/main_development.dart

# Run Staging
$ flutter run --flavor staging --target lib/main_staging.dart

# Run Production
$ flutter run --flavor production --target lib/main_production.dart

ℹ️ Informations

  • Implementation of FakeLoginRemoteDataSourceImpl, Using LoginRemoteDataSourceImpl to implement real login
  • Added a listener in the app.dart file to display a global failure snackbar
  • Added a listener in the app.dart file to display a global loader overlay with loader_overlay
  • Implementation of privacy_provider.dart to manage user's privacy status
  • Saving user in phone, Using local_auth to re-login with biometrics

πŸ’» Commande line

Build runner for freezed and json_serializable

flutter pub run build_runner build --delete-conflicting-outputs

flutter pub run flutter_native_splash:create --path=flutter_native_splash.yaml
flutter pub run flutter_native_splash:remove

Generation of icons for the different flavors for Android and iOS

# Production
flutter pub run flutter_launcher_icons:main -f flutter_launcher_icons-production.yaml

# Staging
flutter pub run flutter_launcher_icons:main -f flutter_launcher_icons-staging.yaml

# Development
flutter pub run flutter_launcher_icons:main -f flutter_launcher_icons-development.yaml

Test coverage More detail here

sh scripts/import_files_coverage.sh template
sh scripts/create_clean_lcov_and_generate_html.sh true

πŸ“¦ Package used


🌐 Translations

This project relies on [flutter_localizations][https://api.flutter.dev/flutter/flutter_localizations/flutter_localizations-library.html] with Flutter Intl.

Adding Strings

  1. To add a new localizable string, open the intl_en.arb and all other .arb file at lib/core/lcoales/l10n/.
{
    "helloWorld": "Hello World!",
    "@helloWorld": {
      "description": "The conventional newborn programmer greeting"
    }
}
  1. Use the new string
import 'lib/core/locales/generated/l10n.dart';

// If you don't have `context` to pass
@override
Widget build(BuildContext context) {
   return Text(S.current.helloWorld);
}

// With context
@override
Widget build(BuildContext context) {
   return Text(S.of(context).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

For each supported locale, add a new ARB file in lib/core/locales/l10n.

β”œβ”€β”€ core
β”‚   β”œβ”€β”€locales
β”‚   β”‚  β”œβ”€β”€ l10n
β”‚   β”‚  β”‚   β”œβ”€β”€ app_en.arb
β”‚   β”‚  β”‚   └── app_es.arb

🚚 Deploying the app

πŸ›  Prerequisites

  • Code Signin Assets
    • 🍏 Apple Certificate
      • public key (download from the developer.apple.com console)
      • private key (.p12)
    • πŸ€– Android Keystore
      • key.properties file -> to store at: app/android/key.properties
      • android_key.keystore file -> to store at: app/android/app/android_key.keystore

🏷 Bump the app version

In pubspec.yaml:

version: 0.0.1+1 # {version}+{build} Bump version following semantic version rules, and bump build ALWAYS (for each new release)

commit and push to master branch
commit and push tag v{version} (v0.0.1) to master branch

πŸ“¦ Building apps for the stores

  • 🍏 iOS : flutter build ios --flavor production --target lib/main_prod.dart --release
  • πŸ€– Android : flutter build appbundl --flavor production --target lib/main_prod.dart --release

🚚 Upload to stores

🍏 iOS

Upload the build to App Store Connect using the Transporter App
Go to the App Store Connect console: https://appstoreconnect.apple.com/apps/

β˜‘οΈ TestFlight
  • ⏳ Wait for the build to be available for testing
  • πŸ” Submit for review
  • πŸ§ͺ Submit to Internal or External testers
βœ… App Store (Production)
  • πŸ‘‰ Create a new version
  • πŸ“¦ Select the latest build
  • πŸ” Submit for review
  • πŸ“² Submit to users
πŸ€– Android

Go to Google Play console: https://play.google.com/console/u/0/developers/

β˜‘οΈ Tests Internes
  • πŸ‘‰ Create a Release
  • πŸ“¦ Uploader the build
  • πŸ§ͺ Submit to testers
βœ… Production
  • πŸ‘‰ Create a Release
  • πŸ“¦ Uploader the build
  • πŸ“² Submit to users

πŸ‘† Possibility of improvement

  1. Replace flutter_dotenv package to make key hacking harder. Instead, use the ENVied package and enable obfuscation.
  2. Added accessibility with Semantics
  3. Implementation widget test, provider test, go_router test and integration tests

πŸ“¦ Useful package


🧱 Project structure

lib/
β”œβ”€ core/
β”‚ β”œβ”€ credentials.dart
β”‚ β”œβ”€ constants/
β”‚ β”œβ”€ enums/
β”‚ β”œβ”€ impl/
β”‚ β”‚ β”œβ”€ api/
β”‚ β”‚ β”œβ”€ local_auth/
β”‚ β”‚ β”œβ”€ logger/
β”‚ β”‚ β”œβ”€ network_info/
β”‚ β”‚ β”œβ”€ package_info/
β”‚ β”‚ β”œβ”€ picker_file/
β”‚ β”‚ β”œβ”€ secure_storage/
β”‚ β”‚ β”œβ”€ share_file/
β”‚ β”œβ”€ locales/
β”‚ β”œβ”€ router/
β”‚ β”œβ”€ utils/
β”‚ β”‚ β”œβ”€ errors/
β”‚ β”‚ β”œβ”€ extensions/
β”‚ β”‚ β”œβ”€ platform/
β”‚ β”‚ β”œβ”€ usecases/
β”‚ β”‚ β”œβ”€ utils.dart
β”‚ β”‚ β”œβ”€ utils_ui.dart
β”‚ β”‚ β”œβ”€ utils_validator.dart
β”œβ”€ features/
β”‚ β”œβ”€ commons/
β”‚ β”‚ β”œβ”€ pages/
β”‚ β”‚ β”œβ”€ providers/
β”‚ β”‚ β”œβ”€ widgets/
β”‚ β”œβ”€ feature1/
β”‚ β”‚ β”œβ”€ data/
β”‚ β”‚ β”‚ β”œβ”€ datasources/
β”‚ β”‚ β”‚ β”œβ”€ models/
β”‚ β”‚ β”‚ β”œβ”€ repositories/
β”‚ β”‚ β”œβ”€ domain/
β”‚ β”‚ β”‚ β”œβ”€ entities/
β”‚ β”‚ β”‚ β”œβ”€ repositories/
β”‚ β”‚ β”‚ β”œβ”€ usecases/
β”‚ β”‚ β”œβ”€ presentation/
β”‚ β”‚ β”‚ β”œβ”€ pages/
β”‚ β”‚ β”‚ β”œβ”€ provider/
β”‚ β”‚ β”‚ β”œβ”€ widgets/
β”œβ”€ ui/
β”‚ β”œβ”€ assets/
β”‚ β”œβ”€ colors/
β”‚ β”œβ”€ icons/
β”‚ β”œβ”€ layout/
β”‚ β”œβ”€ spacing/
β”‚ β”œβ”€ themes/
β”‚ β”œβ”€ typography/
β”‚ β”œβ”€ widgets/
β”œβ”€ app.dart
β”œβ”€ main_dev.dart
β”œβ”€ main_preprod.dart
β”œβ”€ main_prod.dart
test/

πŸ“š Helped me

The links that helped me create this template

About

Authentication flutter app example for Android and iOS. Implementation of a clean architecture with riverpod and 180 tests.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Languages