flattenTreeToList static method

List flattenTreeToList(
  1. List tree
)

Implementation

static List<dynamic> flattenTreeToList(List<dynamic> tree) {
  List<dynamic> result = [];

  for (dynamic node in tree) {
    if (node is Map && node.containsKey('label')) {
      // Add the current node to results list
      result.add(node);

      // If the node has children, recursively flatten them
      if (node.containsKey('children')) {
        List<dynamic> children = node['children'];
        result.addAll(flattenTreeToList(children));
      }
    }
  }

  return result;
}