Last active
August 2, 2018 00:34
-
-
Save ThinkDigitalSoftware/83af99287bab0f59d6b002fbd0ff54e0 to your computer and use it in GitHub Desktop.
StreamExample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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