getAncestors static method

List<Tree> getAncestors(
  1. Tree t
)

Return a list of all ancestors of this node. The first node of list is the root and the last is the parent of this node.

@since 4.5.1

Implementation

static List<Tree> getAncestors(Tree t) {
  if (t.parent == null) return [];
  var walker = t.parent;
  final ancestors = <Tree>[];
  while (walker != null) {
    ancestors.insert(0, walker); // insert at start
    walker = walker.parent;
  }
  return ancestors;
}