Skip to content

fzl-22/faisal-starter-code-flutter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Faisal's Starter Code Flutter

Version 1.0.0

This repository contains my starter code for a Flutter project, which is highly inspired by dbestech and Very Good Ventures.

For quick installation, you can run the following command:

Linux & MacOS:

curl -s https://raw.githubusercontent.com/fzl-22/faisal-starter-code-flutter/master/install.sh > install.sh && bash install.sh

Note: gnu-sed is required for installation on MacOS (brew install gnu-sed)

Table of Contents

1 Technology Stack

Software Version
Flutter 3.19.2
Dart 3.3.0
OpenJDK 11.0.22

2 Dependencies

Package Description
bloc State management library that helps implement the BLoC design pattern.
cached_network_image Loads and caches network images.
dartz Functional programming in Dart (used for clean error-handling)
dio HTTP networking package with supports on Interceptor, request cancellation, timeout, and etc.
envied Explicitly reads environment variables into a dart file from a .env file for more security and faster start up times.
equatable Value-based objects comparison.
flutter_bloc Flutter Widgets that make it easy to implement the bloc
flutter_dotenv Load configuration at runtime from a .env file
flutter_svg SVG rendering widget from an asset.
freezed_annotation Annotations for freezed.
get_it Simple direct Service Locator for dependency injection.
go_router Routing package with URL-based API.
injectable Code generator for get_it
logger Beautiful log printer.
provider A wrapper around InheritedWidget. Used for local state-abstraction.
safe_change_notifier Safer replacement for ChangeNotifier and ValueNotifer.
talker_dio_logger Lightweight and customizable dio http client logger on talker base.
bloc_test Testing library for blocs and cubits (dev_dependencies)
build_runner A build system for Dart code generation and modular compilation (dev_dependencies)
envied_generator Generator for https://pub.dev/packages/envied (dev_dependencies).
freezed Code generation for immutable classes (dev_dependencies).
injectable_generator A generator for injectable library (dev_dependencies)
mocktail Mock library which simplifies mocking with null safety support (dev_dependencies)
very_good_analysis Lint rules for Dart and Flutter by Very Good Ventures (dev_dependencies).

3. Directory Structures and Architectural Overviews

3.1 assets/

This directory contains asset resources such as fonts, images, icon, and etc. Any new asset must be registered to pubspec.yaml and lib/core/resources.

3.2 lib/

Here resides the application source code. Contains only [lib/core/] and [lib/src/].

3.2.1 lib/core/

Contains core features and utilities of the app written mostly in Dart code (almost framework-independent).

3.2.1.1 lib/core/common/

Contains application-wide shared themes, widgets, screens, or state.

3.2.1.2 lib/core/constants/

Contains application-wide constant values.

3.2.1.3 lib/core/errors/

Contains predefined exceptions and failures.

3.2.1.4 lib/core/extensions/

Contains developer-defined extensions for built-in Dart object. This directory provides more-compact of some Dart object/method calls.

3.2.1.5 lib/core/injection/

Contains injection of dependencies of the application architecture. This directory provides dependency injection container.

3.2.1.6 lib/core/resources/

Contains registered constants that hold the value of each assets path in assets/ and defined typographies. This dependency provides UI assets consistency.

3.2.1.7 lib/core/router/

Contains application routes and transitions. This directory defines routes configuration.

3.2.1.8 lib/core/usecase/

Contains classes that encapsulate the business logic of the application (usecases).

3.2.1.9 lib/core/utils/

Contains additional utilities to the application.

3.2.2 lib/src/

This directory holds the features of the application. Any feature added in the application must reside in this directory as lib/src/[feature]/.

Each feature has 3 layers according to the Clean Architecture design by Robert C. Martin.

Source image: dbestech.com

So, each feature must have:

  • lib/src/[feature]/domain/
  • lib/src/[feature]/data/
  • lib/src/[feature]/presentation/
3.2.2.1 Domain Layer (lib/src/[feature]/domain/)

Domain layer contains the business logic of the application (core business logic, not BLoC logic).

Domain does not depend on anyone. Presentation layer finds domain layer to work with.

This layer have 3 sublayers:

  • lib/src/[feature]/domain/entities/
  • lib/src/[feature]/domain/repos/
  • lib/src/[feature]/domain/usecases/
