getNamePath static method

Iterable<String>? getNamePath(
  1. Node ancestor,
  2. Node child
)

Returns the name lookup path from the ancestor node to the child node.

Implementation

static Iterable<String>? getNamePath(Node ancestor, Node child) {
  List<String> result = [];
  Node? current = child;
  while (current != null) {
    if (identical(current, ancestor)) {
      return result.reversed;
    }
    result.add(current.name);
    current = current._parent;
  }

  debugPrint(
      'Name path formation failed because the given ancestor was not an ancestor of the given child.');
  return null;
}