Skip to content

Instantly share code, notes, and snippets.

@Quingsley
Last active August 17, 2022 07:51
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 Quingsley/c06bc8d812b72d2672211fd11b922b60 to your computer and use it in GitHub Desktop.
Save Quingsley/c06bc8d812b72d2672211fd11b922b60 to your computer and use it in GitHub Desktop.
streams
import 'dart:async';
void main() {
final controller = StreamController();
final order = Order('chocolate');
final baker = StreamTransformer.fromHandlers(
handleData:(cakeType,sink){
if(cakeType == 'chocolate'){
sink.add(Cake());
}else {
sink.addError('I can\'t process this type');
}
}
);
controller.sink.add(order);
controller.stream.map(
(order) => order.type
).transform(baker)
.listen(
(cake) => print('Here is your cake, $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