Skip to content

Instantly share code, notes, and snippets.

@meki
Created October 17, 2021 06:19
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 meki/89be289fe87784a9d6bc73256920eb30 to your computer and use it in GitHub Desktop.
Save meki/89be289fe87784a9d6bc73256920eb30 to your computer and use it in GitHub Desktop.
BLoK example
// forked from https://qiita.com/kabochapo/items/8738223894fb74f952d3
import 'dart:async';
void main() {
final data = {'イチゴ': '苺', 'イチジク': '無花果', 'リンゴ': '林檎'};
final controller = StreamController<String>();
controller.sink.add('イチゴ');
controller.sink.add('ドラゴンフルーツ');
controller.sink.add('イチジク');
controller.sink.add('リンゴ');
controller.sink.add('オレンジ');
final toKanji = StreamTransformer<String, String>.fromHandlers(
handleData: (value, sink) {
if (data.containsKey(value) && (data[value] != null)) {
sink.add(data[value]!);
} else {
sink.addError('$value の漢字は不明です');
}
}
);
controller.stream
.transform(toKanji)
.listen(
(value) { print(value); },
onError: (err) { print('[エラー] $err'); }
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment