watch method
Start watching theFileSystemEntity for changes.
The implementation uses platform-dependent event-based APIs for receivingfile-system notifications, thus behavior depends on the platform.
Windows: UsesReadDirectoryChangesW. The implementation onlysupports watching directories. Recursive watching is supported.Linux: Usesinotify. The implementation supports watching bothfiles and directories. Recursive watching is not supported.Note: When watching files directly, delete events might not happenas expected.OS X: Uses theFile System Events API.The implementation supports watching both files and directories.Recursive watching is supported.This API has several limitations:
The system will start listening for events once the returnedStream isbeing listened to, not when the call towatch is issued.
The returned value is an endless broadcastStream, that only stops whenone of the following happens:
- TheStream is canceled, e.g. by calling
cancelon theStreamSubscription. - TheFileSystemEntity being watched is deleted.
- System Watcher exits unexpectedly. e.g. On
Windowsthis happens whenbuffer that receive events fromReadDirectoryChangesWoverflows.
Useevents 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);}