TreeItem<T> class
A concrete tree node implementation that holds data and state.
TreeItem 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 TreeItem 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.
TreeItem supports deep hierarchies through its children list, which can contain other TreeItem instances or TreeRoot containers. The expansion state controls visibility of children in tree views.
Example:
// Create a simple item
TreeItem<String> item = TreeItem(
data: 'Document',
expanded: true,
selected: false,
children: [
TreeItem(data: 'Chapter 1'),
TreeItem(data: 'Chapter 2'),
],
);
// Update its state
TreeItem<String> selected = item.updateState(selected: true);
Constructors
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) → TreeItem<T> >T> -
Creates a new instance with updated children list.
override
-
updateState(
{bool? expanded, bool? selected}) → TreeItem< T> -
Creates a new instance with updated expansion and/or selection state.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override