Skip to main content

Signatures

Two streaming methods, matching the two non-streaming ones:

With a subscription

listen gives you onError and onDone separately, which is usually what a widget wants:

Cancelling

Cancel the subscription:
Or call the namespace-level cancel:
Always cancel in dispose, or the generation keeps running after the widget is gone and setState throws.

Driving a widget with StreamBuilder

Rebuilding the whole subtree on every token is expensive. For long outputs, accumulate into a ValueNotifier and rebuild only the Text widget.

Errors

Failures arrive through the stream’s error channel, so onError on a subscription, or a try/catch around the await for: