But then multiple Blocs sharing the same repository instance should know when other Bloc triggers data change to get the update, hence making repository works like Bloc (listen to events, update the state, notify listeners, etc.). Data change should all be handled by the repository as that is the source of truth now. So Bloc state will only be used for UI data (flagging etc.) and showing only parts of data required for the UI. Probably another way to make use of RepositoryProvider is if we move the state data from Bloc to the repository. ![]() So instantiating the same repository in different Bloc instantiations won't do any harm and render RepositoryProvider useless. But often my repository is just a bunch of methods handling API calls and data mapping, without any state/field being kept inside that class. ![]() ![]() So basically RepositoryProvider will be used only when the repository is required by multiple Blocs, else you just instantiate the repository directly when instantiating the Bloc.
0 Comments
Leave a Reply. |