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?
When should I use BLoC pattern in Flutter?
Not for every screen, but every components that would hold any state changes. –
Durga
bloc seems like old school Flutter. Package provider is what the Flutter cookbook recommends. –
Intermittent
@TedHenry Can you please explain more. –
Saccharate
Like I have a homepage, should I create something like hompage_bloc? or I should create Pageview_bloc, Recommended_bloc ... etc –
Saccharate
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
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? –
Saccharate
you can use bloc to load/listen to data changes . –
Bufford
So you mean bloc for every component or widget on the screen –
Saccharate
something like that.But mainly use it for widgets or screens that require to change state or update –
Bufford
can you explain what "repositories" mean in the sentence "pass data between our repositories and widgets". did you mean repositories=bloc? @Bufford –
Urogenital
i hvae updated my answer with an image read more in detail here medium.com/flutterpub/… –
Bufford
We should use GetX –
Indolence
Repositories handle loading or storing data (think your rest services). Bloc's hold business logic. –
Phylissphyll
© 2022 - 2024 — McMap. All rights reserved.