ntminhdn / Flutter-Bloc-CleanArchitecture

457 stars 200 forks source link

Bloc to bloc communication #37

Closed saswattech9 closed 3 months ago

saswattech9 commented 9 months ago

With this architecture how to communicate between blocs .

Please someone explain with small example.

saswattech9 commented 9 months ago

anyone can help me out ?

hungtrn75 commented 9 months ago

I think u can use depend bloc as a param in constructor. i.e: bloc A depend on bloc B: A(B b) or u can create a global bloc

saswattech9 commented 9 months ago

Global would not be a good option. So what you telling could you give us some example ?

hungtrn75 commented 9 months ago

Ex: I have a A bloc depends on B, C bloc

ABloc extends BaseBloc<> {
  late final B bBloc;
  late final C cBloc;
}

u can overide in ur page

class _PageState extends BasePageState<Page, ABloc> {
  @override
  late final ABloc bloc = super.bloc
    ..bBloc = B()
    ..cBloc = C();

or init b,c instance in initState()

bloc
  ..bBloc = B()
  ..cBloc = C();