accessibility.dart 23.7 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';
import 'dart:math' as math;
import 'dart:typed_data';
import 'dart:ui' as ui;

import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';

import 'finders.dart';
import 'widget_tester.dart';

/// The result of evaluating a semantics node by a [AccessibilityGuideline].
class Evaluation {
  /// Create a passing evaluation.
19 20 21
  const Evaluation.pass()
    : passed = true,
      reason = null;
22 23 24 25 26 27 28 29 30 31 32 33

  /// Create a failing evaluation, with an optional [reason] explaining the
  /// result.
  const Evaluation.fail([this.reason]) : passed = false;

  // private constructor for adding cases together.
  const Evaluation._(this.passed, this.reason);

  /// Whether the given tree or node passed the policy evaluation.
  final bool passed;

  /// If [passed] is false, contains the reason for failure.
34
  final String? reason;
35 36 37 38 39

  /// Combines two evaluation results.
  ///
  /// The [reason] will be concatenated with a newline, and [passed] will be
  /// combined with an `&&` operator.
40
  Evaluation operator +(Evaluation? other) {
41 42
    if (other == null)
      return this;
43
    final StringBuffer buffer = StringBuffer();
44
    if (reason != null) {
45
      buffer.write(reason);
46 47
      buffer.write(' ');
    }
48 49
    if (other.reason != null)
      buffer.write(other.reason);
50
    return Evaluation._(passed && other.passed, buffer.isEmpty ? null : buffer.toString());
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
  }
}

/// An accessibility guideline describes a recommendation an application should
/// meet to be considered accessible.
abstract class AccessibilityGuideline {
  /// A const constructor allows subclasses to be const.
  const AccessibilityGuideline();

  /// Evaluate whether the current state of the `tester` conforms to the rule.
  FutureOr<Evaluation> evaluate(WidgetTester tester);

  /// A description of the policy restrictions and criteria.
  String get description;
}

67
/// A guideline which enforces that all tappable semantics nodes have a minimum
68 69 70 71 72 73 74
/// size.
///
/// Each platform defines its own guidelines for minimum tap areas.
@visibleForTesting
class MinimumTapTargetGuideline extends AccessibilityGuideline {
  const MinimumTapTargetGuideline._(this.size, this.link);

75
  /// The minimum allowed size of a tappable node.
76 77 78 79 80 81 82
  final Size size;

  /// A link describing the tap target guidelines for a platform.
  final String link;

  @override
  FutureOr<Evaluation> evaluate(WidgetTester tester) {
83
    final SemanticsNode root = tester.binding.pipelineOwner.semanticsOwner!.rootSemanticsNode!;
84 85 86 87 88 89
    Evaluation traverse(SemanticsNode node) {
      Evaluation result = const Evaluation.pass();
      node.visitChildren((SemanticsNode child) {
        result += traverse(child);
        return true;
      });
90 91
      if (node.isMergedIntoParent)
        return result;
92
      final SemanticsData data = node.getSemanticsData();
93 94 95 96
      // 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))
97 98
        return result;
      Rect paintBounds = node.rect;
99
      SemanticsNode? current = node;
100 101
      while (current != null) {
        if (current.transform != null)
102
          paintBounds = MatrixUtils.transformRect(current.transform!, paintBounds);
103 104
        current = current.parent;
      }
105 106 107 108 109
      // 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
110 111
        || (paintBounds.bottom - tester.binding.window.physicalSize.height).abs() <= delta
        || (paintBounds.right - tester.binding.window.physicalSize.width).abs() <= delta)
112
        return result;
113
      // shrink by device pixel ratio.
114
      final Size candidateSize = paintBounds.size / tester.binding.window.devicePixelRatio;
115
      if (candidateSize.width < size.width - delta || candidateSize.height < size.height - delta) {
116
        result += Evaluation.fail(
117 118
          '$node: expected tap target size of at least $size, but found $candidateSize\n'
          'See also: $link');
119
      }
120 121 122 123 124 125 126 127 128
      return result;
    }
    return traverse(root);
  }

  @override
  String get description => 'Tappable objects should be at least $size';
}

