Flutterstarterproject - Clean Architecture Flutter starter project, using tdd + bloc

Overview

Flutter Starter Project

coverage report style: very good analysis License: MIT

Generated by the Nero Lab CLI 🤖

A Nero Lab Project created by Nero Lab CLI.


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

Before you push your local branch to remote branch always do this steps:

$ flutter format lib test
$ flutter analyze lib test

*Flutter Starter Project works on iOS, Android, and Web.


Setup GitLab 🐱

Git Branchs

  1. master as development branch (protected)
  2. staging (protected) : for QA to testing App
  3. production (protected) : for production, deploy to Play Store or App Store
  4. features branch

GitLab Flow

Principles

  • Create a new local branch for the task and periodically push a branch of the same name on the server

  • When the task is finished, request a Merge Request for the master branch

  • When the submitted changes were reviewed/approved, merge them with the master branch

  • Once in the master, the code must be integrated into the company's internal environments branches, until reaching the production branch.

  • When being merged into the master, delete the branch where the task was developed leaving the repository more organized.

    https://github.com/jadsonjs/gitlab-flow/raw/master/images/flow14.png

Features Branch > Master > Staging > Production

Read this for more information GitHub - jadsonjs/gitlab-flow: Shows the Gitlab flow workflow

CI Variables

In your project open settings > CI/CD > Variables , and this variabel:

Gitlab CI Variables

  • Encode the keystore: base64 key.jks
  • Copy the base64 output and create a variable called STORE_FILE
  • Save the store password as STORE_PASSWORD variable
  • Save the key password as KEY_PASSWORDvariable
  • Save the key alias as KEY_ALIAS variable

To make the deployment via Fastlane working, you need to to get API access to Google Play console. To get an api key json file, follow the steps of the Collect your Google credentials section of the Fastlane guide

  • Save the content of the key.json file as JSON_KEY_DATA variable.

To deploy to Firebase App Distribution via Fastlane, follow the steps Firebase App Distribution.

  • Save the Firebase app id as FIREBASE_APP_ID variable
  • Save the firebase cli token as FIREBASE_CLI_TOKEN variable, to get firebase cli token follow this steps

GitLab CI/CD

This is Gitlab pipeline visualize for this project: Gitlab Pipeline

Stages

There are 4 stages:

  1. Test
  2. Build
  3. Staging
  4. Internal_test
  5. Production
1. Test

Test stage will run in all branchs and do this scripts

- flutter format --set-exit-if-changed lib test
- flutter analyze lib test
- flutter test --coverage
- lcov --remove coverage/lcov.info 'lib/*/*.g.dart' 'lib/core/**' -o coverage/lcov.info
- genhtml coverage/lcov.info --output=coverage

If when run flutter format --set-exit-if-changed lib test must no file changed or Gitlab CI will return fail, and make sure no error or warning in this project. So before you push the project to remote you need run this in your local branch

$ flutter format lib test
$ flutter analyze lib test
2. Build

Build stage have two jobs build_android_staging will run when master merge to staging branch and build_android_production will run when merge to production branch.

3. Staging

Staging stage only run in staging branch and will distribute app to Firebase App Distribution for testing by QA to testing the app in staging flavor. In Firebase App Distribution make group with name Tester and add tester's emails.

4. Internal Test

Internal test stage will distribute production app to internal test in Playstore

5. Production

Production stage will promote app from internal test to production. You need run this manually after internal test app passed from testing in Gitlab CI/CD.


Running Test 🧪

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

$ flutter test --coverage

To view the generated coverage report you can use lcov.

# Remove core file and generated file to get actual coverage
$ lcov --remove coverage/lcov.info 'lib/*/*.g.dart' 'lib/core/**' -o coverage/lcov.info

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

# Open Coverage Report
$ open coverage/index.html

Integration Testing 📱

Firebase Test Lab

Go to the Firebase Console, and create a new project if you don’t have one already. Then navigate to Quality > Test Lab:

https://flutter.dev/assets/images/docs/integration-test/test-lab-1.png

Uploading an Android APK

Create an APK using Gradle:

