Skip to content

Instantly share code, notes, and snippets.

@ThinkDigitalSoftware
Last active August 2, 2018 00:34
Show Gist options
  • Save ThinkDigitalSoftware/83af99287bab0f59d6b002fbd0ff54e0 to your computer and use it in GitHub Desktop.
Save ThinkDigitalSoftware/83af99287bab0f59d6b002fbd0ff54e0 to your computer and use it in GitHub Desktop.
StreamExample
import 'dart:async';
void main() {
int count = 0;
var counterController = new StreamController();
counterController.stream.listen((value) => print(value));
void increment() {
counterController.add(count++);
}
final transformToString =
new StreamTransformer.fromHandlers(handleData: (number, sink) {
if (number.runtimeType == int) {
sink.add("The counter is at $number!");
} else {
sink.addError("$number is not an int!");
}
});
counterController.stream.map((input) => input).transform(transformToString);
for(int i=0; i < 10; i++){
increment();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment