When should I use BLoC pattern in Flutter?

Wail Hayaly :

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?

G griffo :

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=175244&siteId=1