Watcher constructor

Watcher(
  1. String path, {
  2. Duration? pollingDelay,
})

Creates a new DirectoryWatcher or FileWatcher monitoring path, depending on whether it's a file or directory.

If a native watcher is available for this platform, this will use it. Otherwise, it will fall back to a polling watcher. Notably, watching individual files is not natively supported on Windows, although watching directories is.

If pollingDelay is passed, it specifies the amount of time the watcher will pause between successive polls of the contents of path. Making this shorter will give more immediate feedback at the expense of doing more IO and higher CPU usage. Defaults to one second. Ignored for non-polling watchers.

Implementation

factory Watcher(String path, {Duration? pollingDelay}) {
  if (File(path).existsSync()) {
    return FileWatcher(path, pollingDelay: pollingDelay);
  } else {
    return DirectoryWatcher(path, pollingDelay: pollingDelay);
  }
}