129 130 131 132 133 134 135 136 137 138 139
/// A guideline which enforces that all nodes with a tap or long press action
/// also have a label.
@visibleForTesting
class LabeledTapTargetGuideline extends AccessibilityGuideline {
  const LabeledTapTargetGuideline._();

  @override
  String get description => 'Tappable widgets should have a semantic label';

  @override
  FutureOr<Evaluation> evaluate(WidgetTester tester) {
140
    final SemanticsNode root = tester.binding.pipelineOwner.semanticsOwner!.rootSemanticsNode!;
141 142 143 144 145 146
    Evaluation traverse(SemanticsNode node) {
      Evaluation result = const Evaluation.pass();
      node.visitChildren((SemanticsNode child) {
        result += traverse(child);
        return true;
      });
147
      if (node.isMergedIntoParent || node.isInvisible || node.hasFlag(ui.SemanticsFlag.isHidden))
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
        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))
        return result;
      if (data.label == null || data.label.isEmpty) {
        result += Evaluation.fail(
          '$node: expected tappable node to have semantic label, but none was found\n',
        );
      }
      return result;
    }
    return traverse(root);
  }
}

164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
/// A guideline which verifies that all nodes that contribute semantics via text
/// meet minimum contrast levels.
///
/// The guidelines are defined by the Web Content Accessibility Guidelines,
/// http://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html.
@visibleForTesting
class MinimumTextContrastGuideline extends AccessibilityGuideline {
  const MinimumTextContrastGuideline._();

  /// The minimum text size considered large for contrast checking.
  ///
  /// Defined by http://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html
  static const int kLargeTextMinimumSize = 18;

  /// The minimum text size for bold text to be considered large for contrast
  /// checking.
  ///
  /// Defined by http://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html
  static const int kBoldTextMinimumSize = 14;

  /// The minimum contrast ratio for normal text.
  ///
  /// Defined by http://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html
  static const double kMinimumRatioNormalText = 4.5;