$ pushd android
# flutter build generates files in android/ for building the app
$ flutter build apk --flavor staging -t lib/main_staging.dart
$ ./gradlew app:assembleAndroidTest
$ ./gradlew app:assembleDebug -Ptarget=integration_test/<name>_test.dart
$ popd

Where <name>_test.dart is the file created in the Project Setup section.

Drag the “debug” APK from <flutter_project_directory>/build/app/outputs/apk/debug into the Android Robo Test target on the web page. This starts a Robo test and allows you to run other tests:

https://flutter.dev/assets/images/docs/integration-test/test-lab-2.png

Click Run a test, select the Instrumentation test type and drag the following two files:

  • <flutter_project_directory>/build/app/outputs/apk/debug/<file>.apk
  • <flutter_project_directory>/build/app/outputs/apk/androidTest/debug/<file>.apk

https://flutter.dev/assets/images/docs/integration-test/test-lab-3.png

If a failure occurs, you can view the output by selecting the red icon

https://flutter.dev/assets/images/docs/integration-test/test-lab-4.png

For more information read Flutter Integration Firebase Test Lab or from flutter doc Integration Testing.

Flutter integration tests on Firebase Test Lab

Integration testing

Integration Testing in Real Device

flutter drive --driver=test_driver/integration_test.dart --target=integration_test/app_test.dart

QA Testing Staging App

We will use Firebase App Distribution to distribute staging app to Tester. To add tester add emails in folder firebase_app_distribution/testers.txt, or add groups in folder firebase_app_distribution/groups.txt, add emails or groups divided by comma.

Example add testers:

Example add groups:

Testers, QA

Group tester need set up in Firebase Console go to App Distribution > Testers & Groups and add tester to the group.


Working with Translations 🌐

This project relies on flutter_sheet_localization and read documentation of flutter_sheet_localization_generator. for more information.

Usage

1. Create a Google Sheet

Create a sheet with your translations (following the bellow format, an example sheet is available here) :

example

Make sure that your sheet is shared :

share

Extract from the link the DOCID and SHEETID values : https://docs.google.com/spreadsheets/d/<DOCID>/edit#gid=<SHEETID>) :

2. Declare a localization delegate

Declare the following AppLocalizationsDelegate class with the SheetLocalization annotation pointing to your sheet in a lib/l10n/localization.dart file :

import 'package:flutter/widgets.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_sheet_localization/flutter_sheet_localization.dart';

part 'localization.g.dart';

@SheetLocalization("DOCID", "SHEETID", 1) // <- See 1. to get DOCID and SHEETID
// the `1` is the generated version. You must increment it each time you want to regenerate
// a new version of the labels.
class AppLocalizationsDelegate
    extends LocalizationsDelegate<AppLocalizationsData> {
  const AppLocalizationsDelegate();

  @override
  bool isSupported(Locale locale) => localizedLabels.containsKey(locale);

  @override
  Future<AppLocalizationsData> load(Locale locale) =>
      SynchronousFuture<AppLocalizationsData>(localizedLabels[locale]!);
  @override
  bool shouldReload(AppLocalizationsDelegate old) => false;
}

3. Generate your localizations

Run the following command to generate a lib/l10n/localization.g.dart file :

$ flutter packages pub run build_runner build

4. Display your labels

import 'package:flutter_starter_project/core/l10n/localizations.dart';

final labels = context.localizations;

print(labels.dates.month.february);
print(labels.templated.hello(firstName: "World"));
print(labels.templated.contact(Gender.male, lastName: "John"));

Generate Icon Android IOS

Generate launcher icon for android and ios

$ flutter pub run flutter_launcher_icons:main -f flutter_launcher_icons*

Generate Splashscreen Android IOS

Generate splashscreen for android and ios

$ flutter pub run flutter_native_splash:create
You might also like...

Clean Architecture + TDD + SOLID + Dependency Injection + GitFlow + Mobx

 Clean Architecture + TDD + SOLID + Dependency Injection + GitFlow + Mobx

Clean Architecture + TDD + SOLID + Dependency Injection + GitFlow + Mobx Flutter Interview Challenge This app is part of an interview process. It took

Dec 28, 2022

