DirectoryTreeBuilder<T> class
final
A mutable set of TreeEntrys that builds immutable DirectoryTrees.
Use a builder to assemble entries incrementally (from a scanner, a file picker, or a stream of changes) and call build whenever you need a snapshot. DirectoryTree.rebuild and DirectoryTree.toBuilder give you a builder seeded from an existing tree.
Entries are keyed by the NodeId of their path under TreeOptions.paths: adding an entry whose path maps to an existing id replaces that entry in place, keeping its position. Entries whose paths cannot be parsed are kept, in order, so build can report them in DirectoryTree.issues.
final builder = DirectoryTreeBuilder<int>()
..addFile('/repo/lib/a.dart', data: 120)
..addFile('/repo/lib/b.dart', data: 80)
..addDirectory('/repo/assets');
final tree = builder.build();
builder.remove('/repo/lib'); // also removes both files
A builder is mutable and is not a value: it compares by identity.
Constructors
-
DirectoryTreeBuilder({TreeOptions options = const TreeOptions(), Iterable<
TreeEntry< entries = const []})T> > -
Creates a builder with
options, seeded withentriesin order.
Properties
-
entries
→ List<
TreeEntry< T> > -
The current entries in insertion order, one per key, including entries
with invalid paths.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- length → int
-
The number of entries, including entries with invalid paths.
no setter
- options ↔ TreeOptions
-
The options used for keys and for build.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
add(
TreeEntry< T> entry) → void -
Adds
entry, replacing any entry whose path has the same id. -
addAll(
Iterable< TreeEntry< entries) → voidT> > -
Adds every entry of
entriesin order, as add does. -
addDirectory(
String path, {T? data}) → void -
Adds a directory entry for
pathwith optionaldata. -
addFile(
String path, {T? data}) → void -
Adds a file entry for
pathwith optionaldata. -
build(
) → DirectoryTree< T> - Builds an immutable DirectoryTree from the current entries and options.
-
clear(
) → void - Removes every entry. options stay as they are.
-
contains(
String path) → bool -
Whether an entry exists at
path, compared by id under TreeOptions.paths. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
remove(
String path, {bool recursive = true}) → int -
Removes the entry at
pathand, whenrecursive(the default), every entry inside it. -
removeWhere(
bool test(TreeEntry< T> entry)) → int -
Removes every entry for which
testreturns true and returns how many were removed. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited