updateState method
Creates a new instance with updated expansion and/or selection state.
Returns a new TreeNode instance with the specified state changes while preserving all other properties. This maintains immutability of tree structures.
Parameters:
expanded
(bool?, optional): New expansion state, or null to keep currentselected
(bool?, optional): New selection state, or null to keep current
Returns: A new TreeNode<T>
instance with updated state
Example:
TreeNode<String> expandedNode = node.updateState(expanded: true);
TreeNode<String> selectedNode = node.updateState(selected: true);
TreeNode<String> both = node.updateState(expanded: true, selected: true);
Implementation
@override
TreeItem<T> updateState({
bool? expanded,
bool? selected,
}) {
return TreeItem(
data: data,
children: children,
expanded: expanded ?? this.expanded,
selected: selected ?? this.selected,
);
}