Skip to content

Instantly share code, notes, and snippets.

@AlexKenbo
Created March 9, 2020 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexKenbo/beb9f8f40a144fb523b01947be01f5d2 to your computer and use it in GitHub Desktop.
Save AlexKenbo/beb9f8f40a144fb523b01947be01f5d2 to your computer and use it in GitHub Desktop.
Stream method toList()
// asynchronous data
main() async {
Duration interval = Duration(seconds: 1);
Stream<int> stream = Stream<int>.periodic(interval,transform);
stream = stream.take(5);
List<int> data = await stream.toList();
for(int i in data){
print(i);
}
}
int transform(int x){
return (x + 1) * 2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment