When should I use BLoC pattern in Flutter?
Whenever you start looking into architectures for Flutter there’s no way around the BLoC pattern, but how does it work and how do we implement it?
BLoC stands for Business Logic Component and is one of the more popular approaches when it comes to architectures in Flutter. By placing a BLoC between our screen and data layer it gives us the possibility to pass data between our repositories and widgets and update the UI whenever data changes, without having to manually update the state. Coming from Android it actually has some similarities with the ViewModel & LiveData structure we use in native development.
read more here
Wail Hayaly
Updated on December 18, 2022Comments
-
Wail Hayaly over 1 year
I've recently read about BLoC (Business Logic Component), and I'm building an app to retrieve data from api, I'm wondering when should I create a bloc and when I shouldn't, using the
Flutter_BLoC
package, it seems like I have to create a bloc for every screen am I right? -
Wail Hayaly about 4 yearsI understand the main procedure of doing this, but in my case, I have many screens and each screen has many widgets and one future builder, how can I integrate this?
-
griffins about 4 yearsyou can use bloc to load/listen to data changes .
-
Wail Hayaly about 4 yearsSo you mean bloc for every component or widget on the screen
-
griffins about 4 yearssomething like that.But mainly use it for widgets or screens that require to change state or update
-
Ray over 3 yearscan you explain what "repositories" mean in the sentence "pass data between our repositories and widgets". did you mean repositories=bloc? @griffins
-
griffins over 3 yearsi hvae updated my answer with an image read more in detail here medium.com/flutterpub/…
-
Sanjayrajsinh about 2 yearsWe should use GetX