loadChildren method

Lists the direct children of directory on disk.

Pass it as a tear-off to DirectoryTreeController.new as loadChildren: the controller calls it when a directory without children is expanded and merges the entries into its tree.

It lists directory.data.path: the path dart:io reported for the directory, or for the directory loadTree read, the path it read (the one it was given, or its absolute form for a path that climbs above its start). A node without data, such as an inferred directory, is listed at its tree path instead (TreePath.toString, whose / separators dart:io accepts on Windows too). Each entry's path is the directory's tree path followed by / and the child's name, so the controller always accepts it as inside the directory. Children are filtered by includeHidden and skip, and links are handled by followLinks, exactly as in loadTree. Grandchildren are never read, so a subdirectory comes back without children and loads when it is expanded in turn.

Completes with a PathNotFoundException when the directory no longer exists, a FileSystemException when it is not a directory or cannot be listed completely (for example a PathAccessException without read permission), and any exception skip throws. A partial listing is never returned. The controller turns the error into DirectoryLoadStatus.failed, keeps it for DirectoryTreeController.loadErrorOf, and passes it to its onLoadError; expanding the directory again retries.

Takes one asynchronous directory listing and O(k log k) time for the k children.

Implementation

Future<Iterable<TreeEntry<FileSystemEntity>>> loadChildren(
  DirectoryNode<FileSystemEntity> directory,
) {
  final base = directory.path.toString();
  return _list(directory.data?.path ?? base, base);
}