accessibility_test.dart 23.3 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'package:flutter/gestures.dart';
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  group('text contrast guideline', () {
    testWidgets('black text on white background - Text Widget - direct style', (WidgetTester tester) async {
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(_boilerplate(
        const Text(
          'this is a test',
          style: TextStyle(fontSize: 14.0, color: Colors.black),
        ),
      ));
      await expectLater(tester, meetsGuideline(textContrastGuideline));
      handle.dispose();
    });

    testWidgets('white text on black background - Text Widget - direct style', (WidgetTester tester) async {
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(_boilerplate(
26
        Container(
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
          width: 200.0,
          height: 200.0,
          color: Colors.black,
          child: const Text(
            'this is a test',
            style: TextStyle(fontSize: 14.0, color: Colors.white),
          ),
        ),
      ));
      await expectLater(tester, meetsGuideline(textContrastGuideline));
      handle.dispose();
    });

    testWidgets('black text on white background - Text Widget - inherited style', (WidgetTester tester) async {
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(_boilerplate(
43
        DefaultTextStyle(
44
          style: const TextStyle(fontSize: 14.0, color: Colors.black),
45
          child: Container(
46 47 48 49 50 51 52 53 54 55 56 57
            color: Colors.white,
            child: const Text('this is a test'),
          ),
        ),
      ));
      await expectLater(tester, meetsGuideline(textContrastGuideline));
      handle.dispose();
    });

    testWidgets('white text on black background - Text Widget - inherited style', (WidgetTester tester) async {
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(_boilerplate(
58
        DefaultTextStyle(
59
          style: const TextStyle(fontSize: 14.0, color: Colors.white),
60
          child: Container(
61 62 63 64 65 66 67 68 69 70 71 72 73
            width: 200.0,
            height: 200.0,
            color: Colors.black,
            child: const Text('this is a test'),
          ),
        ),
      ));
      await expectLater(tester, meetsGuideline(textContrastGuideline));
      handle.dispose();
    });

    testWidgets('Material text field - amber on amber', (WidgetTester tester) async {
      final SemanticsHandle handle = tester.ensureSemantics();
74 75 76
      await tester.pumpWidget(MaterialApp(
        home: Scaffold(
          body: Container(
77 78 79
            width: 200.0,
            height: 200.0,
            color: Colors.amberAccent,
80
            child: TextField(
81
              style: const TextStyle(color: Colors.amber),
82
              controller: TextEditingController(text: 'this is a test'),
83 84 85 86 87 88 89 90 91 92
            ),
          ),
        ),
      ));
      await expectLater(tester, doesNotMeetGuideline(textContrastGuideline));
      handle.dispose();
    });

    testWidgets('Material text field - default style', (WidgetTester tester) async {
      final SemanticsHandle handle = tester.ensureSemantics();
93 94 95
      await tester.pumpWidget(MaterialApp(
          home: Scaffold(
            body: Center(
96 97 98 99 100
              child: SizedBox(
                width: 100,
                child: TextField(
                  controller: TextEditingController(text: 'this is a test'),
                ),
101 102 103 104 105
              ),
            ),
          ),
        ),
      );
106
      await tester.idle();
107 108 109 110
      await expectLater(tester, meetsGuideline(textContrastGuideline));
      handle.dispose();
    });

111
    testWidgets('yellow text on yellow background fails with correct message', (WidgetTester tester) async {
112 113
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(_boilerplate(
114
        Container(
115 116 117 118 119 120 121 122 123 124 125 126
          width: 200.0,
          height: 200.0,
          color: Colors.yellow,
          child: const Text(
            'this is a test',
            style: TextStyle(fontSize: 14.0, color: Colors.yellowAccent),
          ),
        ),
      ));
      final Evaluation result = await textContrastGuideline.evaluate(tester);
      expect(result.passed, false);
      expect(result.reason,
127
        'SemanticsNode#4(Rect.fromLTRB(300.0, 200.0, 500.0, 400.0), label: "this is a test",'
128
        ' textDirection: ltr):\nExpected contrast ratio of at least '
129
        '4.5 but found 1.17 for a font size of 14.0. The '
130
        'computed light color was: Color(0xfffafafa), The computed dark color was:'
131
        ' Color(0xffffeb3b)\n'
132 133 134
        'See also: https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html');
      handle.dispose();
    });
135 136 137 138

    testWidgets('label without corresponding text is skipped', (WidgetTester tester) async {
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(_boilerplate(
139
        Semantics(
140 141
          label: 'This is not text',
          container: true,
142
          child: const SizedBox(
143 144
            width: 200.0,
            height: 200.0,
145
            child: Placeholder(),
146 147 148 149 150 151 152 153 154 155 156 157
          ),
        ),
      ));

      final Evaluation result = await textContrastGuideline.evaluate(tester);
      expect(result.passed, true);
      handle.dispose();
    });

    testWidgets('offscreen text is skipped', (WidgetTester tester) async {
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(_boilerplate(
158
        Stack(
159
          children: <Widget>[
160
            Positioned(
161
              left: -300.0,
162
              child: Container(
163 164 165 166 167 168 169 170
                width: 200.0,
                height: 200.0,
                color: Colors.yellow,
                child: const Text(
                  'this is a test',
                  style: TextStyle(fontSize: 14.0, color: Colors.yellowAccent),
                ),
              ),
171
            ),
172 173 174 175 176 177 178 179
          ],
        )
      ));

      final Evaluation result = await textContrastGuideline.evaluate(tester);
      expect(result.passed, true);
      handle.dispose();
    });
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202

    testWidgets('Disabled button is excluded from text contrast guideline', (WidgetTester tester) async {
      // Regression test https://github.com/flutter/flutter/issues/94428
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(
        _boilerplate(
          ElevatedButton(
            onPressed: null,
            child: Container(
              width: 200.0,
              height: 200.0,
              color: Colors.yellow,
              child: const Text(
                'this is a test',
                style: TextStyle(fontSize: 14.0, color: Colors.yellowAccent),
              ),
            ),
          ),
        )
      );
      await expectLater(tester, meetsGuideline(textContrastGuideline));
      handle.dispose();
    });
203 204
  });

