registerCustomWatcher function Null safety

void registerCustomWatcher(
  1. String id,
  2. DirectoryWatcher? createDirectoryWatcher(
    1. String path,
    2. {Duration? pollingDelay}
    )?,
  3. FileWatcher? createFileWatcher(
    1. String path,
    2. {Duration? pollingDelay}
    )?
)

Registers a custom watcher.

Each custom watcher must have a unique id and the same watcher may not be registered more than once. createDirectoryWatcher and createFileWatcher should return watchers for the file paths they are able to handle. If the custom watcher is not able to handle the path it should return null. The paths handled by each custom watch may not overlap, at most one custom matcher may return a non-null watcher for a given path.

When a file or directory watcher is created the path is checked against each registered custom watcher, and if exactly one custom watcher is available it will be used instead of the default.

Implementation

void registerCustomWatcher(
  String id,
  DirectoryWatcher? Function(String path, {Duration? pollingDelay})?
      createDirectoryWatcher,
  FileWatcher? Function(String path, {Duration? pollingDelay})?
      createFileWatcher,
) {
  if (_customWatcherFactories.containsKey(id)) {
    throw ArgumentError('A custom watcher with id `$id` '
        'has already been registered');
  }
  _customWatcherFactories[id] = _CustomWatcherFactory(
      id,
      createDirectoryWatcher ?? (_, {pollingDelay}) => null,
      createFileWatcher ?? (_, {pollingDelay}) => null);
}