evaluate method Null safety

  1. @override
FutureOr<Evaluation> evaluate(
  1. WidgetTester tester
)
override

Evaluate whether the current state of the tester conforms to the rule.

Implementation

@override
FutureOr<Evaluation> evaluate(WidgetTester tester) {
  final SemanticsNode root = tester.binding.pipelineOwner.semanticsOwner!.rootSemanticsNode!;
  Evaluation traverse(SemanticsNode node) {
    Evaluation result = const Evaluation.pass();
    node.visitChildren((SemanticsNode child) {
      result += traverse(child);
      return true;
    });
    if (node.isMergedIntoParent)
      return result;
    final SemanticsData data = node.getSemanticsData();
    // Skip node if it has no actions, or is marked as hidden.
    if ((!data.hasAction(ui.SemanticsAction.longPress)
      && !data.hasAction(ui.SemanticsAction.tap))
      || data.hasFlag(ui.SemanticsFlag.isHidden))
      return result;
    // Skip links https://www.w3.org/WAI/WCAG21/Understanding/target-size.html
    if (data.hasFlag(ui.SemanticsFlag.isLink))
      return result;
    Rect paintBounds = node.rect;
    SemanticsNode? current = node;
    while (current != null) {
      if (current.transform != null)
        paintBounds = MatrixUtils.transformRect(current.transform!, paintBounds);
      current = current.parent;
    }
    // skip node if it is touching the edge of the screen, since it might
    // be partially scrolled offscreen.
    const double delta = 0.001;
    if (paintBounds.left <= delta
      || paintBounds.top <= delta
      || (paintBounds.bottom - tester.binding.window.physicalSize.height).abs() <= delta
      || (paintBounds.right - tester.binding.window.physicalSize.width).abs() <= delta)
      return result;
    // shrink by device pixel ratio.
    final Size candidateSize = paintBounds.size / tester.binding.window.devicePixelRatio;
    if (candidateSize.width < size.width - delta || candidateSize.height < size.height - delta) {
      result += Evaluation.fail(
        '$node: expected tap target size of at least $size, but found $candidateSize\n'
        'See also: $link');
    }
    return result;
  }
  return traverse(root);
}