  /// The minimum contrast ratio for large text.
  ///
  /// Defined by http://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html
  static const double kMinimumRatioLargeText = 3.0;

194 195
  static const double _kDefaultFontSize = 12.0;

196 197
  @override
  Future<Evaluation> evaluate(WidgetTester tester) async {
198
    final SemanticsNode root = tester.binding.pipelineOwner.semanticsOwner!.rootSemanticsNode!;
199
    final RenderView renderView = tester.binding.renderView;
200
    final OffsetLayer layer = renderView.debugLayer! as OffsetLayer;
201 202
    ui.Image? image;
    final ByteData byteData = (await tester.binding.runAsync<ByteData?>(() async {
203 204
      // Needs to be the same pixel ratio otherwise our dimensions won't match the
      // last transform layer.
205
      image = await layer.toImage(renderView.paintBounds, pixelRatio: 1 / tester.binding.window.devicePixelRatio);
206 207 208
      return image!.toByteData();
    }))!;
    assert(image != null);
209 210

    Future<Evaluation> evaluateNode(SemanticsNode node) async {
211 212 213
      Evaluation result = const Evaluation.pass();
      if (node.isInvisible || node.isMergedIntoParent || node.hasFlag(ui.SemanticsFlag.isHidden))
        return result;
214 215 216 217 218 219
      final SemanticsData data = node.getSemanticsData();
      final List<SemanticsNode> children = <SemanticsNode>[];
      node.visitChildren((SemanticsNode child) {
        children.add(child);
        return true;
      });
220
      for (final SemanticsNode child in children) {
221
        result += await evaluateNode(child);
222 223
      }
      if (_shouldSkipNode(data)) {
224
        return result;
225
      }
226 227 228

      // We need to look up the inherited text properties to determine the
      // contrast ratio based on text size/weight.
229
      double? fontSize;
230
      bool isBold;
231
      final String text = data.label.isEmpty ? data.value : data.label;
232
      final List<Element> elements = find.text(text).hitTestable().evaluate().toList();
233
      Rect paintBounds;
234 235
      if (elements.length == 1) {
        final Element element = elements.single;
236 237
        assert(element.renderObject != null && element.renderObject is RenderBox);
        final RenderBox renderObject = element.renderObject! as RenderBox;
238
        paintBounds = Rect.fromPoints(
239 240
          renderObject.localToGlobal(renderObject.paintBounds.topLeft - const Offset(4.0, 4.0)),
          renderObject.localToGlobal(renderObject.paintBounds.bottomRight + const Offset(4.0, 4.0)),
241
        );
242 243 244
        final Widget widget = element.widget;
        final DefaultTextStyle defaultTextStyle = DefaultTextStyle.of(element);
        if (widget is Text) {
245
          final TextStyle effectiveTextStyle = widget.style == null || widget.style!.inherit
246
              ? defaultTextStyle.style.merge(widget.style)
247
              : widget.style!;
248 249 250 251 252 253
          fontSize = effectiveTextStyle.fontSize;
          isBold = effectiveTextStyle.fontWeight == FontWeight.bold;
        } else if (widget is EditableText) {
          isBold = widget.style.fontWeight == FontWeight.bold;
          fontSize = widget.style.fontSize;
        } else {
254
          throw StateError('Unexpected widget type: ${widget.runtimeType}');
255 256
        }
      } else if (elements.length > 1) {
257
        return Evaluation.fail('Multiple nodes with the same label: ${data.label}\n');
258
      } else {
259 260 261
        // If we can't find the text node then assume the label does not
        // correspond to actual text.
        return result;
262 263
      }

264
      if (_isNodeOffScreen(paintBounds, tester.binding.window)) {
265
        return result;
266
      }
267
      final List<int> subset = _colorsWithinRect(byteData, paintBounds, image!.width, image!.height);
268
      // Node was too far off screen.
269
      if (subset.isEmpty) {
270
        return result;
271
      }
272
      final _ContrastReport report = _ContrastReport(subset);
273 274 275 276
      // If rectangle is empty, pass the test.
      if (report.isEmptyRect) {
        return result;
      }
277
      final double contrastRatio = report.contrastRatio();
278 279
      const double delta = -0.01;
      double targetContrastRatio;
280
      if ((isBold && (fontSize ?? _kDefaultFontSize) > kBoldTextMinimumSize) || (fontSize ?? _kDefaultFontSize) > kLargeTextMinimumSize) {
281 282 283 284
        targetContrastRatio = kMinimumRatioLargeText;
      } else {
        targetContrastRatio = kMinimumRatioNormalText;
      }
285
      if (contrastRatio - targetContrastRatio >= delta) {
286
        return result + const Evaluation.pass();
287
      }
288
      return result + Evaluation.fail(
289 290
        '$node:\nExpected contrast ratio of at least '
        '$targetContrastRatio but found ${contrastRatio.toStringAsFixed(2)} for a font size of $fontSize. '
291 292
        'The computed light color was: ${report.lightColor}, '
        'The computed dark color was: ${report.darkColor}\n'
293 294 295 296 297 298 299 300 301 302
        'See also: https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html'
      );
    }
    return evaluateNode(root);
  }

  // Skip routes which might have labels, and nodes without any text.
  bool _shouldSkipNode(SemanticsData data) {
    if (data.hasFlag(ui.SemanticsFlag.scopesRoute))
      return true;
303
    if (data.label.trim().isEmpty && data.value.trim().isEmpty)
304 305 306 307
      return true;
    return false;
  }

308 309
  // Returns a rect that is entirely on screen, or null if it is too far off.
  //
310 311 312
  // Given a pixel buffer based on the physical window size, can we actually
  // get all the data from this node? allow a small delta overlap before
  // culling the node.
313
  bool _isNodeOffScreen(Rect paintBounds, ui.FlutterView window) {
314 315
    return paintBounds.top < -50.0
      || paintBounds.left <  -50.0
316 317
      || paintBounds.bottom > (window.physicalSize.height * window.devicePixelRatio) + 50.0
      || paintBounds.right > (window.physicalSize.width * window.devicePixelRatio)  + 50.0;
318 319
  }

320 321 322 323 324 325 326 327 328 329 330 331
  @override
  String get description => 'Text contrast should follow WCAG guidelines';
}

