Bloc: is it possible to yield state of Bloc from another bloc?

Created on 12 Aug 2020  路  2Comments  路  Source: felangel/bloc

I have scenarios where I want to yield state of bloc1 in bloc2 e.g I have searchBloc and ProductsBloc so I want to yield ProductsLoaded state from SearchBloc and give result of the search (ProductsLoaded(products) like that) is there a way to do that?

question

Most helpful comment

Hi @EngAddow 馃憢

You can achieve that by adding an event to your ProductsBloc with the result of the search as payload.
You can then handle this event, grab your products from the event's payload and yield ProductsLoaded(products).

@RollyPeres Thank you very much this was very helpful and I did as u said
I waited the search loaded state in the UI and fired the GetSearchResults and gave the search results then handled in the ProductBloc.

All 2 comments

Hi @EngAddow 馃憢

You can achieve that by adding an event to your ProductsBloc with the result of the search as payload.
You can then handle this event, grab your products from the event's payload and yield ProductsLoaded(products).

Hi @EngAddow 馃憢

You can achieve that by adding an event to your ProductsBloc with the result of the search as payload.
You can then handle this event, grab your products from the event's payload and yield ProductsLoaded(products).

@RollyPeres Thank you very much this was very helpful and I did as u said
I waited the search loaded state in the UI and fired the GetSearchResults and gave the search results then handled in the ProductBloc.

Was this page helpful?
0 / 5 - 0 ratings