TheCattyDev
TheCattyDev

Reputation: 111

Should I use multiple blocs in one page/screen to load different states in Flutter?

I have been learning about Bloc Pattern in Flutter for weeks, but it seems it's a bit difficult when I implement in my real project. For example:

I created a bloc (product_bloc) for loading all products from my server to a Listview. And on the same screen I have a Category Combobox for filter the product in my Listview by category. At this point, I want to load all my categories from server to the Combobox too. Should I create a new bloc (category_bloc) for loading category to Combobox at this point? It means that the state for product and state for category should be different in this case right? What should I do then? For one screen, we can use only one bloc right? Thanks in advance for you help :)

Upvotes: 2

Views: 2601

Answers (1)

LgFranco
LgFranco

Reputation: 1044

In your example, I think that the category it's only a atribute of the product. You don't apear of been manipulating categories but only selecting one to filter your results. In my opinion, you can use it in the same block.

But it's not a problem to use more than one blocs per pages/screens. I use an Authentication and an 'Entity' bloc in all of my Apps that I builded until today.

Upvotes: 4

Related Questions