StreamWorker<T> constructor

const StreamWorker<T>({
  1. Key? key,
  2. required Stream<T> stream,
  3. required Widget builder(
    1. BuildContext context,
    2. T data
    ),
  4. bool isProd = false,
  5. T? initialData,
  6. Widget emptyBuilder(
    1. BuildContext context
    )?,
  7. Widget errorBuilder(
    1. BuildContext context,
    2. Object? error
    )?,
  8. Widget loadingBuilder(
    1. BuildContext context
    )?,
})

Creates a StreamWorker that listens to the provided stream and builds the user interface according to its state.

  • stream: The data stream to listen to. The stream subscription is automatically managed by StreamBuilder - it will be cancelled when the widget is disposed. For StreamController instances, ensure proper cleanup by closing them when done.
  • builder: Called when non-null data is available.
  • isProd: Production mode flag. When true, hides the default empty state widget (shows nothing instead of OptionEmpty) when data is null. Useful for production environments where empty states should be minimal. Default: false.
  • initialData: Optional initial snapshot value used while awaiting the first event.
  • emptyBuilder: Builder used when the data is null or empty.
  • errorBuilder: Builder used when an error occurs.
  • loadingBuilder: Builder used while the stream is loading.

Implementation

const StreamWorker({
  super.key,
  required this.stream,
  required this.builder,
  this.isProd = false,
  this.initialData,
  this.emptyBuilder,
  this.errorBuilder,
  this.loadingBuilder,
});