asStream method
Creates a Stream containing the result of this future.
The stream will produce single data or error event containing the completion result of this future, and then it will close with a done event.
If the future never completes, the stream will not produce any events.
Implementation
@override
Stream<T> asStream() {
final controller = StreamController<T>.broadcast();
then((value) {
controller.add(value);
}).catchError((Object error, StackTrace stack) {
controller.addError(error, stack);
}).whenComplete(() {
controller.close();
});
return controller.stream;
}