Skip to content

Instantly share code, notes, and snippets.

@dario-valles
Created April 7, 2020 09:34
Show Gist options
  • Save dario-valles/facf9d0c3bb05e33e23bfaded6a0dc8c to your computer and use it in GitHub Desktop.
Save dario-valles/facf9d0c3bb05e33e23bfaded6a0dc8c to your computer and use it in GitHub Desktop.
import 'dart:async';
class Cake {}
class Order {
String type;
Order(this.type);
}
void main() {
final controller = new StreamController();
final order = new Order('chocolate');
final baker =
new StreamTransformer.fromHandlers(handleData: (cakeType, sink) {
if (cakeType == 'chocolate') {
sink.add(new Cake());
} else {
sink.addError('This is not chcolate');
}
});
controller.sink.add(order);
controller.stream.map((order) => order.type).transform(baker).listen(
(cake) => print('Here yor cake $cake'),
onError: (err) => print(err));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment