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

Adam Barth's avatar
Adam Barth committed
5
import 'package:flutter_test/flutter_test.dart';
6
import 'package:flutter/widgets.dart';
7
import 'package:flutter/rendering.dart';
8
import 'package:flutter/gestures.dart';
9 10

void main() {
11 12
  const Offset forcePressOffset = Offset(400.0, 50.0);

13
  testWidgets('Uncontested scrolls start immediately', (WidgetTester tester) async {
14 15 16 17
    bool didStartDrag = false;
    double updatedDragDelta;
    bool didEndDrag = false;

18
    final Widget widget = GestureDetector(
19
      onVerticalDragStart: (DragStartDetails details) {
20 21
        didStartDrag = true;
      },
22 23
      onVerticalDragUpdate: (DragUpdateDetails details) {
        updatedDragDelta = details.primaryDelta;
24
      },
25
      onVerticalDragEnd: (DragEndDetails details) {
26 27
        didEndDrag = true;
      },
28
      child: Container(
29
        color: const Color(0xFF00FF00),
30
      ),
31 32
    );

33
    await tester.pumpWidget(widget);
34 35 36 37
    expect(didStartDrag, isFalse);
    expect(updatedDragDelta, isNull);
    expect(didEndDrag, isFalse);

38
    const Offset firstLocation = Offset(10.0, 10.0);
39
    final TestGesture gesture = await tester.startGesture(firstLocation, pointer: 7);
40 41 42 43 44
    expect(didStartDrag, isTrue);
    didStartDrag = false;
    expect(updatedDragDelta, isNull);
    expect(didEndDrag, isFalse);

45
    const Offset secondLocation = Offset(10.0, 9.0);
46
    await gesture.moveTo(secondLocation);
47 48 49 50 51
    expect(didStartDrag, isFalse);
    expect(updatedDragDelta, -1.0);
    updatedDragDelta = null;
    expect(didEndDrag, isFalse);

52
    await gesture.up();
53 54 55 56 57
    expect(didStartDrag, isFalse);
    expect(updatedDragDelta, isNull);
    expect(didEndDrag, isTrue);
    didEndDrag = false;

58
    await tester.pumpWidget(Container());
59
  });
60

61
  testWidgets('Match two scroll gestures in succession', (WidgetTester tester) async {
62 63 64
    int gestureCount = 0;
    double dragDistance = 0.0;

65 66
    const Offset downLocation = Offset(10.0, 10.0);
    const Offset upLocation = Offset(10.0, 50.0); // must be far enough to be more than kTouchSlop
67

68
    final Widget widget = GestureDetector(
69
      dragStartBehavior: DragStartBehavior.down,
70 71
      onVerticalDragUpdate: (DragUpdateDetails details) { dragDistance += details.primaryDelta; },
      onVerticalDragEnd: (DragEndDetails details) { gestureCount += 1; },
72 73
      onHorizontalDragUpdate: (DragUpdateDetails details) { fail('gesture should not match'); },
      onHorizontalDragEnd: (DragEndDetails details) { fail('gesture should not match'); },
74
      child: Container(
75
        color: const Color(0xFF00FF00),
76
      ),
77
    );
78
    await tester.pumpWidget(widget);
79

80 81 82
    TestGesture gesture = await tester.startGesture(downLocation, pointer: 7);
    await gesture.moveTo(upLocation);
    await gesture.up();
83

84 85 86
    gesture = await tester.startGesture(downLocation, pointer: 7);
    await gesture.moveTo(upLocation);
    await gesture.up();
87

88
    expect(gestureCount, 2);
89
    expect(dragDistance, 40.0 * 2.0); // delta between down and up, twice
Adam Barth's avatar
Adam Barth committed
90

91
    await tester.pumpWidget(Container());
92
  });
93

94
  testWidgets('Pan doesn\'t crash', (WidgetTester tester) async {
95 96 97
    bool didStartPan = false;
    Offset panDelta;
    bool didEndPan = false;
98

99
    await tester.pumpWidget(
100
      GestureDetector(
101
        onPanStart: (DragStartDetails details) {
102 103
          didStartPan = true;
        },
104
        onPanUpdate: (DragUpdateDetails details) {
105
          panDelta = panDelta == null ? details.delta : panDelta + details.delta;
106
        },
107
        onPanEnd: (DragEndDetails details) {
108 109
          didEndPan = true;
        },
110
        child: Container(
111
          color: const Color(0xFF00FF00),
112 113
        ),
      ),
114
    );
115

116 117 118
    expect(didStartPan, isFalse);
    expect(panDelta, isNull);
    expect(didEndPan, isFalse);
119

120
    await tester.dragFrom(const Offset(10.0, 10.0), const Offset(20.0, 30.0));
121

122 123 124 125
    expect(didStartPan, isTrue);
    expect(panDelta.dx, 20.0);
    expect(panDelta.dy, 30.0);
    expect(didEndPan, isTrue);
126
  });
127

128
  testWidgets('Translucent', (WidgetTester tester) async {
129 130 131
    bool didReceivePointerDown;
    bool didTap;

132
    Future<void> pumpWidgetTree(HitTestBehavior behavior) {
133
      return tester.pumpWidget(
134
        Directionality(
135
          textDirection: TextDirection.ltr,
136
          child: Stack(
137
            children: <Widget>[
138
              Listener(
139 140 141
                onPointerDown: (_) {
                  didReceivePointerDown = true;
                },
142
                child: Container(
143 144 145 146 147
                  width: 100.0,
                  height: 100.0,
                  color: const Color(0xFF00FF00),
                ),
              ),
148
              Container(
149 150
                width: 100.0,
                height: 100.0,
151
                child: GestureDetector(
152 153 154 155 156 157 158 159 160
                  onTap: () {
                    didTap = true;
                  },
                  behavior: behavior,
                ),
              ),
            ],
          ),
        ),
161 162 163 164 165
      );
    }

    didReceivePointerDown = false;
    didTap = false;
166
    await pumpWidgetTree(null);
167
    await tester.tapAt(const Offset(10.0, 10.0));
168 169 170 171 172
    expect(didReceivePointerDown, isTrue);
    expect(didTap, isTrue);

    didReceivePointerDown = false;
    didTap = false;
173
    await pumpWidgetTree(HitTestBehavior.deferToChild);
174
    await tester.tapAt(const Offset(10.0, 10.0));
175 176 177 178 179
    expect(didReceivePointerDown, isTrue);
    expect(didTap, isFalse);

    didReceivePointerDown = false;
    didTap = false;
180
    await pumpWidgetTree(HitTestBehavior.opaque);
181
    await tester.tapAt(const Offset(10.0, 10.0));
182 183 184 185 186
    expect(didReceivePointerDown, isFalse);
    expect(didTap, isTrue);

    didReceivePointerDown = false;
    didTap = false;
187
    await pumpWidgetTree(HitTestBehavior.translucent);
188
    await tester.tapAt(const Offset(10.0, 10.0));
189 190 191
    expect(didReceivePointerDown, isTrue);
    expect(didTap, isTrue);

192
  });
193 194 195 196

  testWidgets('Empty', (WidgetTester tester) async {
    bool didTap = false;
    await tester.pumpWidget(
197 198
      Center(
        child: GestureDetector(
199 200 201
          onTap: () {
            didTap = true;
          },
202 203
        ),
      ),
204 205
    );
    expect(didTap, isFalse);
206
    await tester.tapAt(const Offset(10.0, 10.0));
207 208 209 210 211 212
    expect(didTap, isTrue);
  });

  testWidgets('Only container', (WidgetTester tester) async {
    bool didTap = false;
    await tester.pumpWidget(
213 214
      Center(
        child: GestureDetector(
215 216 217
          onTap: () {
            didTap = true;
          },
218
          child: Container(),
219 220
        ),
      ),
221 222
    );
    expect(didTap, isFalse);
223
    await tester.tapAt(const Offset(10.0, 10.0));
224 225
    expect(didTap, isFalse);
  });
226

227
  testWidgets('cache render object', (WidgetTester tester) async {
228
    final GestureTapCallback inputCallback = () { };
229 230

    await tester.pumpWidget(
231 232
      Center(
        child: GestureDetector(
233
          onTap: inputCallback,
234
          child: Container(),
235 236
        ),
      ),
237 238 239 240 241
    );

    final RenderSemanticsGestureHandler renderObj1 = tester.renderObject(find.byType(GestureDetector));

    await tester.pumpWidget(
242 243
      Center(
        child: GestureDetector(
244
          onTap: inputCallback,
245
          child: Container(),
246 247
        ),
      ),
248 249 250 251 252 253
    );

    final RenderSemanticsGestureHandler renderObj2 = tester.renderObject(find.byType(GestureDetector));

    expect(renderObj1, same(renderObj2));
  });
254 255 256 257 258 259 260 261

  testWidgets('Tap down occurs after kPressTimeout', (WidgetTester tester) async {
    int tapDown = 0;
    int tap = 0;
    int tapCancel = 0;
    int longPress = 0;

    await tester.pumpWidget(
262
      Container(
263
        alignment: Alignment.topLeft,
264
        child: Container(
265 266 267
          alignment: Alignment.center,
          height: 100.0,
          color: const Color(0xFF00FF00),
268
          child: GestureDetector(
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
            onTapDown: (TapDownDetails details) {
              tapDown += 1;
            },
            onTap: () {
              tap += 1;
            },
            onTapCancel: () {
              tapCancel += 1;
            },
            onLongPress: () {
              longPress += 1;
            },
          ),
        ),
      ),
    );

    // Pointer is dragged from the center of the 800x100 gesture detector
287
    // to a point (400,300) below it. This should never call onTap.
288
    Future<void> dragOut(Duration timeout) async {
289
      final TestGesture gesture = await tester.startGesture(const Offset(400.0, 50.0));
290 291
      // If the timeout is less than kPressTimeout the recognizer will not
      // trigger any callbacks. If the timeout is greater than kLongPressTimeout
292 293 294 295 296 297
      // then onTapDown, onLongPress, and onCancel will be called.
      await tester.pump(timeout);
      await gesture.moveTo(const Offset(400.0, 300.0));
      await gesture.up();
    }

298
    await dragOut(kPressTimeout * 0.5); // generates nothing
299
    expect(tapDown, 0);
300
    expect(tapCancel, 0);
301 302 303 304 305
    expect(tap, 0);
    expect(longPress, 0);

    await dragOut(kPressTimeout); // generates tapDown, tapCancel
    expect(tapDown, 1);
306
    expect(tapCancel, 1);
307 308 309 310 311
    expect(tap, 0);
    expect(longPress, 0);

    await dragOut(kLongPressTimeout); // generates tapDown, longPress, tapCancel
    expect(tapDown, 2);
312
    expect(tapCancel, 2);
313 314 315
    expect(tap, 0);
    expect(longPress, 1);
  });
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335

  testWidgets('Long Press Up Callback called after long press', (WidgetTester tester) async {
    int longPressUp = 0;

    await tester.pumpWidget(
      Container(
        alignment: Alignment.topLeft,
        child: Container(
          alignment: Alignment.center,
          height: 100.0,
          color: const Color(0xFF00FF00),
          child: GestureDetector(
            onLongPressUp: () {
              longPressUp += 1;
            },
          ),
        ),
      ),
    );

336
    Future<void> longPress(Duration timeout) async {
337 338 339 340 341
      final TestGesture gesture = await tester.startGesture(const Offset(400.0, 50.0));
      await tester.pump(timeout);
      await gesture.up();
    }

342
    await longPress(kLongPressTimeout + const Duration(seconds: 1)); // To make sure the time for long press has occurred
343 344
    expect(longPressUp, 1);
  });
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368

  testWidgets('Force Press Callback called after force press', (WidgetTester tester) async {
    int forcePressStart = 0;
    int forcePressPeaked = 0;
    int forcePressUpdate = 0;
    int forcePressEnded = 0;

    await tester.pumpWidget(
      Container(
        alignment: Alignment.topLeft,
        child: Container(
          alignment: Alignment.center,
          height: 100.0,
          color: const Color(0xFF00FF00),
          child: GestureDetector(
            onForcePressStart: (_) => forcePressStart += 1,
            onForcePressEnd: (_) => forcePressEnded += 1,
            onForcePressPeak: (_) => forcePressPeaked += 1,
            onForcePressUpdate: (_) => forcePressUpdate += 1,
          ),
        ),
      ),
    );
    const int pointerValue = 1;
369 370 371 372 373 374 375 376 377

    final TestGesture gesture = await tester.createGesture();
    await gesture.downWithCustomEvent(
      forcePressOffset,
      const PointerDownEvent(
        pointer: pointerValue,
        position: forcePressOffset,
        pressure: 0.0,
        pressureMax: 6.0,
378
        pressureMin: 0.0,
379 380 381
      ),
    );

382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
    await gesture.updateWithCustomEvent(const PointerMoveEvent(pointer: pointerValue, position: Offset(0.0, 0.0), pressure: 0.3, pressureMin: 0, pressureMax: 1));

    expect(forcePressStart, 0);
    expect(forcePressPeaked, 0);
    expect(forcePressUpdate, 0);
    expect(forcePressEnded, 0);

    await gesture.updateWithCustomEvent(const PointerMoveEvent(pointer: pointerValue, position: Offset(0.0, 0.0), pressure: 0.5, pressureMin: 0, pressureMax: 1));

    expect(forcePressStart, 1);
    expect(forcePressPeaked, 0);
    expect(forcePressUpdate, 1);
    expect(forcePressEnded, 0);

    await gesture.updateWithCustomEvent(const PointerMoveEvent(pointer: pointerValue, position: Offset(0.0, 0.0), pressure: 0.6, pressureMin: 0, pressureMax: 1));
    await gesture.updateWithCustomEvent(const PointerMoveEvent(pointer: pointerValue, position: Offset(0.0, 0.0), pressure: 0.7, pressureMin: 0, pressureMax: 1));
    await gesture.updateWithCustomEvent(const PointerMoveEvent(pointer: pointerValue, position: Offset(0.0, 0.0), pressure: 0.2, pressureMin: 0, pressureMax: 1));
    await gesture.updateWithCustomEvent(const PointerMoveEvent(pointer: pointerValue, position: Offset(0.0, 0.0), pressure: 0.3, pressureMin: 0, pressureMax: 1));

    expect(forcePressStart, 1);
    expect(forcePressPeaked, 0);
    expect(forcePressUpdate, 5);
    expect(forcePressEnded, 0);

    await gesture.updateWithCustomEvent(const PointerMoveEvent(pointer: pointerValue, position: Offset(0.0, 0.0), pressure: 0.9, pressureMin: 0, pressureMax: 1));

    expect(forcePressStart, 1);
    expect(forcePressPeaked, 1);
    expect(forcePressUpdate, 6);
    expect(forcePressEnded, 0);

    await gesture.up();

    expect(forcePressStart, 1);
    expect(forcePressPeaked, 1);
    expect(forcePressUpdate, 6);
    expect(forcePressEnded, 1);
  });

  testWidgets('Force Press Callback not called if long press triggered before force press', (WidgetTester tester) async {
    int forcePressStart = 0;
    int longPressTimes = 0;

    await tester.pumpWidget(
      Container(
        alignment: Alignment.topLeft,
        child: Container(
          alignment: Alignment.center,
          height: 100.0,
          color: const Color(0xFF00FF00),
          child: GestureDetector(
            onForcePressStart: (_) => forcePressStart += 1,
            onLongPress: () => longPressTimes += 1,
          ),
        ),
      ),
    );

    const int pointerValue = 1;
441 442 443 444 445 446 447 448 449 450 451
    const double maxPressure = 6.0;

    final TestGesture gesture = await tester.createGesture();

    await gesture.downWithCustomEvent(
      forcePressOffset,
      const PointerDownEvent(
        pointer: pointerValue,
        position: forcePressOffset,
        pressure: 0.0,
        pressureMax: maxPressure,
452
        pressureMin: 0.0,
453 454 455 456
      ),
    );

    await gesture.updateWithCustomEvent(const PointerMoveEvent(pointer: pointerValue, position: Offset(400.0, 50.0), pressure: 0.3, pressureMin: 0, pressureMax: maxPressure));
457 458 459 460 461 462 463 464 465 466 467

    expect(forcePressStart, 0);
    expect(longPressTimes, 0);

    // Trigger the long press.
    await tester.pump(kLongPressTimeout + const Duration(seconds: 1));

    expect(longPressTimes, 1);
    expect(forcePressStart, 0);

    // Failed attempt to trigger the force press.
468
    await gesture.updateWithCustomEvent(const PointerMoveEvent(pointer: pointerValue, position: Offset(400.0, 50.0), pressure: 0.5, pressureMin: 0, pressureMax: maxPressure));
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493

    expect(longPressTimes, 1);
    expect(forcePressStart, 0);
  });

  testWidgets('Force Press Callback not called if drag triggered before force press', (WidgetTester tester) async {
    int forcePressStart = 0;
    int horizontalDragStart = 0;

    await tester.pumpWidget(
      Container(
        alignment: Alignment.topLeft,
        child: Container(
          alignment: Alignment.center,
          height: 100.0,
          color: const Color(0xFF00FF00),
          child: GestureDetector(
            onForcePressStart: (_) => forcePressStart += 1,
            onHorizontalDragStart: (_) => horizontalDragStart += 1,
          ),
        ),
      ),
    );

    const int pointerValue = 1;
494 495 496 497 498 499 500 501 502 503

    final TestGesture gesture = await tester.createGesture();

    await gesture.downWithCustomEvent(
      forcePressOffset,
      const PointerDownEvent(
        pointer: pointerValue,
        position: forcePressOffset,
        pressure: 0.0,
        pressureMax: 6.0,
504
        pressureMin: 0.0,
505 506 507
      ),
    );

508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
    await gesture.updateWithCustomEvent(const PointerMoveEvent(pointer: pointerValue, position: Offset(0.0, 0.0), pressure: 0.3, pressureMin: 0, pressureMax: 1));

    expect(forcePressStart, 0);
    expect(horizontalDragStart, 0);

    // Trigger horizontal drag.
    await gesture.moveBy(const Offset(100, 0));

    expect(horizontalDragStart, 1);
    expect(forcePressStart, 0);

    // Failed attempt to trigger the force press.
    await gesture.updateWithCustomEvent(const PointerMoveEvent(pointer: pointerValue, position: Offset(0.0, 0.0), pressure: 0.5, pressureMin: 0, pressureMax: 1));

    expect(horizontalDragStart, 1);
    expect(forcePressStart, 0);
  });
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 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 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 599 600 601 602 603

  group('RawGestureDetectorState\'s debugFillProperties', () {
    testWidgets('when default', (WidgetTester tester) async {
      final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
      final GlobalKey key = GlobalKey();
      await tester.pumpWidget(RawGestureDetector(
        key: key,
      ));
      key.currentState.debugFillProperties(builder);

      final List<String> description = builder.properties
        .where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
        .map((DiagnosticsNode node) => node.toString())
        .toList();

      expect(description, <String>[
        'gestures: <none>',
      ]);
    });

    testWidgets('should show gestures, custom semantics and behavior', (WidgetTester tester) async {
      final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
      final GlobalKey key = GlobalKey();
      await tester.pumpWidget(RawGestureDetector(
        key: key,
        behavior: HitTestBehavior.deferToChild,
        gestures: <Type, GestureRecognizerFactory>{
          TapGestureRecognizer: GestureRecognizerFactoryWithHandlers<TapGestureRecognizer>(
            () => TapGestureRecognizer(),
            (TapGestureRecognizer recognizer) {
              recognizer.onTap = () {};
            },
          ),
          LongPressGestureRecognizer: GestureRecognizerFactoryWithHandlers<LongPressGestureRecognizer>(
            () => LongPressGestureRecognizer(),
            (LongPressGestureRecognizer recognizer) {
              recognizer.onLongPress = () {};
            },
          ),
        },
        child: Container(),
        semantics: _EmptySemanticsGestureDelegate(),
      ));
      key.currentState.debugFillProperties(builder);

      final List<String> description = builder.properties
        .where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
        .map((DiagnosticsNode node) => node.toString())
        .toList();

      expect(description, <String>[
        'gestures: tap, long press',
        'semantics: _EmptySemanticsGestureDelegate()',
        'behavior: deferToChild',
      ]);
    });

    testWidgets('should not show semantics when excludeFromSemantics is true', (WidgetTester tester) async {
      final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
      final GlobalKey key = GlobalKey();
      await tester.pumpWidget(RawGestureDetector(
        key: key,
        gestures: const <Type, GestureRecognizerFactory>{},
        child: Container(),
        semantics: _EmptySemanticsGestureDelegate(),
        excludeFromSemantics: true,
      ));
      key.currentState.debugFillProperties(builder);

      final List<String> description = builder.properties
        .where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
        .map((DiagnosticsNode node) => node.toString())
        .toList();

      expect(description, <String>[
        'gestures: <none>',
        'excludeFromSemantics: true',
      ]);
    });
604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701

    group('error control test', () {
      test('constructor redundant pan and scale', () {
        FlutterError error;
        try {
          GestureDetector(onScaleStart: (_) {}, onPanStart: (_) {},);
        } on FlutterError catch (e) {
          error = e;
        } finally {
          expect(error, isNotNull);
          expect(
            error.toStringDeep(),
            'FlutterError\n'
            '   Incorrect GestureDetector arguments.\n'
            '   Having both a pan gesture recognizer and a scale gesture\n'
            '   recognizer is redundant; scale is a superset of pan.\n'
            '   Just use the scale gesture recognizer.\n',
          );
          expect(error.diagnostics.last.level, DiagnosticLevel.hint);
          expect(
            error.diagnostics.last.toStringDeep(),
            equalsIgnoringHashCodes(
              'Just use the scale gesture recognizer.\n',
            )
          );
        }
      });

      test('constructur duplicate drag recognizer', () {
        FlutterError error;
        try {
          GestureDetector(
            onVerticalDragStart: (_) {},
            onHorizontalDragStart: (_) {},
            onPanStart: (_) {},
          );
        } on FlutterError catch (e) {
          error = e;
        } finally {
          expect(error, isNotNull);
          expect(
            error.toStringDeep(),
            'FlutterError\n'
            '   Incorrect GestureDetector arguments.\n'
            '   Simultaneously having a vertical drag gesture recognizer, a\n'
            '   horizontal drag gesture recognizer, and a pan gesture recognizer\n'
            '   will result in the pan gesture recognizer being ignored, since\n'
            '   the other two will catch all drags.\n',
          );
        }
      });

      testWidgets('replaceGestureRecognizers not during layout', (WidgetTester tester) async {
        final GlobalKey<RawGestureDetectorState> key = GlobalKey<RawGestureDetectorState>();
        await tester.pumpWidget(
          Directionality(
            textDirection: TextDirection.ltr,
            child: RawGestureDetector(
              key: key,
              child: Container(
                child: const Text('Text'),
              ),
            ),
          ),
        );
        FlutterError error;
        try {
          key.currentState.replaceGestureRecognizers(
            <Type, GestureRecognizerFactory>{});
        } on FlutterError catch (e) {
          error = e;
        } finally {
          expect(error, isNotNull);
          expect(error.diagnostics.last.level, DiagnosticLevel.hint);
          expect(
            error.diagnostics.last.toStringDeep(),
            equalsIgnoringHashCodes(
              'To set the gesture recognizers at other times, trigger a new\n'
              'build using setState() and provide the new gesture recognizers as\n'
              'constructor arguments to the corresponding RawGestureDetector or\n'
              'GestureDetector object.\n'
            ),
          );
          expect(
            error.toStringDeep(),
            'FlutterError\n'
            '   Unexpected call to replaceGestureRecognizers() method of\n'
            '   RawGestureDetectorState.\n'
            '   The replaceGestureRecognizers() method can only be called during\n'
            '   the layout phase.\n'
            '   To set the gesture recognizers at other times, trigger a new\n'
            '   build using setState() and provide the new gesture recognizers as\n'
            '   constructor arguments to the corresponding RawGestureDetector or\n'
            '   GestureDetector object.\n',
          );
        }
      });
    });
702 703 704 705 706 707 708
  });
}

class _EmptySemanticsGestureDelegate extends SemanticsGestureDelegate {
  @override
  void assignSemantics(RenderSemanticsGestureHandler renderObject) {
  }
709
}