Bloc: Passing a Blocs state to another Bloc

Created on 5 May 2020  路  3Comments  路  Source: felangel/bloc

Building from your Firebase Login example, I am trying to include a reset password page that on failure returns you back to the login screen that then shows a snack bar saying "Reset Failed"

how do you pass state from one Bloc to another

question

Most helpful comment

Thanks Guys. will give it a try 馃憤

All 3 comments

Maybe you could use BlocListener to listen to the bloc state change in reset password page. If the state if failure for reset password, then you could navigate it back to the login page. In the navigation you could pop screen with argument Navigator.pop(context, 'Reset Failed');

Hi @kieronwiehahn 馃憢
Thanks for opening an issue!

You can handle bloc-to-bloc communication either by directly injecting blocA into blocB as described here or by using a BlocListener as @masfranzhuo mentioned to subscribe to blocA and notify blocB like:

BlocListener<BlocA, StateA>(
  listener: (context, state) {
    // notify `BlocB` in response to changes in `BlocA`
    context.bloc<BlocB>().add(...);
  },
  child: ...
)

Hope that helps 馃憤

Thanks Guys. will give it a try 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

krusek picture krusek  路  3Comments

ricktotec picture ricktotec  路  3Comments

clicksocial picture clicksocial  路  3Comments

shawnchan2014 picture shawnchan2014  路  3Comments

1AlexFix1 picture 1AlexFix1  路  3Comments