2

I am looking for an alternative of BehaviorSubject from RxDart in Native Dart Streams. To be more particular: I want to get the previously added value to the Stream when I listen to.

Example flow: 1 -> 2 -> 3 -> * -> 4 -> 5 ...

* is point when I started to listed. In BehaviorSubject I get 3 when I start to listen. But with StreamController the first value I get is 4.

Rza İsmayıl
  • 370
  • 1
  • 2
  • 7

1 Answers1

1

I'm not an expert by any means, but it seems that a standard dart:async StreamController is the same as a BehaviourSubject with the exception of remembering one item. So the native dart way would be to subclass StreamController and override the add function to store the item and onListen to emit the stored item.

  • Yes, initially this was the solution I has in my mind, but I wanted a ready to go way of doing it. If these is no direct alternative of BehaviourSubject in dart:async I will go with RxDart. Thanks! – Rza İsmayıl Mar 11 '23 at 17:56