Skip to content

Instantly share code, notes, and snippets.

@bhavikvashi1804
Created September 9, 2020 04:08
Show Gist options
  • Save bhavikvashi1804/bb900d893830622d17c4c5a253cb619f to your computer and use it in GitHub Desktop.
Save bhavikvashi1804/bb900d893830622d17c4c5a253cb619f 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 order1=new Order('Chocolate');
//change the Order type to 'Banana Cake'
final baker=new StreamTransformer.fromHandlers(
handleData:(cakeType,sink){
if(cakeType=='Chocolate'){
sink.add(new Cake());
}else{
sink.addError('I can not bake that type');
}
}
);
controller.sink.add(order1);
controller.stream
.map((order)=>order.type)
.transform(baker)
.listen(
(cake)=>print('Here is your cake: $cake'),
onError: (error)=>print(error),
);
}
@bhavikvashi1804
Copy link
Author

This is Cake Factory: understanding of Streams in Dart

Annotation 2020-09-09 094246

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment