In my flutter application I have a bloc. It not only sends data with a BehaviorSubject, but also exceptions (per stream.addError()), which I want to handle in the "front-end" by showing certain error messages to the user.
Let's say this is the bloc output:
Now if I listen to the Stream after Output 3 was added then I will only receive Output 2 and know nothing about Output 3 (the Exception). In the case of my app Output 2 would reflect an old state and might confuse users.
My way of thinking was that the BehaviorSubject would emit the last Output to any new listener disregarding if it is a "normal" value or an Exception. So in this example Output 3 instead of Output 2.
Is this intended? If yes I think it should be stated in the documentation.
I tried solving it with a different BehaviorSubject emitting Exceptions and having 2 StreamBuilder, first checking the Exception stream.
This is obviously not a really nice solution.
Ah, our BehaviorSubject does what a regular broadcast stream does in this case,
That doesn't mean we can't implement this though. Seems that with Flutter, a lot of people do prefer the rx way over the Dart way, which is an on going struggle ;)
Would be pretty nice!
I'm just asking myself if I'm doing something fundamentally wrong, as this is something I guess many people would face when using the bloc-pattern.
But I don't know any other "clean" way I could handle this.
Fixed in master, soon on pub
Thank you very much! :)
Most helpful comment
Ah, our BehaviorSubject does what a regular broadcast stream does in this case,
That doesn't mean we can't implement this though. Seems that with Flutter, a lot of people do prefer the rx way over the Dart way, which is an on going struggle ;)