3.2.2.1.1 Entities (lib/src/[feature]/domain/entities/)

Entities hold the blue print of data model which we will pass around for a certain features or screens or pages.

3.2.2.1.2 Repositories (lib/src/[feature]/domain/repos)

Domain repositories contains abstract classes that defines a contract between domain layer and data layer.

The method of repository must be implemented in the data layer's repository.

3.2.2.1.3 Usecases (lib/src/[feature]/domain/usecases)

Usecases contains communication tunnel between presentation and domain layer

Usecases depend on repositories and should be independent of anything outside of domain layer.

3.2.2.2 Data Layer (lib/src/[feature]/data/)

Data layer is an interface to communicate with data outside the app (remote or local).

Data layer depends on domain layer.

This layer have 3 sublayers:

  • lib/src/[feature]/data/models/
  • lib/src/[feature]/data/repos/
  • lib/src/[feature]/data/datasources/
3.2.2.2.1 Models (lib/src/[feature]/data/models/)

Model is an extension of the extensions. This sublayer provides JSON serialization or constructorss to interact with outside data.

3.2.2.2.2 Repositories (lib/src/[feature]/data/repos/)

The repos in data layer is the implementation of the repos in the domain layer. It provides the communication with domain layers.

Data layer's repositories depends on datasources.

3.2.2.2.3 Data Sources (lib/src/[feature]/data/datasources/)

Data sources provides communication with data from outside (API, local storage, and etc).

Data sources depends on external source, for example: http package.

3.2.2.3 Presentation Layer (lib/src/[feature]/presentation/)

Presentation layer provides UI presented to the user. Flutter's code only resides here in lib/src/[feature]/ directory.

DO NOT add framework-dependent code to any other layer than the presentation layer.

Presentation layer is framework-dependent and depends on domain layer.

This layer may have 3 sublayers:

  • lib/src/[feature]/domain/bloc/
  • lib/src/[feature]/domain/views/
  • lib/src/[feature]/domain/widgets/

This sublayer can have providers to manages local state-abstraction if necessary.

3.2.2.3.1 BLoC (lib/src/[feature]/presentation/bloc).

BLoC contains the state management to controls UI state.

BLoC is dependent to the domain layer's usecases.

It provides multilayer state-management between presentation layer and domain layer.

Note: It is recommended to inject BLoC to the widget tree via the router instead of the root widget or inside a views.

3.2.2.3.2 Views (lib/src/[feature]/presentation/views).

Views sublayer provides the screens of the feature. The state of the screens and widgets inside is controlled with state manager.

3.2.2.3.3 Widgets (lib/src/[feature]/presentation/widgets/).

Provides the feature-wide shared widgets that resides in the views sublayer.

4 Guides

4.1 Setup Project

4.1.1 Clone project

Clone this repository to your local machine.

git clone [email protected]:fzl-22/faisal-starter-code-flutter.git

4.1.2 Get all dependencies

To get all dependencies, run the following command.

flutter pub get

4.1.3 Run the code generator

In a newly cloned project, you will notice that some files with *.g.dart, *.config.dart, and *.freezed.dart are missing. You need to generate those files with build_runner.

dart run build_runner build # one time and exits

or

dart run build_runner watch # watch and rebuild as necessary

4.2 Run project

Turn on your Android emulator or physical device. Then, run the project.

flutter run

flutter run key commands.

  • r to hot reload.
  • R to hot restart.
  • h to list all available interactive commands.
  • d to detach (terminate "flutter run" but leave application running).
  • c to clear the screen
  • q to quit (terminate the application on the device).

4.3 Installing and removing packages

Install a package.

flutter pub add {package}

Install a package as dev_dependencies.

flutter pub add dev:{package}

Uninstall a package.

flutter pub remove {package}

5 Documentation

The documentation of this project can be generated using dartdoc.

Install compatible version of dartdoc.

fvm dart pub global activate dartdoc

In the project root directory, generate HTML documentation.

dart doc .

Make sure you have no error in the source code

Your generated documentation will be on doc/api/ directory.

Serve the docs with dhttpd package (install with fvm dart pub global activate dhttpd).

dhttpd --path doc/api

You can read the documentation at http://localhost:8080.

About

My Flutter's starter code (v1.0.0)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published