Closed drogbut closed 3 years ago
Hi @drogbut 👋 Thanks for opening an issue!
As @robsonsilv4 mentioned, BlocProvider
is used to provide a single instance of a bloc or cubit to the widget tree. It handles automatically closing the bloc/cubit when the subtree is unmounted so you don't have to. Similarly, RepositoryProvider
is used to provide a single instance of a repository to the widget tree. I highly recommend reading through the architecture documentation if you haven't already and you can take a look at BlocProvider and RepositoryProvider in action in various examples such as the weather example. Hope that helps!
Closing for now but feel free to comment with any additional questions or join us on discord 👍
The definition is clear but in the implementation with Firebase I have trouble understanding. Indeed the RepositoryProvider could be passed to the bloc in its constructor. To me this seems to be the right approach.
My question is whether the best approach is to pass the Repository into the constructor of the bloc or to wrap the bloc in the Repository?
BlocProvider is used to provide Bloc and Cubit (Stream and State) and RepositoryProvider is used to provide another classes (repositories, data providers and etc), like normal Provider.
My question is whether the best approach is to pass the Repository into the bloc-constructor or to wrap the block in the Repository?
BlocProvider is used to provide Bloc and Cubit (Stream and State) and RepositoryProvider is used to provide another classes (repositories, data providers and etc), like normal Provider.
My question is whether the best approach is to pass the Repository into the bloc-constructor or to wrap the block in the Repository?
@drogbut @felangel Hi) I have the same misunderstanding, which approach is better? Did you find the answer?
BlocProvider is used to provide Bloc and Cubit (Stream and State) and RepositoryProvider is used to provide another classes (repositories, data providers and etc), like normal Provider.
My question is whether the best approach is to pass the Repository into the bloc-constructor or to wrap the block in the Repository?
@drogbut @felangel Hi) I have the same misunderstanding, which approach is better? Did you find the answer?
I recommend providing your repositories to the widget tree using RepositoryProvider
and then injecting the provided instance into the bloc:
BlocProvider(
create: (context) => MyBloc(context.read<MyRepository>()),
child: MyChild(),
)
Hope that helps 👍
BlocProvider is used to provide Bloc and Cubit (Stream and State) and RepositoryProvider is used to provide another classes (repositories, data providers and etc), like normal Provider.
My question is whether the best approach is to pass the Repository into the bloc-constructor or to wrap the block in the Repository?
@drogbut @felangel Hi) I have the same misunderstanding, which approach is better? Did you find the answer?
I recommend providing your repositories to the widget tree using
RepositoryProvider
and then injecting the provided instance into the bloc:BlocProvider( create: (context) => MyBloc(context.read<MyRepository>()), child: MyChild(), )
Hope that helps 👍
Thanks for the answer) I'm ecstatic about your library, awesome features and documentation, thanks)
BlocProvider is used to provide Bloc and Cubit (Stream and State) and RepositoryProvider is used to provide another classes (repositories, data providers and etc), like normal Provider.