connectToStream method

void connectToStream(
  1. Stream<ProgressUpdate> stream
)

Connects to a stream for real-time progress updates Useful for gRPC streaming or other async sources

Implementation

void connectToStream(Stream<ProgressUpdate> stream) {
  _cancelStreamSubscription();
  _streamSubscription = stream.listen(
    (update) {
      if (update.title != null) updateTitle(update.title!);
      if (update.subtitle != null) updateSubtitle(update.subtitle!);
      if (update.progress != null) updateProgress(update.progress);
      if (update.isCompleted) complete(message: update.subtitle);
      if (update.hasError) setError(update.errorMessage ?? 'Unknown error');
    },
    onError: (error) {
      setError(error.toString());
    },
    onDone: () {
      if (!hasError.value && !isCompleted.value) {
        complete();
      }
    },
  );
}