0

I am creating a flutter application with clean archetecture with bloc as state management solution and object box as local datastore,object-box has a feature of stream which emits when ever there is a data change I want to listen it in multiple places in the screen using same bloc I am getting error "Stream has already been listened to" if I try to listen it multiple places .I can use stream.asBroadcast() but It will miss data totally if the screen is not listening at the exact time of emitting or if the widget rebuilds due to something it will still loose it so Anyone have better approch or know a solution please share.

I tried StreamTransformer to transform DB entity into Model and create it inside DbHelper class and expose this in domain layer that will be passed on to presentation layer using bloc states.

I have already followed this question Streaming data from local ObjectBox (or Hive) database in a Clean Architecture Style But when I use same stream in multiple places I get the error.

Bibek Saha
  • 134
  • 1
  • 7
  • The Stream returned by watch() is a single-subscription stream, see [the method docs](https://pub.dev/documentation/objectbox/latest/objectbox/QueryBuilder/watch.html) and [the Dart docs](https://dart.dev/tutorials/language/streams#two-kinds-of-streams) about this. – Uwe - ObjectBox May 22 '23 at 06:02

0 Answers0