205
  group('custom minimum contrast guideline', () {
206
    Widget _icon({IconData icon = Icons.search, required Color color, required Color background}) {
207 208 209 210 211 212 213
      return Container(
        padding: const EdgeInsets.all(8.0),
        color: background,
        child: Icon(icon, color: color),
      );
    }

214
    Widget _text({String text = 'Text', required Color color, required Color background}) {
215 216 217 218 219 220 221
      return Container(
        padding: const EdgeInsets.all(8.0),
        color: background,
        child: Text(text, style: TextStyle(color: color)),
      );
    }

222
    Widget _row(List<Widget> widgets) => _boilerplate(Row(children: widgets));
223 224 225 226 227 228 229

    final Finder _findIcons = find.byWidgetPredicate((Widget widget) => widget is Icon);
    final Finder _findTexts = find.byWidgetPredicate((Widget widget) => widget is Text);
    final Finder _findIconsAndTexts = find.byWidgetPredicate((Widget widget) => widget is Icon || widget is Text);

    testWidgets('Black icons on white background', (WidgetTester tester) async {
      await tester.pumpWidget(_row(<Widget>[
230 231
        _icon(color: Colors.black, background: Colors.white),
        _icon(color: Colors.black, background: Colors.white),
232 233 234 235 236 237 238
      ]));

      await expectLater(tester, meetsGuideline(CustomMinimumContrastGuideline(finder: _findIcons)));
    });

    testWidgets('Black icons on black background', (WidgetTester tester) async {
      await tester.pumpWidget(_row(<Widget>[
239 240
        _icon(color: Colors.black, background: Colors.black),
        _icon(color: Colors.black, background: Colors.black),
241 242 243 244 245 246 247
      ]));

      await expectLater(tester, doesNotMeetGuideline(CustomMinimumContrastGuideline(finder: _findIcons)));
    });

    testWidgets('White icons on black background ("dark mode")', (WidgetTester tester) async {
      await tester.pumpWidget(_row(<Widget>[
248 249
        _icon(color: Colors.white, background: Colors.black),
        _icon(color: Colors.white, background: Colors.black),
250 251 252 253 254 255 256
      ]));

      await expectLater(tester, meetsGuideline(CustomMinimumContrastGuideline(finder: _findIcons)));
    });

    testWidgets('Using different icons', (WidgetTester tester) async {
      await tester.pumpWidget(_row(<Widget>[
257 258 259 260
        _icon(color: Colors.black, background: Colors.white, icon: Icons.more_horiz),
        _icon(color: Colors.black, background: Colors.white, icon: Icons.description),
        _icon(color: Colors.black, background: Colors.white, icon: Icons.image),
        _icon(color: Colors.black, background: Colors.white, icon: Icons.beach_access),
261 262 263 264 265 266 267
      ]));

      await expectLater(tester, meetsGuideline(CustomMinimumContrastGuideline(finder: _findIcons)));
    });

    testWidgets('One invalid instance fails entire test', (WidgetTester tester) async {
      await tester.pumpWidget(_row(<Widget>[
268 269
        _icon(color: Colors.black, background: Colors.white),
        _icon(color: Colors.black, background: Colors.black),
270 271 272 273 274 275 276
      ]));

      await expectLater(tester, doesNotMeetGuideline(CustomMinimumContrastGuideline(finder: _findIcons)));
    });

    testWidgets('White on different colors, passing', (WidgetTester tester) async {
      await tester.pumpWidget(_row(<Widget>[
277 278 279 280
        _icon(color: Colors.white, background: Colors.red[800]!, icon: Icons.more_horiz),
        _icon(color: Colors.white, background: Colors.green[800]!, icon: Icons.description),
        _icon(color: Colors.white, background: Colors.blue[800]!, icon: Icons.image),
        _icon(color: Colors.white, background: Colors.purple[800]!, icon: Icons.beach_access),
281 282 283 284 285 286 287
      ]));

      await expectLater(tester, meetsGuideline(CustomMinimumContrastGuideline(finder: _findIcons)));
    });

    testWidgets('White on different colors, failing', (WidgetTester tester) async {
      await tester.pumpWidget(_row(<Widget>[
288 289 290 291
        _icon(color: Colors.white, background: Colors.red[200]!, icon: Icons.more_horiz),
        _icon(color: Colors.white, background: Colors.green[400]!, icon: Icons.description),
        _icon(color: Colors.white, background: Colors.blue[600]!, icon: Icons.image),
        _icon(color: Colors.white, background: Colors.purple[800]!, icon: Icons.beach_access),
292 293 294 295 296 297 298 299 300 301 302 303 304
      ]));

      await expectLater(tester, doesNotMeetGuideline(CustomMinimumContrastGuideline(finder: _findIcons)));
    });

    testWidgets('Absence of icons, passing', (WidgetTester tester) async {
      await tester.pumpWidget(_row(<Widget>[]));

      await expectLater(tester, meetsGuideline(CustomMinimumContrastGuideline(finder: _findIcons)));
    });

    testWidgets('Absence of icons, passing - 2nd test', (WidgetTester tester) async {
      await tester.pumpWidget(_row(<Widget>[
305 306
        _text(color: Colors.black, background: Colors.white),
        _text(color: Colors.black, background: Colors.black),
307 308 309 310 311 312 313
      ]));

      await expectLater(tester, meetsGuideline(CustomMinimumContrastGuideline(finder: _findIcons)));
    });

    testWidgets('Guideline ignores widgets of other types', (WidgetTester tester) async {
      await tester.pumpWidget(_row(<Widget>[
314 315 316 317
        _icon(color: Colors.black, background: Colors.white),
        _icon(color: Colors.black, background: Colors.white),
        _text(color: Colors.black, background: Colors.white),
        _text(color: Colors.black, background: Colors.black),
318 319 320 321 322 323 324 325 326
      ]));

      await expectLater(tester, meetsGuideline(CustomMinimumContrastGuideline(finder: _findIcons)));
      await expectLater(tester, doesNotMeetGuideline(CustomMinimumContrastGuideline(finder: _findTexts)));
      await expectLater(tester, doesNotMeetGuideline(CustomMinimumContrastGuideline(finder: _findIconsAndTexts)));
    });

    testWidgets('Custom minimum ratio - Icons', (WidgetTester tester) async {
      await tester.pumpWidget(_row(<Widget>[
327 328
        _icon(color: Colors.blue, background: Colors.white),
        _icon(color: Colors.black, background: Colors.white),
329 330 331 332 333 334 335 336
      ]));

      await expectLater(tester, doesNotMeetGuideline(CustomMinimumContrastGuideline(finder: _findIcons)));
      await expectLater(tester, meetsGuideline(CustomMinimumContrastGuideline(finder: _findIcons, minimumRatio: 3.0)));
    });

    testWidgets('Custom minimum ratio - Texts', (WidgetTester tester) async {
      await tester.pumpWidget(_row(<Widget>[
337 338
        _text(color: Colors.blue, background: Colors.white),
        _text(color: Colors.black, background: Colors.white),
339 340 341 342 343 344 345 346
      ]));

      await expectLater(tester, doesNotMeetGuideline(CustomMinimumContrastGuideline(finder: _findTexts)));
      await expectLater(tester, meetsGuideline(CustomMinimumContrastGuideline(finder: _findTexts, minimumRatio: 3.0)));
    });

    testWidgets('Custom minimum ratio - Different standards for icons and texts', (WidgetTester tester) async {
      await tester.pumpWidget(_row(<Widget>[
347 348 349 350
        _icon(color: Colors.blue, background: Colors.white),
        _icon(color: Colors.black, background: Colors.white),
        _text(color: Colors.blue, background: Colors.white),
        _text(color: Colors.black, background: Colors.white),
351 352 353 354 355 356 357 358
      ]));

      await expectLater(tester, doesNotMeetGuideline(CustomMinimumContrastGuideline(finder: _findIcons)));
      await expectLater(tester, meetsGuideline(CustomMinimumContrastGuideline(finder: _findTexts, minimumRatio: 3.0)));
    });

  });

