useStream<T> function

AsyncSnapshot<T> useStream<T>(
  1. Stream<T>? stream, {
  2. T? initialData,
  3. bool preserveState = true,
})

Subscribes to a Stream and returns its current state as an AsyncSnapshot.

  • preserveState determines if the current value should be preserved when changing the Stream instance.

When preserveState is true (the default) update jank is reduced when switching streams, but this may result in inconsistent state when using multiple or nested streams. See https://github.com/rrousselGit/flutter_hooks/issues/312 for more context.

See also:

Implementation

AsyncSnapshot<T> useStream<T>(
  Stream<T>? stream, {
  T? initialData,
  bool preserveState = true,
}) {
  return use(
    _StreamHook(
      stream,
      initialData: initialData,
      preserveState: preserveState,
    ),
  );
}