'How to retrieve the value of a listener passed to a Stream?

Stream<int> get ints async* {
  yield 100;
}
  
Future<int> foo(int i) async {
  print(i);
  return 0;
}
  
void main() {
  final subscription = ints.listen(foo);

  // I thought something like this could work...
  subscription.asFuture().then((value) => print('value = $value')); 
}

How can I retrieve the value of foo function (i.e. 0) from the StreamSubscription instance?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source