dart

Watch for file changes in Dart


Is it possible to watch for file changes (deletion, creation, edit) in Dart, like in NodeJS?

I do not seem to be able to find an answer to this, is it possible that it will be implemented in the future?


Solution

  • You want to take a look at FileSystemEntity.watch() method. However due to platform differences some platforms provide better support than others. In particular, on Windows you can only watch a Directory, and not just an individual file. On Linux you can watch Files or Directories but not recursively watch Directories. And MacOS supports all of the above.

    There is also a watcher package on Pub. This supports polling (periodically check if the file has changed) if the file system does not allow watching.