something like tail -f

import 'dart:async';
import 'dart:convert';
import 'dart:io';

void main() {
  File observedFile = File("/tmp/access.log");
  String lastline = "";
  const int modify = 1 << 1;
  observedFile.watch(events: modify).listen((event) {
    utf8.decoder.bind(File('/tmp/access.log').openRead()).listen((event) {
      var lines = LineSplitter().convert(event);
      if (lines.last != lastline) {
        print(lines.last);
        lastline = lines.last;
      }
    });
  });
}

Note: ut8.decoder.bind is a method of ut8.decoder that takes a Stream<List<int>> and converts it into a Stream<String>. I find it noteworthy that a single event of this stream is the retrieval of a List which actually stands for the entire file.

To get the long ass Stream<List<int>>, we use the File class's openRead method. File('/tmp/access.log').openRead().

Once bind converts the Stream<List<int>> into Stream<String> we the listen method on the stream


Comments