5

仲間のダーツプログラマー。

以下のように Stream を使用してファイルを読み込んでいます。

Stream<List<int>> stream = new File(filepath).openRead();
stream
    .transform(UTF8.decoder)
    .transform(const LineSpilitter())
    .listen((line){
        // TODO: check if this is the last line of the file
        var isLastLine;
    });

listen() の行がファイルの最後の行かどうかを確認したい。

4

2 に答える 2

6

現在のデータのチャンクが最後のチャンクかどうかを確認できるとは思いません。
ストリームが閉じられたときに呼び出されるコールバックのみを渡すことができます。

Stream<List<int>> stream = new File('main.dart').openRead();
  stream.
  .transform(UTF8.decoder)
  .transform(const LineSpilitter())
  .listen((line) {
// TODO: check if this is the last line of the file
    var isLastLine;
  }
  ,onDone: (x) => print('done')); // <= add a second callback
于 2014-10-02T05:12:54.113 に答える