Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR DART

convert future to stream using stream.fromfuture dart

Future<String> futureTask() async {
  await Future.delayed(const Duration(seconds: 5));
  return 'Future complete';
}

final stream = Stream<String>.fromFuture(futureTask());
stream.listen(print,
    onDone: () => print('Done'), onError: print);

// Outputs:
// "Future complete" after 'futureTask' finished.
// "Done" when stream completed.
Source by api.flutter.dev #
 
PREVIOUS NEXT
Tagged: #convert #future #stream #dart
ADD COMMENT
Topic
Name
6+3 =