/// A guideline which verifies that all elements specified by [finder]
/// meet minimum contrast levels.
class CustomMinimumContrastGuideline extends AccessibilityGuideline {
  /// Creates a custom guideline which verifies that all elements specified
  /// by [finder] meet minimum contrast levels.
  ///
  /// An optional description string can be given using the [description] parameter.
  const CustomMinimumContrastGuideline({
332
    required this.finder,
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
    this.minimumRatio = 4.5,
    this.tolerance = 0.01,
    String description = 'Contrast should follow custom guidelines',
  }) : _description = description;

  /// The minimum contrast ratio allowed.
  ///
  /// Defaults to 4.5, the minimum contrast
  /// ratio for normal text, defined by WCAG.
  /// See http://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html.
  final double minimumRatio;

  /// Tolerance for minimum contrast ratio.
  ///
  /// Any contrast ratio greater than [minimumRatio] or within a distance of [tolerance]
  /// from [minimumRatio] passes the test.
  /// Defaults to 0.01.
  final double tolerance;

  /// The [Finder] used to find a subset of elements.
  ///
  /// [finder] determines which subset of elements will be tested for
  /// contrast ratio.
  final Finder finder;

  final String _description;

  @override
  String get description => _description;

  @override
  Future<Evaluation> evaluate(WidgetTester tester) async {
    // Compute elements to be evaluated.

    final List<Element> elements = finder.evaluate().toList();

    // Obtain rendered image.

    final RenderView renderView = tester.binding.renderView;
372
    final OffsetLayer layer = renderView.debugLayer! as OffsetLayer;
373 374
    ui.Image? image;
    final ByteData byteData = (await tester.binding.runAsync<ByteData?>(() async {
375 376 377
      // Needs to be the same pixel ratio otherwise our dimensions won't match the
      // last transform layer.
      image = await layer.toImage(renderView.paintBounds, pixelRatio: 1 / tester.binding.window.devicePixelRatio);
378 379 380
      return image!.toByteData();
    }))!;
    assert(image != null);
381 382 383 384

    // How to evaluate a single element.

    Evaluation evaluateElement(Element element) {
385
      final RenderBox renderObject = element.renderObject! as RenderBox;
386 387 388 389 390 391 392 393 394 395

      final Rect originalPaintBounds = renderObject.paintBounds;

      final Rect inflatedPaintBounds = originalPaintBounds.inflate(4.0);

      final Rect paintBounds = Rect.fromPoints(
        renderObject.localToGlobal(inflatedPaintBounds.topLeft),
        renderObject.localToGlobal(inflatedPaintBounds.bottomRight),
      );

396
      final List<int> subset = _colorsWithinRect(byteData, paintBounds, image!.width, image!.height);
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414

      if (subset.isEmpty) {
        return const Evaluation.pass();
      }

      final _ContrastReport report = _ContrastReport(subset);
      final double contrastRatio = report.contrastRatio();

      if (report.isEmptyRect || contrastRatio >= minimumRatio - tolerance) {
        return const Evaluation.pass();
      } else {
        return Evaluation.fail(
            '$element:\nExpected contrast ratio of at least '
                '$minimumRatio but found ${contrastRatio.toStringAsFixed(2)} \n'
                'The computed light color was: ${report.lightColor}, '
                'The computed dark color was: ${report.darkColor}\n'
                '$description'
        );
415 416 417
      }
    }

418 419 420 421 422 423 424 425 426 427
    // Collate all evaluations into a final evaluation, then return.

    Evaluation result = const Evaluation.pass();

    for (final Element element in elements) {
      result = result + evaluateElement(element);
    }

    return result;
  }
428 429
}

