TreeItemNode<T> class
A concrete tree node implementation that holds data and state.
TreeItemNode represents a data-bearing node in the tree structure with support for hierarchical organization, expansion/collapse state, and selection state. It implements the immutable pattern where state changes return new instances.
Each TreeItemNode contains user data of type T, a list of child nodes, and
boolean flags for expansion and selection state. The class provides equality
comparison based on all properties and implements proper hash codes.
TreeItemNode supports deep hierarchies through its children list, which can contain other TreeItemNode instances or TreeRootNode containers. The expansion state controls visibility of children in tree views.
Example:
// Create a simple item
TreeItemNode<String> item = TreeItemNode(
data: 'Document',
expanded: true,
selected: false,
children: [
TreeItemNode(data: 'Chapter 1'),
TreeItemNode(data: 'Chapter 2'),
],
);
// Update its state
TreeItemNode<String> selected = item.updateState(selected: true);
Constructors
-
TreeItemNode({required T data, List<
TreeNode< children = const [], bool expanded = false, bool selected = false})T> > - Creates a TreeItemNode with the specified data and configuration.
Properties
-
children
→ List<
TreeNode< T> > -
List of child nodes beneath this item in the tree hierarchy.
final
- data → T
-
The data value stored in this tree item.
final
- expanded → bool
-
Whether this item is currently expanded to show its children.
final
- hashCode → int
-
The hash code for this object.
no setteroverride
- leaf → bool
-
Whether this node is a leaf (has no children).
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- selected → bool
-
Whether this item is currently selected.
final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
-
updateChildren(
List< TreeNode< children) → TreeItemNode<T> >T> -
Creates a new instance with updated children list.
override
-
updateState(
{bool? expanded, bool? selected}) → TreeItemNode< T> -
Creates a new instance with updated expansion and/or selection state.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override