scanTree method

void scanTree(
  1. BuildContext context
)

Scan the widget/render tree for issues.

Default implementation runs a single-detector walk using the unified walk methods (prepareScan, checkElement, afterElement, finalizeScan). The controller bypasses this and calls those methods directly in a unified walk for better performance.

Custom detectors may override this directly for backward compatibility.

Implementation

void scanTree(BuildContext context) {
  if (!isEnabled) return;
  prepareScan(context);
  void visitor(Element element) {
    checkElement(element);
    element.visitChildren(visitor);
    afterElement(element);
  }

  try {
    context.visitChildElements(visitor);
    notifyWalkCompleted();
  } catch (e, s) {
    assert(() {
      debugPrint('Sleuth: detector tree walk failed: $e\n$s');
      return true;
    }());
  }
  finalizeScan();
}