Flutter Bloc : A Complete Guide to State Management in Flutter
In this article, I am going to explain about Bloc. Bloc is not just a state management, but it's also an architectural design pattern which helps us to build production-level applications.
- What is Bloc and its Architecture?
- What is BlocBuilder,
- BlocProvider,
- BlocListener,
- BlocConsumer,
- RepositoryProvider?
- Folder Structure For Bloc
Intro
When it comes to building an application,
Flutter is the easiest and powerful framework.
But building an application without any strong architecture is like building a house without any planning and blueprints.
- You won't understand the uses of architecture when building small applications.
- But when it comes to building a big production level application where you have many screens, animations, methods, classes, etc, without any proper architecture you will end up in a state where everything is messed up and you don't know how all the components, classes, methods are communicating and functioning.
So it is very necessary to maintain the code make code more readable and testable, and easily trackable when designing and developing this kind of big application.
There are many different packages available, and all have their own way to handle application states.
Why bloc?
In this article, I am going to explain about Bloc. Bloc is not just a state management, but it's also an architectural design pattern which helps us to build production-level applications.
..
What is Bloc?
Bloc stands for Business Logic Component.
The Bloc is distinguished into four layers
- UI (Presentation Layer)
- Bloc (Business Logic Layer)
- Data Layer (Repo & Data Provider )
- Data Provider - This layer retrieves/fetches the raw data from different data sources (ex: different APIs, DBs, Network, Shared preferences, etc).
- Repository - : The repository layer acts as an intermediary between the data sources (such as APIs, databases, or local storage) and the business logic layer. It abstracts away the details of how data is fetched and provides a clean API for the business logic to retrieve data.
- LoadingState - Will Show Progress Indicator
- LoadedState - Will Show Actual widget with data
- ErrorState - Will show an error that something went wrong.
Comments
Post a Comment