Mastering Modular in Flutter Application
R Rifa Fauzi Komara
Currently
Mobile Programmer Specialist, Sinarmas MSIG Life
Part Time (Remote) Flutter Developer, Hireplace, Singapore
External Reviewer Flutter, Dicoding Indonesia
Previously
Community Lead, Google DSC Indonesia
Freelance Flutter Developer, Dcolearning
Flutter Developer, Cari Aja Indonesia
Android Developer, Eudeka and GITS Indonesia
@rifafauzi6
Outline
Modularization?
Modular programming is a software design technique to separate functionality into independent, interchangeable module, so that each contains everything necessary to execute a specific functionality.
Why we should care about Modular approach?
Common Project VS Multiple Module
lib
App
Module B
lib
Module A
App
Module C
Left side
Right side
Confidential + Proprietary
Sample
Confidential + Proprietary
Confidential + Proprietary
Modularization in Several Ways
Basic
Basic
Common
UI
Network
Custom Shared
Data Handler, Logic, etc
Visible to User
Helpers, Utils, Cons, etc
API, Model, Database, etc
Activity/View/Screen
Widget
Custom Widget
Custom Widget
Confidential + Proprietary
Sample
Confidential + Proprietary
Pattern / Architecture / State Management
State Management (BLoC)
Repository
Network
BLoC
UI
Visible to User
Logic
Data Handler
Data Provider
Page, Widget, Common, etc
BLoC / View Model / Presenter
Repo, SharedPreferences, etc
API, Model, Utils, etc
Confidential + Proprietary
Sample
Confidential + Proprietary
Unpublish
Unpublish
Local
App
Module Repository
Module BLoC
lib
Module Network
All module inside the project
Can connect with each module
Confidential + Proprietary
Sample
Confidential + Proprietary
How to create Module?
1. Android Studio
2. Terminal
$ flutter create --template=package name_of_module
Confidential + Proprietary
Add the Module into our Project
Project structure
Your module
Confidential + Proprietary
And How if our module is outside the project?
You can use path property and call (dots) .. first. Ex:
Your project
Your module
Confidential + Proprietary
Internet
App
lib
All module (bloc, repository, network) save on git except lib
Module Repository
Module BLoC
Module Network
Confidential + Proprietary
Sample
In Your Machine
In Your Git
Confidential + Proprietary
Add the Module from Git into our Project
Confidential + Proprietary
But, wait...
How if the git have a branch name and want to add specific branch?
Relax...
Confidential + Proprietary
But, wait...
If we use this approach, we will get the problem to update and reuse our module. What it’s?
Problem
If we add, delete, or change/update the function from module in the Git. The UI / your project can’t take the update function from the module because you must to publish the module update to git first (git push), so after that you can take the updated function from your module.
Form Local (your project)
Form Git (your module)
Confidential + Proprietary
Publish
Publish
For this way, the module that will be created is like library who add in the dependencies (Android Native) and host it into maven and Plugin or Package who add in the pubspec.yaml (Flutter) and host it into pub.dev
What Modularize can we use?
Image slides
Layer
Separate the module by layer
App
BLoC
Ne�two�r�k
Repos�i�t�o�r�y
l�i�b��/��UI
Image slides
Feature
Separate the module by feature
App
Log�i�n
Use�r
Home
Image slides
Combine
Separate the module by layer and add the feature as module
App
Repos�i�t�o�r�y
Fea�t�u�r�e��A
Fea�t�u�r�e��B
Ne�two�r�k
BLoC
Conclusion
Confidential + Proprietary
Without Implement Modular
Pros:
Cons:
Confidential + Proprietary
With Implement Modular
Pros:
Cons:
Confidential + Proprietary
What is your choice?
Confidential + Proprietary
References
Confidential + Proprietary
42
@rifafauzi6
rrifafauzikomara
rrifafauzikomara
Thank You!