@@ -455,6 +455,7 @@ class TestGesture {
455
455
/// Dispatch a pointer down event at the given `downLocation` , caching the
456
456
/// hit test result.
457
457
Future <void > down (Offset downLocation, { Duration timeStamp = Duration .zero }) async {
458
+ assert (_pointer.kind != PointerDeviceKind .trackpad, 'Trackpads are expected to send panZoomStart events, not down events.' );
458
459
return TestAsyncUtils .guard <void >(() async {
459
460
return _dispatcher (_pointer.down (downLocation, timeStamp: timeStamp));
460
461
});
@@ -463,6 +464,7 @@ class TestGesture {
463
464
/// Dispatch a pointer down event at the given `downLocation` , caching the
464
465
/// hit test result with a custom down event.
465
466
Future <void > downWithCustomEvent (Offset downLocation, PointerDownEvent event) async {
467
+ assert (_pointer.kind != PointerDeviceKind .trackpad, 'Trackpads are expected to send panZoomStart events, not down events' );
466
468
_pointer.setDownInfo (event, downLocation);
467
469
return TestAsyncUtils .guard <void >(() async {
468
470
return _dispatcher (event);
@@ -507,7 +509,15 @@ class TestGesture {
507
509
/// * [WidgetController.fling] , a method to simulate a fling.
508
510
Future <void > moveBy (Offset offset, { Duration timeStamp = Duration .zero }) {
509
511
assert (_pointer.location != null );
510
- return moveTo (_pointer.location! + offset, timeStamp: timeStamp);
512
+ if (_pointer.isPanZoomActive) {
513
+ return panZoomUpdate (
514
+ _pointer.location! ,
515
+ pan: (_pointer.pan ?? Offset .zero) + offset,
516
+ timeStamp: timeStamp
517
+ );
518
+ } else {
519
+ return moveTo (_pointer.location! + offset, timeStamp: timeStamp);
520
+ }
511
521
}
512
522
513
523
/// Send a move event moving the pointer to the given location.
@@ -521,6 +531,7 @@ class TestGesture {
521
531
/// It sends move events at a given frequency and it is useful when there are listeners involved.
522
532
/// * [WidgetController.fling] , a method to simulate a fling.
523
533
Future <void > moveTo (Offset location, { Duration timeStamp = Duration .zero }) {
534
+ assert (_pointer.kind != PointerDeviceKind .trackpad);
524
535
return TestAsyncUtils .guard <void >(() {
525
536
if (_pointer._isDown) {
526
537
return _dispatcher (_pointer.move (location, timeStamp: timeStamp));
@@ -530,19 +541,27 @@ class TestGesture {
530
541
});
531
542
}
532
543
533
- /// End the gesture by releasing the pointer.
544
+ /// End the gesture by releasing the pointer. For trackpad pointers this
545
+ /// will send a panZoomEnd event instead of an up event.
534
546
Future <void > up ({ Duration timeStamp = Duration .zero }) {
535
547
return TestAsyncUtils .guard <void >(() async {
536
- assert (_pointer._isDown);
537
- await _dispatcher (_pointer.up (timeStamp: timeStamp));
538
- assert (! _pointer._isDown);
548
+ if (_pointer.kind == PointerDeviceKind .trackpad) {
549
+ assert (_pointer._isPanZoomActive);
550
+ await _dispatcher (_pointer.panZoomEnd (timeStamp: timeStamp));
551
+ assert (! _pointer._isPanZoomActive);
552
+ } else {
553
+ assert (_pointer._isDown);
554
+ await _dispatcher (_pointer.up (timeStamp: timeStamp));
555
+ assert (! _pointer._isDown);
556
+ }
539
557
});
540
558
}
541
559
542
560
/// End the gesture by canceling the pointer (as would happen if the
543
561
/// system showed a modal dialog on top of the Flutter application,
544
562
/// for instance).
545
563
Future <void > cancel ({ Duration timeStamp = Duration .zero }) {
564
+ assert (_pointer.kind != PointerDeviceKind .trackpad, 'Trackpads do not send cancel events.' );
546
565
return TestAsyncUtils .guard <void >(() async {
547
566
assert (_pointer._isDown);
548
567
await _dispatcher (_pointer.cancel (timeStamp: timeStamp));
@@ -553,6 +572,7 @@ class TestGesture {
553
572
/// Dispatch a pointer pan zoom start event at the given `location` , caching the
554
573
/// hit test result.
555
574
Future <void > panZoomStart (Offset location, { Duration timeStamp = Duration .zero }) async {
575
+ assert (_pointer.kind == PointerDeviceKind .trackpad, 'Only trackpads can send PointerPanZoom events.' );
556
576
return TestAsyncUtils .guard <void >(() async {
557
577
return _dispatcher (_pointer.panZoomStart (location, timeStamp: timeStamp));
558
578
});
@@ -566,6 +586,7 @@ class TestGesture {
566
586
double rotation = 0 ,
567
587
Duration timeStamp = Duration .zero
568
588
}) async {
589
+ assert (_pointer.kind == PointerDeviceKind .trackpad, 'Only trackpads can send PointerPanZoom events.' );
569
590
return TestAsyncUtils .guard <void >(() async {
570
591
return _dispatcher (_pointer.panZoomUpdate (location,
571
592
pan: pan,
@@ -580,6 +601,7 @@ class TestGesture {
580
601
Future <void > panZoomEnd ({
581
602
Duration timeStamp = Duration .zero
582
603
}) async {
604
+ assert (_pointer.kind == PointerDeviceKind .trackpad, 'Only trackpads can send PointerPanZoom events.' );
583
605
return TestAsyncUtils .guard <void >(() async {
584
606
return _dispatcher (_pointer.panZoomEnd (
585
607
timeStamp: timeStamp
0 commit comments