filtered method

InspectTree filtered(
  1. InspectFilter filter
)

This tree, narrowed to what filter asks for.

Throws when InspectFilter.root names no node, for the reason nodeAt gives: answering about whatever moved into that position would be a confident wrong answer.

Implementation

InspectTree filtered(InspectFilter filter) {
  if (filter.isEmpty || root == null) return this;
  var from = root!;
  if (filter.root case var id? when id.isNotEmpty) {
    var found = nodeAt(id);
    if (found == null) {
      throw ArgumentError(
        'no node "$id" in this tree. Ids are positions in the tree as it was '
        'when you read it, so an id from an older screen names nothing here. '
        'Observe again and take the id from that reply.',
      );
    }
    from = found;
  }
  if (filter.noise) from = from._withoutScaffolding();
  if (filter.maxDepth case var depth?) from = from._toDepth(depth);
  return InspectTree(entryId: entryId, root: from, format: format);
}