What the need for get_it in Bloc implementation as we are already using BLOC Provider for dependency injection ?
I'm currently using bloc provider for Dependency Injection and how get_it package was useful over Bloc Provider ? Needs clarification
What the need for get_it in Bloc implementation as we are already using BLOC Provider for dependency injection ?
I'm currently using bloc provider for Dependency Injection and how get_it package was useful over Bloc Provider ? Needs clarification
Copyright © 2021 Jogjafile Inc.
get_it
will be useful when you use it to register Repository, DB, API Client instance, UseCases,..Maybe your question is creating a bloc using
get_it
likeregisterFactory<FooBloc>()
. If your question is like that:get_it
will help create a block instance based on the dependencies you registered previously, it will help you not have to code a lot if that block is provided in many places. Finally, you still have to useBlocProvider
to provide blocks down the widget tree. You must useBlocProvider
because Bloc will live in the widget lifecycle and its context, so it will be easy to manage the initialization or closure of the Bloc via Widget.If use
get_it
:If not use
get_it
If your
FooBloc
has dependences:When using
get_it
, you register Bloc first:and provide it via
BlocProvider
and other places you want to provide:In case if you not use
get_it
:You will need to do the same if you want to provide to other place.
Hope my explanation will resolve your question. Happy coding <3