findParent method
Implementation
CNode findParent({
required final List<CNode> nodes,
required final NodeID parentID,
}) {
final parent = nodes.firstWhere((element) => element.id == parentID);
if (parent.intrinsicState.canHaveChildren) {
final children = nodes.where((element) => element.parentID == parent.id);
return parent.copyWith(children: children.toList());
}
if (parent.intrinsicState.canHaveChild) {
final child =
nodes.firstWhere((element) => element.parentID == parent.id);
return parent.copyWith(child: child);
}
return parent;
}