TreeNode<T> class
abstract
Abstract base class representing a node in a tree structure.
TreeNode defines the interface for all nodes in the tree hierarchy, providing access to children, expansion state, and selection state. It supports immutable updates through copy methods that return new instances with modified state.
The generic type parameter T
represents the data type stored in tree items.
TreeNode is implemented by TreeItem for data-bearing nodes and TreeRoot
for the invisible root container.
Key operations include state updates for expansion and selection, child manipulation, and leaf node detection. All state changes return new instances to maintain immutability.
Example:
TreeNode<String> node = TreeItem(
data: 'parent',
children: [TreeItem(data: 'child1'), TreeItem(data: 'child2')],
);
// Expand the node
TreeNode<String> expanded = node.updateState(expanded: true);
// Check if it's a leaf
bool isLeaf = node.leaf; // false, has children
Constructors
Properties
-
children
→ List<
TreeNode< T> > -
List of child nodes belonging to this node.
no setter
- expanded → bool
-
Whether this node is currently expanded to show its children.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- leaf → bool
-
Whether this node is a leaf (has no children).
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- selected → bool
-
Whether this node is currently selected.
no setter
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
updateChildren(
List< TreeNode< children) → TreeNode<T> >T> - Creates a new instance with updated children list.
-
updateState(
{bool? expanded, bool? selected}) → TreeNode< T> - Creates a new instance with updated expansion and/or selection state.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited