Skip to content

Instantly share code, notes, and snippets.

@wyattbiker
Created May 12, 2019 01:46
Show Gist options
  • Save wyattbiker/9c475329f25f6be533ae824fcc149a23 to your computer and use it in GitHub Desktop.
Save wyattbiker/9c475329f25f6be533ae824fcc149a23 to your computer and use it in GitHub Desktop.
Stream example
// asynchronous data
main() async {
// Duration interval = Duration(seconds: 1);
// Stream<int> stream = Stream<int>.periodic(interval, callback);
// List l=[1,2,1,2,3,4,5,6];
// Stream stream = Stream.fromIterable(l);
Map<dynamic, int> map = {1: 1, 'a': 10, 'b': 20, 3: 2, 4: 4, 6: 5};
Stream stream = Stream.fromIterable(map.entries);
await stream
.where((i) => i.key.runtimeType == int)
// .takeWhile((i) => i.runtimeType == String)
.listen((i) => print(i.value))
.onDone(() => print("done"));
print("Running");
// await for(int i in stream){
// print(i);
// }
}
// This callback modify the given value to even number.
int callback(int value) {
return (value + 1) * 2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment