evaluate method

  1. @override
FutureOr<Evaluation> evaluate (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;
    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 - ui.window.physicalSize.height).abs() <= delta
      || (paintBounds.right - ui.window.physicalSize.width).abs() <= delta)
      return result;
    // shrink by device pixel ratio.
    final Size candidateSize = paintBounds.size / ui.window.devicePixelRatio;
    if (candidateSize.width < size.width || candidateSize.height < size.height)
      result += Evaluation.fail(
        '$node: expected tap target size of at least $size, but found $candidateSize\n'
        'See also: $link');
    return result;
  }
  return traverse(root);
}