Skip to content

Instantly share code, notes, and snippets.

@mannuelf
Created July 18, 2022 08:11
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 mannuelf/4f12c2966c7d5b1a704f5a0c529b96e5 to your computer and use it in GitHub Desktop.
Save mannuelf/4f12c2966c7d5b1a704f5a0c529b96e5 to your computer and use it in GitHub Desktop.
reactive-dart
import 'dart:async';
void main() {
String chosenCake = 'chocolate';
// Stream Controller
final controller = StreamController();
final order = Order(chosenCake);
final baker = StreamTransformer.fromHandlers(handleData: (cakeType, sink) {
if (cakeType == 'chocolate') {
sink.add(Cake());
} else {
sink.addError('Sorry I cannot bake that');
}
});
controller.sink.add(order);
controller.stream.map((order) => order.type).transform(baker).listen(
(cake) => print('here is the $cake'),
onError: (err) => print(err));
}
class Cake {}
class Order {
String type;
Order(this.type);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment