3

I'm using BehaviorSubject and it's emitting back last item on subscription as expected. However, sometimes, data is not changed and and with new listen event will be triggered back with last emitted item.

Would be nice to use distinct to remove duplicated data. However on new listen event stream recreated and doesn't have history. Besides that last item. Any sane solution to handle such situation? To summarize, how we can keep using BehaviorSubject, but filter/distinct last item?

GensaGames
  • 5,538
  • 4
  • 24
  • 53

2 Answers2

1
final _subject = BehaviorSubject<String>();
get Stream<String> distinctSubject => _subject.stream.distinct();

and you probably shouldn't do listen() too often either

Benoit Jadinon
  • 1,082
  • 11
  • 21
1

Create subsclass of BehaviourSubject and override add method, so you could store all added items in set variable and check for _set.containts(newItem);

Alexander Farkas
  • 529
  • 3
  • 11