Skip to content

Commit 796df06

Browse files
authored
Add API sample code to AccessibilityGuideline (#102161)
1 parent 9e4f265 commit 796df06

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

packages/flutter_test/lib/src/accessibility.dart

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,34 @@ class Evaluation {
5858

5959
/// An accessibility guideline describes a recommendation an application should
6060
/// meet to be considered accessible.
61+
///
62+
/// Use [meetsGuideline] matcher to test whether a screen meets the
63+
/// accessibility guideline.
64+
///
65+
/// {@tool snippet}
66+
///
67+
/// This sample demonstrates how to run an accessibility guideline in a unit
68+
/// test against a single screen.
69+
///
70+
/// ```dart
71+
/// testWidgets('HomePage meets androidTapTargetGuideline', (WidgetTester tester) async {
72+
/// final SemanticsHandle handle = tester.ensureSemantics();
73+
/// await tester.pumpWidget(const MaterialApp(home: HomePage()));
74+
/// await expectLater(tester, meetsGuideline(androidTapTargetGuideline));
75+
/// handle.dispose();
76+
/// });
77+
/// ```
78+
/// {@end-tool}
79+
///
80+
/// See also:
81+
/// * [androidTapTargetGuideline], which checks that tappable nodes have a
82+
/// minimum size of 48 by 48 pixels.
83+
/// * [iOSTapTargetGuideline], which checks that tappable nodes have a minimum
84+
/// size of 44 by 44 pixels.
85+
/// * [textContrastGuideline], which provides guidance for text contrast
86+
/// requirements specified by [WCAG](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html#contrast-ratiodef).
87+
/// * [labeledTapTargetGuideline], which enforces that all nodes with a tap or
88+
/// long press action also have a label.
6189
abstract class AccessibilityGuideline {
6290
/// A const constructor allows subclasses to be const.
6391
const AccessibilityGuideline();
@@ -73,6 +101,14 @@ abstract class AccessibilityGuideline {
73101
/// size.
74102
///
75103
/// Each platform defines its own guidelines for minimum tap areas.
104+
///
105+
/// See also:
106+
/// * [AccessibilityGuideline], which provides a general overview of
107+
/// accessibility guidelines and how to use them.
108+
/// * [androidTapTargetGuideline], which checks that tappable nodes have a
109+
/// minimum size of 48 by 48 pixels.
110+
/// * [iOSTapTargetGuideline], which checks that tappable nodes have a minimum
111+
/// size of 44 by 44 pixels.
76112
@visibleForTesting
77113
class MinimumTapTargetGuideline extends AccessibilityGuideline {
78114
/// Create a new [MinimumTapTargetGuideline].
@@ -161,6 +197,10 @@ class MinimumTapTargetGuideline extends AccessibilityGuideline {
161197

162198
/// A guideline which enforces that all nodes with a tap or long press action
163199
/// also have a label.
200+
///
201+
/// See also:
202+
/// * [AccessibilityGuideline], which provides a general overview of
203+
/// accessibility guidelines and how to use them.
164204
@visibleForTesting
165205
class LabeledTapTargetGuideline extends AccessibilityGuideline {
166206
const LabeledTapTargetGuideline._();
@@ -206,6 +246,10 @@ class LabeledTapTargetGuideline extends AccessibilityGuideline {
206246
///
207247
/// The guidelines are defined by the Web Content Accessibility Guidelines,
208248
/// http://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html.
249+
///
250+
/// See also:
251+
/// * [AccessibilityGuideline], which provides a general overview of
252+
/// accessibility guidelines and how to use them.
209253
@visibleForTesting
210254
class MinimumTextContrastGuideline extends AccessibilityGuideline {
211255
/// Create a new [MinimumTextContrastGuideline].
@@ -401,6 +445,10 @@ class MinimumTextContrastGuideline extends AccessibilityGuideline {
401445

402446
/// A guideline which verifies that all elements specified by [finder]
403447
/// meet minimum contrast levels.
448+
///
449+
/// See also:
450+
/// * [AccessibilityGuideline], which provides a general overview of
451+
/// accessibility guidelines and how to use them.
404452
class CustomMinimumContrastGuideline extends AccessibilityGuideline {
405453
/// Creates a custom guideline which verifies that all elements specified
406454
/// by [finder] meet minimum contrast levels.
@@ -617,6 +665,10 @@ Map<Color, int> _colorsWithinRect(
617665
/// See also:
618666
///
619667
/// * [Android tap target guidelines](https://support.google.com/accessibility/android/answer/7101858?hl=en).
668+
/// * [AccessibilityGuideline], which provides a general overview of
669+
/// accessibility guidelines and how to use them.
670+
/// * [iOSTapTargetGuideline], which checks that tappable nodes have a minimum
671+
/// size of 44 by 44 pixels.
620672
const AccessibilityGuideline androidTapTargetGuideline = MinimumTapTargetGuideline(
621673
size: Size(48.0, 48.0),
622674
link: 'https://support.google.com/accessibility/android/answer/7101858?hl=en',
@@ -627,7 +679,11 @@ const AccessibilityGuideline androidTapTargetGuideline = MinimumTapTargetGuideli
627679
///
628680
/// See also:
629681
///
630-
/// * [iOS human interface guidelines](https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/adaptivity-and-layout/).
682+
/// * [iOS human interface guidelines](https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/adaptivity-and-layout/).
683+
/// * [AccessibilityGuideline], which provides a general overview of
684+
/// accessibility guidelines and how to use them.
685+
/// * [androidTapTargetGuideline], which checks that tappable nodes have a
686+
/// minimum size of 48 by 48 pixels.
631687
const AccessibilityGuideline iOSTapTargetGuideline = MinimumTapTargetGuideline(
632688
size: Size(44.0, 44.0),
633689
link: 'https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/adaptivity-and-layout/',
@@ -642,8 +698,14 @@ const AccessibilityGuideline iOSTapTargetGuideline = MinimumTapTargetGuideline(
642698
/// frequently occurring color in each partition as a representative of the
643699
/// foreground and background colors. The contrast ratio is calculated from
644700
/// these colors according to the [WCAG](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html#contrast-ratiodef)
701+
///
702+
/// * [AccessibilityGuideline], which provides a general overview of
703+
/// accessibility guidelines and how to use them.
645704
const AccessibilityGuideline textContrastGuideline = MinimumTextContrastGuideline();
646705

647706
/// A guideline which enforces that all nodes with a tap or long press action
648707
/// also have a label.
708+
///
709+
/// * [AccessibilityGuideline], which provides a general overview of
710+
/// accessibility guidelines and how to use them.
649711
const AccessibilityGuideline labeledTapTargetGuideline = LabeledTapTargetGuideline._();

packages/flutter_test/lib/src/matchers.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ Matcher matchesSemantics({
663663
/// * [androidTapTargetGuideline], for Android minimum tappable area guidelines.
664664
/// * [iOSTapTargetGuideline], for iOS minimum tappable area guidelines.
665665
/// * [textContrastGuideline], for WCAG minimum text contrast guidelines.
666+
/// * [labeledTapTargetGuideline], for enforcing labels on tappable areas.
666667
AsyncMatcher meetsGuideline(AccessibilityGuideline guideline) {
667668
return _MatchesAccessibilityGuideline(guideline);
668669
}

0 commit comments

Comments
 (0)