359 360 361 362
  group('tap target size guideline', () {
    testWidgets('Tappable box at 48 by 48', (WidgetTester tester) async {
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(_boilerplate(
363
        SizedBox(
364 365
          width: 48.0,
          height: 48.0,
366
          child: GestureDetector(
367
            onTap: () { },
368 369 370 371 372 373 374 375 376 377
          ),
        ),
      ));
      await expectLater(tester, meetsGuideline(androidTapTargetGuideline));
      handle.dispose();
    });

    testWidgets('Tappable box at 47 by 48', (WidgetTester tester) async {
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(_boilerplate(
378
        SizedBox(
379 380
          width: 47.0,
          height: 48.0,
381
          child: GestureDetector(
382
            onTap: () { },
383 384 385 386 387 388 389 390 391 392
          ),
        ),
      ));
      await expectLater(tester, doesNotMeetGuideline(androidTapTargetGuideline));
      handle.dispose();
    });

    testWidgets('Tappable box at 48 by 47', (WidgetTester tester) async {
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(_boilerplate(
393
        SizedBox(
394 395
          width: 48.0,
          height: 47.0,
396
          child: GestureDetector(
397
            onTap: () { },
398 399 400 401 402 403 404 405 406 407
          ),
        ),
      ));
      await expectLater(tester, doesNotMeetGuideline(androidTapTargetGuideline));
      handle.dispose();
    });

    testWidgets('Tappable box at 48 by 48 shrunk by transform', (WidgetTester tester) async {
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(_boilerplate(
408
        Transform.scale(
409
          scale: 0.5, // should have new height of 24 by 24.
410
          child: SizedBox(
411 412
            width: 48.0,
            height: 48.0,
413
            child: GestureDetector(
414
              onTap: () { },
415 416 417 418 419 420 421 422 423 424 425
            ),
          ),
        ),
      ));
      await expectLater(tester, doesNotMeetGuideline(androidTapTargetGuideline));
      handle.dispose();
    });

    testWidgets('Too small tap target fails with the correct message', (WidgetTester tester) async {
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(_boilerplate(
426
        SizedBox(
427 428
          width: 48.0,
          height: 47.0,
429
          child: GestureDetector(
430
            onTap: () { },
431 432 433 434 435 436
          ),
        ),
      ));
      final Evaluation result = await androidTapTargetGuideline.evaluate(tester);
      expect(result.passed, false);
      expect(result.reason,
437
        'SemanticsNode#4(Rect.fromLTRB(376.0, 276.5, 424.0, 323.5), actions: [tap]): expected tap '
438 439 440 441
        'target size of at least Size(48.0, 48.0), but found Size(48.0, 47.0)\n'
        'See also: https://support.google.com/accessibility/android/answer/7101858?hl=en');
      handle.dispose();
    });
442 443 444

    testWidgets('Box that overlaps edge of window is skipped', (WidgetTester tester) async {
      final SemanticsHandle handle = tester.ensureSemantics();
445
      final Widget smallBox = SizedBox(
446 447
        width: 48.0,
        height: 47.0,
448
        child: GestureDetector(
449
          onTap: () { },
450 451 452
        ),
      );
      await tester.pumpWidget(
453 454
        MaterialApp(
          home: Stack(
455
            children: <Widget>[
456
              Positioned(
457 458 459 460 461 462 463 464 465 466 467 468 469
                left: 0.0,
                top: -1.0,
                child: smallBox,
              ),
            ],
          ),
        ),
      );

      final Evaluation overlappingTopResult = await androidTapTargetGuideline.evaluate(tester);
      expect(overlappingTopResult.passed, true);

      await tester.pumpWidget(
470 471
        MaterialApp(
          home: Stack(
472
            children: <Widget>[
473
              Positioned(
474 475 476 477 478 479 480 481 482 483 484 485 486
                left: -1.0,
                top: 0.0,
                child: smallBox,
              ),
            ],
          ),
        ),
      );

      final Evaluation overlappingLeftResult = await androidTapTargetGuideline.evaluate(tester);
      expect(overlappingLeftResult.passed, true);

      await tester.pumpWidget(
487 488
        MaterialApp(
          home: Stack(
489
            children: <Widget>[
490
              Positioned(
491 492 493 494 495 496 497 498 499 500 501 502
                bottom: -1.0,
                child: smallBox,
              ),
            ],
          ),
        ),
      );

      final Evaluation overlappingBottomResult = await androidTapTargetGuideline.evaluate(tester);
      expect(overlappingBottomResult.passed, true);

      await tester.pumpWidget(
503 504
        MaterialApp(
          home: Stack(
505
            children: <Widget>[
506
              Positioned(
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522
                right: -1.0,
                child: smallBox,
              ),
            ],
          ),
        ),
      );

      final Evaluation overlappingRightResult = await androidTapTargetGuideline.evaluate(tester);
      expect(overlappingRightResult.passed, true);
      handle.dispose();
    });

    testWidgets('Does not fail on mergedIntoParent child', (WidgetTester tester) async {
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(_boilerplate(
523 524
        MergeSemantics(
          child: Semantics(
525
            container: true,
526
            child: SizedBox(
527 528
              width: 50.0,
              height: 50.0,
529
              child: Semantics(
530
                container: true,
531
                child: GestureDetector(
532
                  onTap: () { },
533
                  child: const SizedBox(width: 4.0, height: 4.0),
534 535
                ),
              ),
536
            ),
537
          ),
538 539 540 541 542 543 544
        )
      ));

      final Evaluation overlappingRightResult = await androidTapTargetGuideline.evaluate(tester);
      expect(overlappingRightResult.passed, true);
      handle.dispose();
    });
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573

    testWidgets('Does not fail on links', (WidgetTester tester) async {
      Widget textWithLink() {
        return Builder(
          builder: (BuildContext context) {
            return RichText(
              text: TextSpan(
                children: <InlineSpan>[
                  const TextSpan(
                    text: 'See examples at ',
                  ),
                  TextSpan(
                    text: 'flutter repo',
                    recognizer: TapGestureRecognizer()
                      ..onTap = () { },
                  ),
                ],
              ),
            );
          },
        );
      }

      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(_boilerplate(textWithLink()));

      await expectLater(tester, meetsGuideline(androidTapTargetGuideline));
      handle.dispose();
    });
574
  });
