lastChildWhere method

Node? lastChildWhere(
  1. bool test(
    1. Node element
    )
)

Returns the last node in the subtree that satisfies the given predicate

Implementation

Node? lastChildWhere(bool Function(Node element) test) {
  final children = this.children.toList().reversed;
  for (final child in children) {
    if (child.children.isNotEmpty) {
      final last = child.lastChildWhere(test);
      if (last != null) {
        return last;
      }
    }
    if (test(child)) {
      return child;
    }
  }
  return null;
}