Skip to content

Instantly share code, notes, and snippets.

@DrBeta

DrBeta/main.dart

Last active May 15, 2019
Embed
What would you like to do?
Stream Example
import 'dart:async';
class Cake {}
class Order {
String type;
Order(this.type);
}
void main() {
final controller = StreamController();
final order = new Order('chocolate');
final baker = new StreamTransformer.fromHandlers(
handleData: (cakeType, sink) {
if (cakeType == 'chocolate') {
sink.add(new Cake());
} else {
sink.addError('I cant bake that type');
}
}
);
controller.sink.add(order);
controller.stream.map((order) => order.type).transform(baker).listen(
(cake) => print('Heres your cake $cake'),
onError: (err) => print(err));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment