TreeController<T extends Object> class
A controller for managing the state of a tree structure.
This controller handles:
- Tree state management (expansion/collapse)
- Tree traversal (depth-first and breadth-first)
- Search functionality
- Parent/ancestor navigation
Example:
class Node {
Node(this.title, [this.children = const []]);
final String title;
final List<Node> children;
Node? parent;
}
final controller = TreeController<Node>(
roots: [Node('Root')],
childrenProvider: (node) => node.children,
parentProvider: (node) => node.parent,
);
- Mixed-in types
Constructors
-
TreeController({required Iterable<
T> roots, required ChildrenProvider<T> childrenProvider, ParentProvider<T> ? parentProvider, bool defaultExpansionState = false, bool enableCheckbox = false}) - Creates a TreeController.
Properties
- areAllRootsCollapsed → bool
-
Whether all root nodes are collapsed.
no setter
- areAllRootsExpanded → bool
-
Whether all root nodes are expanded.
no setter
-
checkedNodes
→ Set<
T> -
Set of checked nodes (when checkbox is enabled).
latefinal
-
childrenProvider
→ ChildrenProvider<
T> -
Callback to get the children of a node.
final
- defaultExpansionState → bool
-
Default expansion state for nodes.
final
- enableCheckbox → bool
-
Whether checkbox selection is enabled.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- isTreeCollapsed → bool
-
Whether all nodes in the tree are collapsed.
no setter
- isTreeExpanded → bool
-
Whether all nodes in the tree are expanded.
no setter
-
parentProvider
→ ParentProvider<
T> -
Callback to get the parent of a node.
final
-
roots
↔ Iterable<
T> -
The root nodes of the tree.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
toggledNodes
→ Set<
T> -
Set of toggled nodes (expanded if defaultExpansionState is false, collapsed otherwise).
latefinal
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
breadthFirstSearch(
{Iterable< T> ? startingNodes, ValuePredicate<T> ? descendCondition, ValuePredicate<T> ? returnCondition, Visitor<T> ? onTraverse}) → T? - Traverses the tree in breadth-first order.
-
checkNodeHasAncestor(
{required T node, required T potentialAncestor, bool checkForEquality = false}) → bool -
Checks if
potentialAncestoris an ancestor ofnode. -
clearCheckedNodes(
) → void - Clears all checked nodes.
-
collapse(
T node) → void -
Collapses
node. -
collapseAll(
) → void - Collapses all nodes in the tree.
-
collapseCascading(
Iterable< T> nodes) → void -
Collapses
nodesand all their descendants. -
defaultDescendCondition(
TreeEntry< T> entry) → bool - Default descend condition for depth-first traversal.
-
depthFirstTraversal(
{required Visitor< TreeEntry< onTraverse, ValuePredicate<T> >TreeEntry< ? descendCondition, TreeEntry<T> >T> ? rootEntry}) → void - Traverses the tree in depth-first order creating TreeEntry instances.
-
dispose(
) → void -
Discards any resources used by the object.
override
-
expand(
T node) → void -
Expands
node. -
expandAll(
) → void - Expands all nodes in the tree.
-
expandAncestors(
T node) → void -
Expands all ancestors of
node. -
expandCascading(
Iterable< T> nodes) → void -
Expands
nodesand all their descendants. -
getCheckedNodes(
) → Set< T> - Returns all checked nodes (excluding indeterminate parents).
-
getExpansionState(
T node) → bool -
Returns the expansion state of
node. -
isChecked(
T node) → bool -
Returns whether
nodeis checked. -
isIndeterminate(
T node) → bool -
Returns whether
nodeis in indeterminate state (some but not all children checked). -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
rebuild(
) → void - Notifies listeners that the tree structure changed.
-
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes.
inherited
-
search(
ValuePredicate< T> predicate) → TreeSearchResult<T> -
Searches the tree for nodes matching
predicate. -
selectAll(
) → void - Selects all nodes in the tree (checks all checkboxes).
-
setCheckboxState(
T node, bool checked) → void -
Sets the checked state of
nodeand updates children and ancestors. -
setCheckedNodes(
Set< T> nodes) → void - Sets the checked nodes (useful for initializing selection).
-
setExpansionState(
T node, bool expanded) → void -
Sets the expansion state of
node. -
toggleCheckbox(
T node) → void -
Toggles the checked state of
nodeand updates children and ancestors. -
toggleExpansion(
T node) → void -
Toggles the expansion state of
node. -
toString(
) → String -
A string representation of this object.
inherited
-
unselectAll(
) → void - Unselects all nodes in the tree (unchecks all checkboxes).
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited