Stream Builder

The StreamBuilder widget builds itself based on the latest snapshot of interaction with a Stream. This is useful for displaying data that changes over time, such as real-time data from a WebSocket, Firebase, or other streaming sources. The widget automatically rebuilds its child whenever new data is available.

Properties

Property
Description

initialData

The initial data that will be used to create the child widget before any data is received from the stream.

controller

An expression that provides the stream to listen to.

onSuccess

An action to be executed when the stream emits a new value.

onError

An action to be executed when the stream emits an error.


Default Properties

The StreamBuilder widget supports the following section of the Default Properties:

Layout

  • width

  • height

  • padding

  • margin

  • align


Child of StreamBuilder

Slot
Description

child

The widget to be rebuilt whenever the stream emits a new value. The child has access to the streamState (e.g., loading, error, listening, completed) and streamData variables.


Best Practices

  • Use the initialData property to provide a good user experience while the stream is connecting.

  • Use a ConditionalBuilder as the child of the StreamBuilder to display different UI for different stream states (e.g., loading, error, data).

  • Ensure that the stream is properly closed when it is no longer needed to avoid memory leaks.

Last updated