575

576
  group('Labeled tappable node guideline', () {
577 578 579 580
    testWidgets('Passes when node is labeled', (WidgetTester tester) async {
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(_boilerplate(Semantics(
        container: true,
581
        onTap: () { },
582
        label: 'test',
583
        child: const SizedBox(width: 10.0, height: 10.0),
584 585 586 587 588 589 590 591 592
      )));
      final Evaluation result = await labeledTapTargetGuideline.evaluate(tester);
      expect(result.passed, true);
      handle.dispose();
    });
    testWidgets('Fails if long-press has no label', (WidgetTester tester) async {
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(_boilerplate(Semantics(
        container: true,
593
        onLongPress: () { },
594
        label: '',
595
        child: const SizedBox(width: 10.0, height: 10.0),
596 597 598 599 600 601 602 603 604 605
      )));
      final Evaluation result = await labeledTapTargetGuideline.evaluate(tester);
      expect(result.passed, false);
      handle.dispose();
    });

    testWidgets('Fails if tap has no label', (WidgetTester tester) async {
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(_boilerplate(Semantics(
        container: true,
606
        onTap: () { },
607
        label: '',
608
        child: const SizedBox(width: 10.0, height: 10.0),
609 610 611 612 613 614 615 616 617 618
      )));
      final Evaluation result = await labeledTapTargetGuideline.evaluate(tester);
      expect(result.passed, false);
      handle.dispose();
    });

    testWidgets('Passes if tap is merged into labeled node', (WidgetTester tester) async {
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(_boilerplate(Semantics(
        container: true,
619
        onLongPress: () { },
620 621 622 623 624 625 626 627 628 629 630 631
        label: '',
        child: Semantics(
          label: 'test',
          child: const SizedBox(width: 10.0, height: 10.0),
        ),
      )));
      final Evaluation result = await labeledTapTargetGuideline.evaluate(tester);
      expect(result.passed, true);
      handle.dispose();
    });
  });

632 633 634 635 636 637 638
  testWidgets('regression test for material widget', (WidgetTester tester) async {
    final SemanticsHandle handle = tester.ensureSemantics();
    await tester.pumpWidget(
      MaterialApp(
        theme: ThemeData.light(),
        home: Scaffold(
          backgroundColor: Colors.white,
639 640 641 642 643
          body: ElevatedButton(
            style: ElevatedButton.styleFrom(
              primary: const Color(0xFFFBBC04),
              elevation: 0,
            ),
644 645 646 647 648 649 650 651
            onPressed: () {},
            child: const Text('Button', style: TextStyle(color: Colors.black)),
        ),
      ),
    ));
    await expectLater(tester, meetsGuideline(textContrastGuideline));
    handle.dispose();
  });
652 653 654
}

Widget _boilerplate(Widget child) {
655 656
  return MaterialApp(
    home: Scaffold(body: Center(child: child)),
657 658
  );
}