![]() Then here I set the reference from the BLoC A to a stream of the BLoC B where I want to send the data. ![]() Hello, I had this need in one application I made and I ended up to use this strategy: I made a BLoC container class where I've instantiated the BLoCs of the two screen. NumComplete = repository.todos().map((todos) => todos.fold(0, (total, todo) => plete ? total++ : total ĪddTodoBloc(this.todosRepository, erRepository) įinal user = await // Perform some example "Business Rules" validation here before adding the Todo to the repo If two Blocs need to know the current Todos, they would both both take the `TodosRepository` in as a constructor parameter and listen / transform the Stream of Todos! whether they're in Firebase or a Local DB or an in-memory cache or mixing these things)! The Blocs shouldn't care about the storage mechanism. It is also responsible for how the todos are stored (e.g. The `TodosRepository` provides methods like `Stream todos()`. I might have things like a `UserRepository` and a `TodoRepository` for example. I usually call my data sources "Repositories" in my codebase. ![]() IMO, this is where Clean Architecture layers really help: I generally don't send data between Blocs, but rather the two blocs share a Data Source (e.g. ![]() I need to know if is there a recommend way to share data between blocs? (pass through constructor doesn't a good practice).
0 Comments
Leave a Reply. |