FileSystemTreeLoader class final
Reads directory trees from the local file system one level at a time, for tree views that load folders when they are opened.
loadTree reads a directory and as many levels below it as you ask for; loadChildren reads the direct children of one directory. Pass loadChildren as a tear-off to DirectoryTreeController.new, and the controller reads a folder only when the user expands it:
const loader = FileSystemTreeLoader();
final controller = DirectoryTreeController<FileSystemEntity>(
tree: await loader.loadTree('/home/me/project'),
loadChildren: loader.loadChildren,
onLoadError: (directory, error, stackTrace) =>
debugPrint('Cannot open $directory: $error'),
);
Use it for file browsers and pickers over large or slow directories. To read a whole directory tree at once, use DirectoryScanner.scanTree instead.
Every directory is listed with a DirectoryScanner, one level deep, and each child becomes an entry of the kind, and with the data, that the scanner reports:
- a directory:
TreeEntry.directorywith Directory data; - a file, or any other entity that is not a directory (a pipe, a
socket):
TreeEntry.filewith File data; - a symbolic link that is not followed:
TreeEntry.filewith Link data (see followLinks).
Each child's entry path is the tree path of the directory that was
listed, followed by / and the child's name, so the children always
land inside that directory whatever spelling the tree uses. Each
child's data keeps the path exactly as dart:io reports it, and that is
the path a later loadChildren lists.
includeHidden and then skip decide which children are listed; the directory being read is never filtered.
Requires dart:io, so it works on Android, iOS, Linux, macOS, and
Windows, but not on the web.
- Annotations
Constructors
- FileSystemTreeLoader({bool includeHidden = false, bool followLinks = false, bool skip(FileSystemEntity entity)?})
-
Creates a loader; the directory to read is given later to loadTree
or loadChildren, so one loader serves a whole tree.
const
Properties
- followLinks → bool
-
Whether symbolic links are resolved.
final
- hashCode → int
-
The hash code for this object.
no setteroverride
- includeHidden → bool
-
Whether entities whose name starts with
.are listed.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- skip → bool Function(FileSystemEntity entity)?
-
Decides which entities to leave out; return true to omit one.
final
Methods
-
loadChildren(
DirectoryNode< FileSystemEntity> directory) → Future<Iterable< TreeEntry< >FileSystemEntity> > -
Lists the direct children of
directoryon disk. -
loadTree(
String path, {TreeOptions options = const TreeOptions(), int depth = 1}) → Future< DirectoryTree< FileSystemEntity> > -
Reads the directory at
pathanddepthlevels below it into a new tree built withoptions. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
Whether
otheris a FileSystemTreeLoader with equal settings.override