A BLoC pattern is design pattern created by Google to seperate the UI from Business logic.
- BLoC as Design Pattern and StateManagement
- Knowing the STATE of app is CRUCIAL
- Presentation Layer & Logic behind it
- Understand easily what's happening inside the app
- More structured code, easier to maintain and test
- Know & understand every state of the app
- Work on a single, stable, popular and effective BLoC codebase
Providing an instance of bloc/cubit to A SINGLE SCREEN is called LOCAL ACCESS
Providing an instance of bloc/cubit to MULTIPLE SCREENs is called ROUTE ACCESS
Navigation with ROUTES: requires
- ROUTE Name
- The associated PAGE/SCREEN
Flutter Routing Options | ||
---|---|---|
Anonymous Routing | Named Routing | Generated Routing |
Routing without Name | Navigation With a Route Name | Navigation With a Route Name |
Only the SCREENS are used to navigate | ROUTES NAMES and their associated SCREENS are set up inside routes parameter of MaterialApp widget | ROUTES NAMES and their associated SCREENS are set up inside a seperate onGenerateRoute function |
Suitable for SMALL applications | Suitable for SMALL-MEDIUM applications | Suitable for LARGE applications |
-
You can NAVIGATE inside Flutter by using
- Anonymous Routing (recmmended for SMALL projects)
- Named Routing (recmmended for MEDIUM projects)
- Generated Routing (recmmended for LARGE projects)
-
The key is to provide a UNIQUE INSTANCE of a bloc/cubit.
-
You SHOULDONT create MULTIPLE INSTANCES of the same bloc/cubit.
-
BlocProvider() CREATES & PROVIDES a NEW INSTANCE of a bloc/cubit.
-
BlocProvider.value() takes an ALREADY CREATED INSTANCE and then PROVIDES it further.
-
You can PROVIDE your cubit/bloc INSTANCES
- LOCALLY-when you want to provide the instance to A SINGLE SCREEN
- SPECIFICALLY-when you want to SPECIFICALLY PROVIDE the instance across one or more SCREENS
- GLOBALLY-when you want to provide the instance ACROSS ALL OF YOUR SCREENS