|
3 | 3 | // found in the LICENSE file.
|
4 | 4 |
|
5 | 5 | import 'package:flutter_test/flutter_test.dart';
|
| 6 | +import 'package:flutter/material.dart'; |
6 | 7 | import 'package:flutter/widgets.dart';
|
7 | 8 | import 'package:flutter/rendering.dart';
|
8 | 9 |
|
| 10 | +import 'semantics_tester.dart'; |
| 11 | + |
9 | 12 | Future<void> test(WidgetTester tester, double offset, { double anchor = 0.0 }) {
|
10 | 13 | return tester.pumpWidget(
|
11 | 14 | Directionality(
|
@@ -418,6 +421,113 @@ void main() {
|
418 | 421 | // It will be corrected after a auto scroll animation.
|
419 | 422 | expect(controller.offset, 800.0);
|
420 | 423 | });
|
| 424 | + |
| 425 | + group('SliverIgnorePointer - ', () { |
| 426 | + Widget _boilerPlate(Widget sliver) { |
| 427 | + return Localizations( |
| 428 | + locale: const Locale('en', 'us'), |
| 429 | + delegates: const <LocalizationsDelegate<dynamic>>[ |
| 430 | + DefaultWidgetsLocalizations.delegate, |
| 431 | + DefaultMaterialLocalizations.delegate, |
| 432 | + ], |
| 433 | + child: Directionality( |
| 434 | + textDirection: TextDirection.ltr, |
| 435 | + child: MediaQuery( |
| 436 | + data: const MediaQueryData(), |
| 437 | + child: CustomScrollView(slivers: <Widget>[sliver]) |
| 438 | + ) |
| 439 | + ) |
| 440 | + ); |
| 441 | + } |
| 442 | + |
| 443 | + testWidgets('ignores pointer events', (WidgetTester tester) async { |
| 444 | + final SemanticsTester semantics = SemanticsTester(tester); |
| 445 | + final List<String> events = <String>[]; |
| 446 | + await tester.pumpWidget(_boilerPlate( |
| 447 | + SliverIgnorePointer( |
| 448 | + ignoring: true, |
| 449 | + ignoringSemantics: false, |
| 450 | + sliver: SliverToBoxAdapter( |
| 451 | + child: GestureDetector( |
| 452 | + child: const Text('a'), |
| 453 | + onTap: () { |
| 454 | + events.add('tap'); |
| 455 | + }, |
| 456 | + ) |
| 457 | + ) |
| 458 | + ) |
| 459 | + )); |
| 460 | + expect(semantics.nodesWith(label: 'a'), hasLength(1)); |
| 461 | + await tester.tap(find.byType(GestureDetector)); |
| 462 | + expect(events, equals(<String>[])); |
| 463 | + }); |
| 464 | + |
| 465 | + testWidgets('ignores semantics', (WidgetTester tester) async { |
| 466 | + final SemanticsTester semantics = SemanticsTester(tester); |
| 467 | + final List<String> events = <String>[]; |
| 468 | + await tester.pumpWidget(_boilerPlate( |
| 469 | + SliverIgnorePointer( |
| 470 | + ignoring: false, |
| 471 | + ignoringSemantics: true, |
| 472 | + sliver: SliverToBoxAdapter( |
| 473 | + child: GestureDetector( |
| 474 | + child: const Text('a'), |
| 475 | + onTap: () { |
| 476 | + events.add('tap'); |
| 477 | + }, |
| 478 | + ) |
| 479 | + ) |
| 480 | + ) |
| 481 | + )); |
| 482 | + expect(semantics.nodesWith(label: 'a'), hasLength(0)); |
| 483 | + await tester.tap(find.byType(GestureDetector)); |
| 484 | + expect(events, equals(<String>['tap'])); |
| 485 | + }); |
| 486 | + |
| 487 | + testWidgets('ignores pointer events & semantics', (WidgetTester tester) async { |
| 488 | + final SemanticsTester semantics = SemanticsTester(tester); |
| 489 | + final List<String> events = <String>[]; |
| 490 | + await tester.pumpWidget(_boilerPlate( |
| 491 | + SliverIgnorePointer( |
| 492 | + ignoring: true, |
| 493 | + ignoringSemantics: true, |
| 494 | + sliver: SliverToBoxAdapter( |
| 495 | + child: GestureDetector( |
| 496 | + child: const Text('a'), |
| 497 | + onTap: () { |
| 498 | + events.add('tap'); |
| 499 | + }, |
| 500 | + ) |
| 501 | + ) |
| 502 | + ) |
| 503 | + )); |
| 504 | + expect(semantics.nodesWith(label: 'a'), hasLength(0)); |
| 505 | + await tester.tap(find.byType(GestureDetector)); |
| 506 | + expect(events, equals(<String>[])); |
| 507 | + }); |
| 508 | + |
| 509 | + testWidgets('ignores nothing', (WidgetTester tester) async { |
| 510 | + final SemanticsTester semantics = SemanticsTester(tester); |
| 511 | + final List<String> events = <String>[]; |
| 512 | + await tester.pumpWidget(_boilerPlate( |
| 513 | + SliverIgnorePointer( |
| 514 | + ignoring: false, |
| 515 | + ignoringSemantics: false, |
| 516 | + sliver: SliverToBoxAdapter( |
| 517 | + child: GestureDetector( |
| 518 | + child: const Text('a'), |
| 519 | + onTap: () { |
| 520 | + events.add('tap'); |
| 521 | + }, |
| 522 | + ) |
| 523 | + ) |
| 524 | + ) |
| 525 | + )); |
| 526 | + expect(semantics.nodesWith(label: 'a'), hasLength(1)); |
| 527 | + await tester.tap(find.byType(GestureDetector)); |
| 528 | + expect(events, equals(<String>['tap'])); |
| 529 | + }); |
| 530 | + }); |
421 | 531 | }
|
422 | 532 |
|
423 | 533 | bool isRight(Offset a, Offset b) => b.dx > a.dx;
|
|
0 commit comments