daily pastebin goal
71%
SHARE
TWEET

Untitled

a guest Jan 24th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import 'dart:async';
  2.  
  3. void main() {
  4.   final data = {'イチゴ': '苺', 'イチジク': '無花果'};
  5.  
  6.   //Sink
  7.   final controller = StreamController<String>();
  8.   //Stream
  9.   //rxdartというライブラリをimportして、
  10.   //BehaviorSubjectを用いることが多いです。
  11.   final kanjiStream = StreamController<String>();
  12.  
  13.   transformToKanjiFrom(String katakana) {
  14.     if (data.containsKey(katakana)) {
  15.       kanjiStream.add(data[katakana]);
  16.       return;
  17.     }
  18.     print('${katakana}の漢字は不明です');
  19.   }
  20.  
  21.     //FlutterではView部分に相当します。
  22.   //StreamBuilderなどのStreamを監視するWidgetを使います。
  23.   kanjiStream.stream.listen((kanji) {
  24.     print(kanji);
  25.   });
  26.  
  27.   controller.stream.listen(transformToKanjiFrom);
  28.  
  29.   controller.sink.add('イチゴ');
  30.   controller.sink.add('ドラゴンフルーツ');
  31.   controller.sink.add('イチジク');
  32. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top