updateNode<T> method
Updates an existing node identified by specified key. This method returns a new list with the updated node.
Implementation
List<Node> updateNode<T>(String key, Node<T> newNode, {Node? parent}) {
List<Node> _children = parent == null ? this.children : parent.children;
return _children.map((Node child) {
if (child.key == key) {
return newNode;
} else {
if (child.isParent) {
return child.copyWith(
children: updateNode<T>(
key,
newNode,
parent: child,
),
);
}
return child;
}
}).toList();
}