Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter BehaviourSubject with StreamBuilder

Tags:

flutter

dart

Using a stream builder with its stream set to a BehaviourSubject's stream, whenever the parent widget is rebuilt and the builder function of the streamBuilder is invoked, the snapshot connection state is waiting ,and despite having previous data in the stream the snapshot has no data.. Then immediately the builder is invoked again with active connection and the snapshot has latest value..

Shouldn't the latest value in the BehaviourSubject's stream be accessible in the first time ?

like image 441
Omar Farrag Avatar asked Oct 19 '25 14:10

Omar Farrag


1 Answers

No, the stream values are always asynchronous so StreamBuilder always passes through a waiting state. You can mitigate this behavior by setting its initialData to the stream's value property.

like image 135
Jacob Phillips Avatar answered Oct 22 '25 03:10

Jacob Phillips



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!