Bloc: Blocs communication with each other

Created on 8 Oct 2020  路  3Comments  路  Source: felangel/bloc

Hello! In Todos example we have two blocs witch are communicate with each other: FilteredTodosBloc and TodosBloc.
This is a part of code in main.dart file witch create dependencies:

BlocProvider<FilteredTodosBloc>( 
create: (context) => FilteredTodosBloc( 
todosBloc: BlocProvider.of<TodosBloc>(context), 
 ), 
 ), 

How to create dependencies if i use get_it package? Because this method does not work:
BlocProvider<FilteredTodosBloc>(create: (context) => getIt<FilteredTodosBloc>()),

dependency question

Most helpful comment

Hi @popay34 馃憢
Thanks for opening an issue!

That should work as long as you've registered both blocs properly like:

getIt.registerSingleton<TodosBloc>(TodosBloc());
getIt.registerSingleton<FilteredTodosBloc>(FilteredTodosBloc(getIt<TodosBloc>()));

Hope that helps 馃憤

All 3 comments

The same doubt

Hi @popay34 馃憢
Thanks for opening an issue!

That should work as long as you've registered both blocs properly like:

getIt.registerSingleton<TodosBloc>(TodosBloc());
getIt.registerSingleton<FilteredTodosBloc>(FilteredTodosBloc(getIt<TodosBloc>()));

Hope that helps 馃憤

Closing for now but feel free to comment if you have additional questions and I'm happy to continue the conversation 馃憤

Was this page helpful?
0 / 5 - 0 ratings