2

what is the difference here first yield push our status to the stream and what does the second yield* do?

final _controller = StreamController<AuthenticationStatus>(); 
  Stream<AuthenticationStatus> get status async* {
    await Future<void>.delayed(const Duration(seconds: 1));
    yield AuthenticationStatus.unauthenticated;
    yield* _controller.stream;
    
  }

what would be the difference between yield AuthenticationStatus.unauthenticated; and _controller.add(AuthenticationStatus.unauthenticated)?

i can’t understand why we need to yield* controller.stream and what difference it makes

  • The first `yield` emits a single value. The second `yield*` then emits all of the elements of the other stream as they are generated. So `status` returns a stream of all the values of the controller stream, *prefixed* by `unauthenticated`. – Richard Heap Apr 05 '22 at 12:30

0 Answers0