Flutter BehaviourSubject with StreamBuilder

Viewed 1070

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 ?

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.

Related