Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Waiting for multiple blocs #762

Closed
payam-zahedi opened this issue Jan 4, 2020 · 6 comments
Closed

Waiting for multiple blocs #762

payam-zahedi opened this issue Jan 4, 2020 · 6 comments
Assignees
Labels
question Further information is requested
Projects

Comments

@payam-zahedi
Copy link

Hi @felangel , thanks for this awesome library.
I have the below situation:
imagine I have a Splash screen that waited for cart bloc and the favorite bloc.

  • cart bloc is for taking user cart information.
  • and the favorite bloc is about getting user favorite products.

I just want to get the cart information and the favorite products and if everything was ok push the user to the next screen. if some error received I want to show error and retry button.

I think MultiBlocBuilder would be great for this situation. but there is no MultiBlocBuilder.

can u give me a solution for that?

@felangel
Copy link
Owner

felangel commented Jan 5, 2020

Hi @payam-zahedi 👋
Thanks for opening an issue!

Regarding MultiBlocBuilder, there was an issue for it and after multiple discussions we decided not to include it.

In your case you have several options:

  • Nest BlocBuilders
  • Create a new bloc which combines states from the other two
  • Combine the states of the blocs using combineLatest and use a StreamBuilder to handle building the UI.

Hope that helps 👍

@felangel felangel closed this as completed Jan 5, 2020
@felangel felangel self-assigned this Jan 5, 2020
@felangel felangel added the question Further information is requested label Jan 5, 2020
@felangel felangel added this to To do in bloc via automation Jan 5, 2020
@felangel felangel moved this from To do to Done in bloc Jan 5, 2020
@payam-zahedi
Copy link
Author

dear @felangel , thanks for your useful response.
if you have any resource or tutorial link, it would be very helpful for me.
thanks

@urusai88
Copy link

  • Create a new bloc which combines states from the other two
  • Combine the states of the blocs using combineLatest and use a StreamBuilder to handle building the UI.

Can we have some examples please?

@felangel
Copy link
Owner

@urusai88 I've created a sample gist. Please let me know if that helps 👍

@urusai88
Copy link

urusai88 commented Feb 15, 2020

@felangel thanks you very much! It is what we need i think.
Can you also provide some examples for it please?:

Create a new bloc which combines states from the other two

@felangel
Copy link
Owner

@urusai88 no problem here's a sample gist which shows how you can composed streams within a bloc. In this case it's obviously a bit weird because the bloc is just a proxy but normally you'd execute some sort of logic/processing on the data from the streams and output a normalized view model for the UI to consume.

Hope that helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
bloc
  
Done
Development

No branches or pull requests

3 participants