applyProgress property

Stream<PatchApplyProgress> get applyProgress

Broadcast progress stream for applyPatch.

Subscribe before calling applyPatch to receive downloading, verifying, and finalizing events. Unsupported platforms return an empty stream.

Implementation

static Stream<PatchApplyProgress> get applyProgress {
  if (_unsupportedGuard('applyProgress')) return const Stream.empty();
  return _progressStream ??= () {
    final subscriptions = <StreamSubscription<PatchApplyProgress>>[];
    late final StreamController<PatchApplyProgress> merged;
    merged = StreamController<PatchApplyProgress>.broadcast(
      onListen: () {
        subscriptions
          ..add(_downloads.stream.listen(merged.add))
          ..add(
            _eventChannel
                .receiveBroadcastStream()
                .map((raw) => PatchApplyProgress.fromNative(raw))
                .listen(merged.add, onError: merged.addError),
          );
      },
      onCancel: () {
        for (final subscription in subscriptions) {
          subscription.cancel();
        }
        subscriptions.clear();
      },
    );
    return merged.stream;
  }();
}