Flutter starter project - boilerPlate for Clean Architecture with Domain-Driven-Design with commonly used dependencies

flutter_starter_project A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you

Jan 2, 2022

clean architecture and clean code with flutter , with bloc and getx state managment .

example_bloc A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if

Aug 22, 2022

Proyect with Clean Architecture / Hexagonal Architecture - Patron BLoC - The MovieDB API

flutter_movies_db A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you starte

Sep 22, 2022

This project follows the Reso Coder course for flutter test-driven-development with clean architecture and BloC state management for a random trivia simple app.

This project follows the Reso Coder course for flutter test-driven-development with clean architecture and BloC state management for a random trivia simple app.

Jan 5, 2022

Flutter project to find and discover events with Clean Architecture and Bloc from SeatGeek API.

Flutter project to find and discover events with Clean Architecture and Bloc from SeatGeek API.

Dec 6, 2022

Flutter boilerplate with TDD architecture

flutter_tdd_architecture A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you

May 25, 2022

💻 Flutter clean architecture using the bloc & cubit library for state management

💻 Flutter clean architecture using the bloc & cubit library for state management

Egymation 🎥 · This application was developed using a well-defined and decoupled architecture, following TDD (test-driven programming) as a working me

Nov 21, 2022

🚀 User management app built in flutter using clean architecture, MVVM, get it, dio, RxDart, bloc, cubit, getX and provider

🚀 User management app built in flutter using clean architecture, MVVM,  get it,  dio, RxDart, bloc, cubit, getX and provider

🔥 Go Rest app In this project, we are going to build a user management app using Flutter. We have used the Go REST API to make HTTP request methods.

Aug 14, 2023
Owner
Muhammad Noerhidayatullah
Muhammad Noerhidayatullah
Random Users app, developed with Flutter and using Clean Architecture, BLoC, TDD and Functional Programming.

random_users This project is a sample of how to build a Flutter application using de benefits of Clean Architecture, TDD and Functional Programming. G

Yago Nunes 3 Jul 21, 2022
Ouday 25 Dec 15, 2022
Starter-Flutter - Starter flutter project for best architecture and seperation of code

Modular-Architecture Codebase CodeBase , Infrastructure and the common Layers (c

Ahmed Tawfiq 13 Feb 16, 2022
A starter kit for beginner learns with Bloc pattern, RxDart, sqflite, Fluro and Dio to architect a flutter project. This starter kit build an App Store app as a example

Flutter Starter Kit - App Store Example A starter kit for beginner learns with Bloc pattern, RxDart, sqflite, Fluro and Dio to architect a flutter pro

kw101 678 Jan 8, 2023
Clean Architecture Project with TDD Approach

Clean-Architecture-Project-with-TDD-Approach Small project to implement TDD(Testing Driven Development) by applying SOLID and YAGNI and rules(Clean Ar

null 7 Jun 24, 2022
COVID-19 application made with Flutter, following Test Driven Development (TDD) and Clean Architecture along with Internationalization with JSON.

Covid App COVID-19 application made with Flutter, following Test Driven Development (TDD) and Clean Architecture along with Internationalization with

Sandip Pramanik 4 Aug 4, 2022
Flutter - Clean Architecture & TDD

Flutter - Clean Architecture & TDD Introducción Este proyecto consta de una aplicación móvil desarrollada en Flutter, la cual muestra información acer

Jorge Fernández 21 Oct 26, 2022
Flutter, Dart, TDD, Clean Architecture, SOLID e GetX

cep_search_clean_architecture A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to ge

Jadiel Santana 3 Feb 22, 2022
Flutter auth app with TDD Clean Architecture

Flutter App Auth ?? This is App with Auth Function like Login and Register. All API using reqres.in. This app also implementing Flutter Clean Architec

LazyCat Labs 73 Dec 29, 2022
Made with Clean architecture + TDD + GraphQL + flutter_bloc + CodeCov + GitHooks + GitHub Actions (CI/CD) and finally with 💙

Rick and Morty Info A simple app to demonstrate Clean Architecture with GraphQL and flutter_bloc Motivation In Martin Fowler's words, “Any fool can wr

Venkatesh Prasad 473 Dec 25, 2022