430 431 432 433
/// A class that reports the contrast ratio of a part of the screen.
///
/// Commonly used in accessibility testing to obtain the contrast ratio of
/// text widgets and other types of widgets.
434
class _ContrastReport {
435 436 437 438
  /// Generates a contrast report given a list of colors.
  ///
  /// Given a list of integers [colors], each representing the color of a pixel
  /// on a part of the screen, generates a contrast ratio report.
Shi-Hao Hong's avatar
Shi-Hao Hong committed
439
  /// Each colors is given in ARGB format, as is the parameter for the
440 441 442 443 444
  /// constructor [Color].
  ///
  /// The contrast ratio of the most frequent light color and the most
  /// frequent dark color is calculated. Colors are divided into light and
  /// dark colors based on their lightness as an [HSLColor].
445 446
  factory _ContrastReport(List<int> colors) {
    final Map<int, int> colorHistogram = <int, int>{};
447
    for (final int color in colors) {
448
      colorHistogram[color] = (colorHistogram[color] ?? 0) + 1;
449
    }
450
    if (colorHistogram.length == 1) {
451 452
      final Color hslColor = Color(colorHistogram.keys.first);
      return _ContrastReport._(hslColor, hslColor);
453 454 455
    }
    // to determine the lighter and darker color, partition the colors
    // by lightness and then choose the mode from each group.
456
    double averageLightness = 0.0;
457
    for (final int color in colorHistogram.keys) {
458
      final HSLColor hslColor = HSLColor.fromColor(Color(color));
459
      averageLightness += hslColor.lightness * colorHistogram[color]!;
460 461 462
    }
    averageLightness /= colors.length;
    assert(averageLightness != double.nan);
463 464 465 466 467
    int lightColor = 0;
    int darkColor = 0;
    int lightCount = 0;
    int darkCount = 0;
    // Find the most frequently occurring light and dark color.
468
    for (final MapEntry<int, int> entry in colorHistogram.entries) {
469
      final HSLColor color = HSLColor.fromColor(Color(entry.key));
470
      final int count = entry.value;
471
      if (color.lightness <= averageLightness && count > darkCount) {
472 473
        darkColor = entry.key;
        darkCount = count;
474
      } else if (color.lightness > averageLightness && count > lightCount) {
475 476 477 478
        lightColor = entry.key;
        lightCount = count;
      }
    }
479 480 481 482 483 484 485 486 487 488 489
    // Depending on the number of colors present, return the correct contrast
    // report.
    if (lightCount > 0 && darkCount > 0) {
      return _ContrastReport._(Color(lightColor), Color(darkColor));
    } else if (lightCount > 0) {
      return _ContrastReport.singleColor(Color(lightColor));
    } else if (darkCount > 0) {
      return _ContrastReport.singleColor(Color(darkColor));
    } else {
      return const _ContrastReport.emptyRect();
    }
490 491
  }

492 493 494 495 496 497 498 499 500
  const _ContrastReport._(this.lightColor, this.darkColor)
      : isSingleColor = false,
        isEmptyRect = false;

  const _ContrastReport.singleColor(Color color)
      : lightColor = color,
        darkColor = color,
        isSingleColor = true,
        isEmptyRect = false;
501

502
  const _ContrastReport.emptyRect()
503 504
      : lightColor = _transparent,
        darkColor = _transparent,
505 506 507
        isSingleColor = false,
        isEmptyRect = true;

508 509
  static const Color _transparent = Color(0x00000000);

510 511
  /// The most frequently occurring light color. Uses [Colors.transparent] if
  /// the rectangle is empty.
512
  final Color lightColor;
513 514 515

  /// The most frequently occurring dark color. Uses [Colors.transparent] if
  /// the rectangle is empty.
516 517
  final Color darkColor;

518 519 520 521 522 523
  /// Whether the rectangle contains only one color.
  final bool isSingleColor;

  /// Whether the rectangle contains 0 pixels.
  final bool isEmptyRect;

524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540
  /// Computes the contrast ratio as defined by the WCAG.
  ///
  /// source: https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html
  double contrastRatio() {
    return (_luminance(lightColor) + 0.05) / (_luminance(darkColor) + 0.05);
  }

