When should I use BLoC pattern in Flutter?

3,520

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.

img

read more here

Share:
3,520
Wail Hayaly
Author by

Wail Hayaly

Updated on December 18, 2022

Comments

  • Wail Hayaly
    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
    Wail Hayaly about 4 years
    I 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
    griffins about 4 years
    you can use bloc to load/listen to data changes .
  • Wail Hayaly
    Wail Hayaly about 4 years
    So you mean bloc for every component or widget on the screen
  • griffins
    griffins about 4 years
    something like that.But mainly use it for widgets or screens that require to change state or update
  • Ray
    Ray over 3 years
    can you explain what "repositories" mean in the sentence "pass data between our repositories and widgets". did you mean repositories=bloc? @griffins
  • griffins
    griffins over 3 years
    i hvae updated my answer with an image read more in detail here medium.com/flutterpub/…
  • Sanjayrajsinh
    Sanjayrajsinh about 2 years
    We should use GetX