TreeRows<T> class
final
The visible rows of a DirectoryTree view, in display order, with lookup, keyboard navigation, and incremental expand and collapse.
Create rows with DirectoryTree.flatten. The list holds one TreeRow
per visible node (or per compacted chain of directories): the tree's
pre-order restricted to nodes whose parent row is expanded (top-level
nodes are always candidates, unless showRoots is false). It is an
unmodifiable List, so it plugs straight into a virtualized list view:
itemCount: rows.length, itemBuilder: (_, i) => draw(rows[i]). Every
mutating List method throws an UnsupportedError, even when the call
would change nothing.
var rows = tree.flatten(expansion: const ExpansionState.collapsed());
rows = rows.toggleNode(rows.first.id); // the user clicked the first row
final row = rows.rowOf(tree.idOf('/repo/lib')!);
Filters and compact folders
With a filter, a node is visible only when it or a descendant matches;
TreeRow.isMatch tells which. Rows created with expandMatches: true
(the DirectoryTree.flatten default) have every ancestor of a match
whose state a row consults added to expansion, so the matches are
visible and can still be collapsed one by one. With compactFolders, a
directory that has exactly one child, which is itself a directory,
shares a row with that child, as in the compact folders of VS Code.
Compaction depends only on the tree's structure, not on the filter, so a
visible compacted row can also show directories that neither match nor
contain a match: with the filter name == 'lib', the row lib/src
shows src. Such a directory counts as visible wherever its row does:
indexOfNode finds it, and reveal reveals it.
Two expansion states
expansion is the state the rows show; requestedExpansion is the same state without the folders a filter revealed: what the caller passed in, plus every later expandNode, collapseNode, toggleNode, and reveal. Draw from the rows (or expansion); persist requestedExpansion, so a saved view does not reopen every folder a search opened. The two are the same object until a filter reveals something: until revealing a match expands a directory whose state a row consults (never a hidden root, and never a directory that continues a compacted chain).
Hidden roots
With showRoots false, the top-level nodes produce no rows and count as
expanded whatever expansion says. Their visible children are the
depth-0 rows, in root order and then child order, and all depth-0 rows
are siblings for TreeRow.isLast and TreeRow.guides, as if the roots
did not exist. A top-level id has no row (indexOfNode returns -1),
expandNode, collapseNode, and toggleNode ignore it, and neither
reveal nor expandMatches adds it to a state. Compacted chains start
below the roots. Use it for an explorer of one folder, whose name is a
title rather than a row.
Incremental updates
expandNode, collapseNode, toggleNode, and reveal return new rows
that equal what DirectoryTree.flatten would return for the updated
expansion with the same filter, compactFolders, and showRoots
and expandMatches: false, but they only build the rows that change:
expanding a row inserts its newly visible descendants right after it,
collapsing removes them, and every other row is the identical TreeRow
object as before. The filter is never called again; match results
computed by the original flatten are shared by every TreeRows derived
from it.
Keyboard navigation
indexOfNode finds the row of a node (also when the node is hidden
inside a compacted row), parentIndexOf moves to the parent row (left
arrow), and firstChildIndexOf to the first child row (right arrow).
Up and down are index - 1 and index + 1. All of them run in
O(log rows) or better, however long the compacted chains are.
Properties
- compactFolders → bool
-
Whether chains of single-child directories share one row.
no setter
- expansion → ExpansionState
-
The expansion state the rows show (the effective state).
final
- filter → TreeFilter?
-
The filter that decides which nodes are visible, or
nullwhen every node is a candidate.no setter -
first
↔ TreeRow<
T> -
The first element.
getter/setter pairinherited-getteroverride-setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isEmpty → bool
-
Whether this collection has no elements.
no setterinherited
- isNotEmpty → bool
-
Whether this collection has at least one element.
no setterinherited
-
iterator
→ Iterator<
TreeRow< T> > -
A new
Iteratorthat allows iterating the elements of thisIterable.no setterinherited -
last
↔ TreeRow<
T> -
The last element.
getter/setter pairinherited-getteroverride-setter
- length ↔ int
-
The number of visible rows.
getter/setter pairoverride
- requestedExpansion → ExpansionState
-
The expansion state the caller asked for, without the folders a filter
revealed.
final
-
reversed
→ Iterable<
TreeRow< T> > -
An Iterable of the objects in this list in reverse order.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- showRoots → bool
-
Whether the top-level nodes are rows.
no setter
-
single
→ TreeRow<
T> -
Checks that this iterable has only one element, and returns that element.
no setterinherited
-
tree
→ DirectoryTree<
T> -
The tree these rows show.
no setter
Methods
-
add(
TreeRow< T> element) → void -
Adds
valueto the end of this list, extending the length by one.override -
addAll(
Iterable< TreeRow< iterable) → voidT> > -
Appends all objects of
iterableto the end of this list.override -
any(
bool test(TreeRow< T> element)) → bool -
Checks whether any element of this iterable satisfies
test.inherited -
asMap(
) → Map< int, TreeRow< T> > -
An unmodifiable Map view of this list.
inherited
-
cast<
R> () → List< R> -
Returns a view of this list as a list of
Rinstances.inherited -
clear(
) → void -
Removes all objects from this list; the length of the list becomes zero.
override
-
collapseNode(
NodeId id) → TreeRows< T> -
Returns rows in which the directory
idis collapsed. -
contains(
Object? element) → bool -
Whether the collection contains an element equal to
element.inherited -
elementAt(
int index) → TreeRow< T> -
Returns the
indexth element.inherited -
every(
bool test(TreeRow< T> element)) → bool -
Checks whether every element of this iterable satisfies
test.inherited -
expand<
T> (Iterable< T> f(TreeRow<T> element)) → Iterable<T> -
Expands each element of this Iterable into zero or more elements.
inherited
-
expandNode(
NodeId id) → TreeRows< T> -
Returns rows in which the directory
idis expanded. -
fillRange(
int start, int end, [TreeRow< T> ? fill]) → void -
Overwrites a range of elements with
fillValue.override -
firstChildIndexOf(
int index) → int? -
The index of the first child row of the row at
index, which is alwaysindex + 1, ornullwhen the row shows no child rows. -
firstWhere(
bool test(TreeRow< T> element), {TreeRow<T> orElse()?}) → TreeRow<T> -
The first element that satisfies the given predicate
test.inherited -
fold<
T> (T initialValue, T combine(T previousValue, TreeRow< T> element)) → T -
Reduces a collection to a single value by iteratively combining each
element of the collection with an existing value
inherited
-
followedBy(
Iterable< TreeRow< other) → Iterable<T> >TreeRow< T> > -
Creates the lazy concatenation of this iterable and
other.inherited -
forEach(
void action(TreeRow< T> element)) → void -
Invokes
actionon each element of this iterable in iteration order.inherited -
getRange(
int start, int end) → Iterable< TreeRow< T> > -
Creates an Iterable that iterates over a range of elements.
inherited
-
indexOf(
Object? element, [int start = 0]) → int -
The first index of
elementin this list.inherited -
indexOfNode(
NodeId id) → int -
The index of the row that shows the node
id, or -1 when that node is not visible. -
indexWhere(
bool test(TreeRow< T> element), [int start = 0]) → int -
The first index in the list that satisfies the provided
test.inherited -
insert(
int index, TreeRow< T> element) → void -
Inserts
elementat positionindexin this list.override -
insertAll(
int index, Iterable< TreeRow< iterable) → voidT> > -
Inserts all objects of
iterableat positionindexin this list.override -
join(
[String separator = ""]) → String -
Converts each element to a String and concatenates the strings.
inherited
-
lastIndexOf(
Object? element, [int? start]) → int -
The last index of
elementin this list.inherited -
lastIndexWhere(
bool test(TreeRow< T> element), [int? start]) → int -
The last index in the list that satisfies the provided
test.inherited -
lastWhere(
bool test(TreeRow< T> element), {TreeRow<T> orElse()?}) → TreeRow<T> -
The last element that satisfies the given predicate
test.inherited -
map<
T> (T f(TreeRow< T> element)) → Iterable<T> -
The current elements of this iterable modified by
toElement.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
parentIndexOf(
int index) → int? -
The index of the parent row of the row at
index, ornullfor a top-level row (depth 0). -
reduce(
TreeRow< T> combine(TreeRow<T> previousValue, TreeRow<T> element)) → TreeRow<T> -
Reduces a collection to a single value by iteratively combining elements
of the collection using the provided function.
inherited
-
remove(
Object? element) → bool -
Removes the first occurrence of
valuefrom this list.override -
removeAt(
int index) → TreeRow< T> -
Removes the object at position
indexfrom this list.override -
removeLast(
) → TreeRow< T> -
Removes and returns the last object in this list.
override
-
removeRange(
int start, int end) → void -
Removes a range of elements from the list.
override
-
removeWhere(
bool test(TreeRow< T> element)) → void -
Removes all objects from this list that satisfy
test.override -
replaceRange(
int start, int end, Iterable< TreeRow< newContents) → voidT> > -
Replaces a range of elements with the elements of
replacements.override -
retainWhere(
bool test(TreeRow< T> element)) → void -
Removes all objects from this list that fail to satisfy
test.override -
reveal(
NodeId id) → TreeRows< T> -
Returns rows in which the node
idis visible, by expanding its collapsed ancestors. -
rowOf(
NodeId id) → TreeRow< T> ? -
The row that shows the node
id, ornullwhen that node is not visible. -
setAll(
int index, Iterable< TreeRow< iterable) → voidT> > -
Overwrites elements with the objects of
iterable.override -
setRange(
int start, int end, Iterable< TreeRow< iterable, [int skipCount = 0]) → voidT> > -
Writes some elements of
iterableinto a range of this list.override -
shuffle(
[Random? random]) → void -
Shuffles the elements of this list randomly.
override
-
singleWhere(
bool test(TreeRow< T> element), {TreeRow<T> orElse()?}) → TreeRow<T> -
The single element that satisfies
test.inherited -
skip(
int count) → Iterable< TreeRow< T> > -
Creates an Iterable that provides all but the first
countelements.inherited -
skipWhile(
bool test(TreeRow< T> element)) → Iterable<TreeRow< T> > -
Creates an
Iterablethat skips leading elements whiletestis satisfied.inherited -
sort(
[int compare(TreeRow< T> a, TreeRow<T> b)?]) → void -
Sorts this list according to the order specified by the
comparefunction.override -
sublist(
int start, [int? end]) → List< TreeRow< T> > -
Returns a new list containing the elements between
startandend.inherited -
take(
int count) → Iterable< TreeRow< T> > -
Creates a lazy iterable of the
countfirst elements of this iterable.inherited -
takeWhile(
bool test(TreeRow< T> element)) → Iterable<TreeRow< T> > -
Creates a lazy iterable of the leading elements satisfying
test.inherited -
toggleNode(
NodeId id) → TreeRows< T> -
Returns rows in which the directory
idhas the opposite state: collapseNode when it is expanded in expansion, expandNode otherwise. -
toList(
{bool growable = true}) → List< TreeRow< T> > -
Creates a List containing the elements of this Iterable.
inherited
-
toSet(
) → Set< TreeRow< T> > -
Creates a Set containing the same elements as this iterable.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
where(
bool test(TreeRow< T> element)) → Iterable<TreeRow< T> > -
Creates a new lazy Iterable with all elements that satisfy the
predicate
test.inherited -
whereType<
T> () → Iterable< T> -
Creates a new lazy Iterable with all elements that have type
T.inherited -
withExpansion(
ExpansionState expansion, {bool revealMatches = false}) → TreeRows< T> -
Returns the rows for
expansion, with the same tree, filter, compactFolders, and showRoots.
Operators
-
operator +(
List< TreeRow< other) → List<T> >TreeRow< T> > -
Returns the concatenation of this list and
other.inherited -
operator ==(
Object other) → bool -
The equality operator.
inherited
-
operator [](
int index) → TreeRow< T> -
The row at
index. Throws a RangeError whenindexis out of range. O(1).override -
operator []=(
int index, TreeRow< T> value) → void -
Sets the value at the given
indexin the list tovalue.override