watch method - FileSystemEntity class - dart:io library (original) (raw)

Stream<FileSystemEvent> watch({

  1. int events = FileSystemEvent.all,
  2. bool recursive = false, })

Start watching the FileSystemEntity for changes.

The implementation uses platform-dependent event-based APIs for receiving file-system notifications, thus behavior depends on the platform.

The system will start listening for events once the returned Stream is being listened to, not when the call to watch is issued.

The returned value is an endless broadcast Stream, that only stops when one of the following happens:

Use events to specify what events to listen for. The constants inFileSystemEvent can be or'ed together to mix events. Default isFileSystemEvent.all.

A move event may be reported as separate delete and create events.

Implementation

Stream<FileSystemEvent> watch({
  int events = FileSystemEvent.all,
  bool recursive = false,
}) {
  // FIXME(bkonyi): find a way to do this using the raw path.
  final String trimmedPath = _trimTrailingPathSeparators(path);
  final IOOverrides? overrides = IOOverrides.current;
  if (overrides == null) {
    return _FileSystemWatcher._watch(trimmedPath, events, recursive);
  }
  return overrides.fsWatch(trimmedPath, events, recursive);
}