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_itwill be useful when you use it to register Repository, DB, API Client instance, UseCases,..Maybe your question is creating a bloc using
get_itlikeregisterFactory<FooBloc>(). If your question is like that:get_itwill 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 useBlocProviderto provide blocks down the widget tree. You must useBlocProviderbecause 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_itIf your
FooBlochas dependences:When using
get_it, you register Bloc first:and provide it via
BlocProviderand 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