  /// Relative luminance calculation.
  ///
  /// Based on https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
  static double _luminance(Color color) {
    double r = color.red / 255.0;
    double g = color.green / 255.0;
    double b = color.blue / 255.0;
    if (r <= 0.03928)
      r /= 12.92;
    else
541
      r = math.pow((r + 0.055)/ 1.055, 2.4).toDouble();
542 543 544
    if (g <= 0.03928)
      g /= 12.92;
    else
545
      g = math.pow((g + 0.055)/ 1.055, 2.4).toDouble();
546 547 548
    if (b <= 0.03928)
      b /= 12.92;
    else
549
      b = math.pow((b + 0.055)/ 1.055, 2.4).toDouble();
550 551 552 553
    return 0.2126 * r + 0.7152 * g + 0.0722 * b;
  }
}

554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
/// Gives the colors of all pixels inside a given rectangle on the screen.
///
/// Given a [ByteData] object [data], which stores the color of each pixel
/// in row-first order, where each pixel is given in 4 bytes in RGBA order,
/// and [paintBounds], the rectangle,
/// and [width] and [height], the dimensions of the [ByteData],
/// returns a list of the colors of all pixels within the rectangle in
/// row-first order.
///
/// In the returned list, each color is represented as a 32-bit integer
/// in ARGB format, similar to the parameter for the [Color] constructor.
List<int> _colorsWithinRect(ByteData data, Rect paintBounds, int width, int height) {
  final Rect truePaintBounds = paintBounds.intersect(
    Rect.fromLTWH(0.0, 0.0, width.toDouble(), height.toDouble()),
  );

  final int leftX   = truePaintBounds.left.floor();
  final int rightX  = truePaintBounds.right.ceil();
  final int topY    = truePaintBounds.top.floor();
  final int bottomY = truePaintBounds.bottom.ceil();

  final List<int> buffer = <int>[];

  int _getPixel(ByteData data, int x, int y) {
    final int offset = (y * width + x) * 4;
    final int r = data.getUint8(offset);
    final int g = data.getUint8(offset + 1);
    final int b = data.getUint8(offset + 2);
    final int a = data.getUint8(offset + 3);
    final int color = (((a & 0xff) << 24) |
    ((r & 0xff) << 16) |
    ((g & 0xff) << 8)  |
    ((b & 0xff) << 0)) & 0xFFFFFFFF;
    return color;
  }

  for (int x = leftX; x < rightX; x ++) {
    for (int y = topY; y < bottomY; y ++) {
      buffer.add(_getPixel(data, x, y));
    }
  }

  return buffer;
}

599
/// A guideline which requires tappable semantic nodes a minimum size of 48 by 48.
600 601 602 603 604 605 606 607 608
///
/// See also:
///
///  * [Android tap target guidelines](https://support.google.com/accessibility/android/answer/7101858?hl=en).
const AccessibilityGuideline androidTapTargetGuideline = MinimumTapTargetGuideline._(
  Size(48.0, 48.0),
  'https://support.google.com/accessibility/android/answer/7101858?hl=en',
);

609
/// A guideline which requires tappable semantic nodes a minimum size of 44 by 44.
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628
///
/// See also:
///
///   * [iOS human interface guidelines](https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/adaptivity-and-layout/).
const AccessibilityGuideline iOSTapTargetGuideline = MinimumTapTargetGuideline._(
  Size(44.0, 44.0),
  'https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/adaptivity-and-layout/',
);

/// A guideline which requires text contrast to meet minimum values.
///
/// This guideline traverses the semantics tree looking for nodes with values or
/// labels that corresponds to a Text or Editable text widget. Given the
/// background pixels for the area around this widget, it performs a very naive
/// partitioning of the colors into "light" and "dark" and then chooses the most
/// frequently occurring color in each partition as a representative of the
/// foreground and background colors. The contrast ratio is calculated from
/// these colors according to the [WCAG](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html#contrast-ratiodef)
const AccessibilityGuideline textContrastGuideline = MinimumTextContrastGuideline._();
629 630 631 632

/// A guideline which enforces that all nodes with a tap or long press action
/// also have a label.
const AccessibilityGuideline labeledTapTargetGuideline = LabeledTapTargetGuideline._();