Skip to content

Commit 7e96d89

Browse files
authored
PointerEvent asserts device kinds (#105987)
1 parent 54bd629 commit 7e96d89

File tree

5 files changed

+39
-35
lines changed

5 files changed

+39
-35
lines changed

packages/flutter/lib/src/gestures/converter.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ class PointerEventConverter {
216216
return PointerPanZoomStartEvent(
217217
timeStamp: timeStamp,
218218
pointer: datum.pointerIdentifier,
219-
kind: kind,
220219
device: datum.device,
221220
position: position,
222221
embedderId: datum.embedderId,
@@ -230,7 +229,6 @@ class PointerEventConverter {
230229
return PointerPanZoomUpdateEvent(
231230
timeStamp: timeStamp,
232231
pointer: datum.pointerIdentifier,
233-
kind: kind,
234232
device: datum.device,
235233
position: position,
236234
pan: pan,
@@ -244,7 +242,6 @@ class PointerEventConverter {
244242
return PointerPanZoomEndEvent(
245243
timeStamp: timeStamp,
246244
pointer: datum.pointerIdentifier,
247-
kind: kind,
248245
device: datum.device,
249246
position: position,
250247
embedderId: datum.embedderId,

packages/flutter/lib/src/gestures/events.dart

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,10 @@ class PointerHoverEvent extends PointerEvent with _PointerEventDescription, _Cop
10351035
super.tilt,
10361036
super.synthesized,
10371037
super.embedderId,
1038-
}) : super(
1038+
}) : // Dart doesn't support comparing enums with == in const contexts yet.
1039+
// https://github.com/dart-lang/language/issues/1811
1040+
assert(!identical(kind, PointerDeviceKind.trackpad)),
1041+
super(
10391042
down: false,
10401043
pressure: 0.0,
10411044
);
@@ -1153,7 +1156,8 @@ class PointerEnterEvent extends PointerEvent with _PointerEventDescription, _Cop
11531156
super.down,
11541157
super.synthesized,
11551158
super.embedderId,
1156-
}) : super(
1159+
}) : assert(!identical(kind, PointerDeviceKind.trackpad)),
1160+
super(
11571161
pressure: 0.0,
11581162
);
11591163

@@ -1297,7 +1301,8 @@ class PointerExitEvent extends PointerEvent with _PointerEventDescription, _Copy
12971301
super.down,
12981302
super.synthesized,
12991303
super.embedderId,
1300-
}) : super(
1304+
}) : assert(!identical(kind, PointerDeviceKind.trackpad)),
1305+
super(
13011306
pressure: 0.0,
13021307
);
13031308

@@ -1432,7 +1437,8 @@ class PointerDownEvent extends PointerEvent with _PointerEventDescription, _Copy
14321437
super.orientation,
14331438
super.tilt,
14341439
super.embedderId,
1435-
}) : super(
1440+
}) : assert(!identical(kind, PointerDeviceKind.trackpad)),
1441+
super(
14361442
down: true,
14371443
distance: 0.0,
14381444
);
@@ -1548,7 +1554,8 @@ class PointerMoveEvent extends PointerEvent with _PointerEventDescription, _Copy
15481554
super.platformData,
15491555
super.synthesized,
15501556
super.embedderId,
1551-
}) : super(
1557+
}) : assert(!identical(kind, PointerDeviceKind.trackpad)),
1558+
super(
15521559
down: true,
15531560
distance: 0.0,
15541561
);
@@ -1662,7 +1669,8 @@ class PointerUpEvent extends PointerEvent with _PointerEventDescription, _CopyPo
16621669
super.orientation,
16631670
super.tilt,
16641671
super.embedderId,
1665-
}) : super(
1672+
}) : assert(!identical(kind, PointerDeviceKind.trackpad)),
1673+
super(
16661674
down: false,
16671675
);
16681676

@@ -1711,7 +1719,7 @@ abstract class PointerSignalEvent extends PointerEvent {
17111719
super.device,
17121720
super.position,
17131721
super.embedderId,
1714-
});
1722+
}) : assert(!identical(kind, PointerDeviceKind.trackpad));
17151723
}
17161724

17171725
mixin _CopyPointerScrollEvent on PointerEvent {
@@ -1849,9 +1857,9 @@ mixin _CopyPointerPanZoomStartEvent on PointerEvent {
18491857
bool? synthesized,
18501858
int? embedderId,
18511859
}) {
1860+
assert(kind == null || identical(kind, PointerDeviceKind.trackpad));
18521861
return PointerPanZoomStartEvent(
18531862
timeStamp: timeStamp ?? this.timeStamp,
1854-
kind: kind ?? this.kind,
18551863
device: device ?? this.device,
18561864
position: position ?? this.position,
18571865
embedderId: embedderId ?? this.embedderId,
@@ -1871,19 +1879,18 @@ class PointerPanZoomStartEvent extends PointerEvent with _PointerEventDescriptio
18711879
/// All of the arguments must be non-null.
18721880
const PointerPanZoomStartEvent({
18731881
super.timeStamp,
1874-
super.kind = PointerDeviceKind.mouse,
18751882
super.device,
18761883
super.pointer,
18771884
super.position,
18781885
super.embedderId,
18791886
super.synthesized,
18801887
}) : assert(timeStamp != null),
1881-
assert(kind != null),
18821888
assert(device != null),
18831889
assert(pointer != null),
18841890
assert(position != null),
18851891
assert(embedderId != null),
1886-
assert(synthesized != null);
1892+
assert(synthesized != null),
1893+
super(kind: PointerDeviceKind.trackpad);
18871894

18881895
@override
18891896
PointerPanZoomStartEvent transformed(Matrix4? transform) {
@@ -1953,9 +1960,9 @@ mixin _CopyPointerPanZoomUpdateEvent on PointerEvent {
19531960
double? scale,
19541961
double? rotation,
19551962
}) {
1963+
assert(kind == null || identical(kind, PointerDeviceKind.trackpad));
19561964
return PointerPanZoomUpdateEvent(
19571965
timeStamp: timeStamp ?? this.timeStamp,
1958-
kind: kind ?? this.kind,
19591966
device: device ?? this.device,
19601967
position: position ?? this.position,
19611968
embedderId: embedderId ?? this.embedderId,
@@ -1979,7 +1986,6 @@ class PointerPanZoomUpdateEvent extends PointerEvent with _PointerEventDescripti
19791986
/// All of the arguments must be non-null.
19801987
const PointerPanZoomUpdateEvent({
19811988
super.timeStamp,
1982-
super.kind = PointerDeviceKind.mouse,
19831989
super.device,
19841990
super.pointer,
19851991
super.position,
@@ -1990,7 +1996,6 @@ class PointerPanZoomUpdateEvent extends PointerEvent with _PointerEventDescripti
19901996
this.rotation = 0.0,
19911997
super.synthesized,
19921998
}) : assert(timeStamp != null),
1993-
assert(kind != null),
19941999
assert(device != null),
19952000
assert(pointer != null),
19962001
assert(position != null),
@@ -1999,7 +2004,9 @@ class PointerPanZoomUpdateEvent extends PointerEvent with _PointerEventDescripti
19992004
assert(panDelta != null),
20002005
assert(scale != null),
20012006
assert(rotation != null),
2002-
assert(synthesized != null);
2007+
assert(synthesized != null),
2008+
super(kind: PointerDeviceKind.trackpad);
2009+
20032010
@override
20042011
final Offset pan;
20052012
@override
@@ -2085,9 +2092,9 @@ mixin _CopyPointerPanZoomEndEvent on PointerEvent {
20852092
bool? synthesized,
20862093
int? embedderId,
20872094
}) {
2095+
assert(kind == null || identical(kind, PointerDeviceKind.trackpad));
20882096
return PointerPanZoomEndEvent(
20892097
timeStamp: timeStamp ?? this.timeStamp,
2090-
kind: kind ?? this.kind,
20912098
device: device ?? this.device,
20922099
position: position ?? this.position,
20932100
embedderId: embedderId ?? this.embedderId,
@@ -2107,19 +2114,18 @@ class PointerPanZoomEndEvent extends PointerEvent with _PointerEventDescription,
21072114
/// All of the arguments must be non-null.
21082115
const PointerPanZoomEndEvent({
21092116
super.timeStamp,
2110-
super.kind = PointerDeviceKind.mouse,
21112117
super.device,
21122118
super.pointer,
21132119
super.position,
21142120
super.embedderId,
21152121
super.synthesized,
21162122
}) : assert(timeStamp != null),
2117-
assert(kind != null),
21182123
assert(device != null),
21192124
assert(pointer != null),
21202125
assert(position != null),
21212126
assert(embedderId != null),
2122-
assert(synthesized != null);
2127+
assert(synthesized != null),
2128+
super(kind: PointerDeviceKind.trackpad);
21232129

21242130
@override
21252131
PointerPanZoomEndEvent transformed(Matrix4? transform) {
@@ -2224,7 +2230,8 @@ class PointerCancelEvent extends PointerEvent with _PointerEventDescription, _Co
22242230
super.orientation,
22252231
super.tilt,
22262232
super.embedderId,
2227-
}) : super(
2233+
}) : assert(!identical(kind, PointerDeviceKind.trackpad)),
2234+
super(
22282235
down: false,
22292236
pressure: 0.0,
22302237
);

packages/flutter/test/gestures/drag_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,7 +1507,7 @@ void main() {
15071507
didEndPan = true;
15081508
};
15091509

1510-
final TestPointer pointer = TestPointer(2);
1510+
final TestPointer pointer = TestPointer(2, PointerDeviceKind.trackpad);
15111511
final PointerPanZoomStartEvent start = pointer.panZoomStart(const Offset(10.0, 10.0));
15121512
pan.addPointerPanZoom(start);
15131513
competingPan.addPointerPanZoom(start);
@@ -1564,7 +1564,7 @@ void main() {
15641564
didEndPan = true;
15651565
};
15661566

1567-
final TestPointer panZoomPointer = TestPointer(2);
1567+
final TestPointer panZoomPointer = TestPointer(2, PointerDeviceKind.trackpad);
15681568
final TestPointer touchPointer = TestPointer(3);
15691569
final PointerPanZoomStartEvent start = panZoomPointer.panZoomStart(const Offset(10.0, 10.0));
15701570
pan.addPointerPanZoom(start);
@@ -1641,7 +1641,7 @@ testGesture('Touch drags should allow pointer pan/zooms to join them', (GestureT
16411641
didEndPan = true;
16421642
};
16431643

1644-
final TestPointer panZoomPointer = TestPointer(2);
1644+
final TestPointer panZoomPointer = TestPointer(2, PointerDeviceKind.trackpad);
16451645
final TestPointer touchPointer = TestPointer(3);
16461646
final PointerDownEvent touchDown = touchPointer.down(const Offset(20.0, 20.0));
16471647
pan.addPointer(touchDown);

packages/flutter/test/gestures/scale_test.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ void main() {
732732
didEndScale = true;
733733
};
734734

735-
final TestPointer pointer1 = TestPointer(2);
735+
final TestPointer pointer1 = TestPointer(2, PointerDeviceKind.trackpad);
736736

737737
final PointerPanZoomStartEvent start = pointer1.panZoomStart(Offset.zero);
738738
scale.addPointerPanZoom(start);
@@ -836,7 +836,7 @@ void main() {
836836

837837
final TestPointer touchPointer1 = TestPointer(2);
838838
final TestPointer touchPointer2 = TestPointer(3);
839-
final TestPointer panZoomPointer = TestPointer(4);
839+
final TestPointer panZoomPointer = TestPointer(4, PointerDeviceKind.trackpad);
840840

841841
final PointerPanZoomStartEvent panZoomStart = panZoomPointer.panZoomStart(Offset.zero);
842842
scale.addPointerPanZoom(panZoomStart);
@@ -985,7 +985,7 @@ void main() {
985985
drag.onStart = (DragStartDetails details) { log.add('drag-start'); };
986986
drag.onEnd = (DragEndDetails details) { log.add('drag-end'); };
987987

988-
final TestPointer pointer1 = TestPointer(2);
988+
final TestPointer pointer1 = TestPointer(2, PointerDeviceKind.trackpad);
989989

990990
final PointerPanZoomStartEvent down = pointer1.panZoomStart(const Offset(10.0, 10.0));
991991
scale.addPointerPanZoom(down);
@@ -1004,7 +1004,7 @@ void main() {
10041004
expect(log, equals(<String>['scale-start', 'scale-update']));
10051005
log.clear();
10061006

1007-
final TestPointer pointer2 = TestPointer(3);
1007+
final TestPointer pointer2 = TestPointer(3, PointerDeviceKind.trackpad);
10081008
final PointerPanZoomStartEvent down2 = pointer2.panZoomStart(const Offset(10.0, 20.0));
10091009
scale.addPointerPanZoom(down2);
10101010
drag.addPointerPanZoom(down2);
@@ -1033,7 +1033,7 @@ void main() {
10331033
// TODO(ianh): https://github.com/flutter/flutter/issues/11384
10341034
// In this case, we move fast, so that the scale wins. If we moved slowly,
10351035
// the horizontal drag would win, since it was added first.
1036-
final TestPointer pointer3 = TestPointer(4);
1036+
final TestPointer pointer3 = TestPointer(4, PointerDeviceKind.trackpad);
10371037
final PointerPanZoomStartEvent down3 = pointer3.panZoomStart(const Offset(30.0, 30.0));
10381038
scale.addPointerPanZoom(down3);
10391039
drag.addPointerPanZoom(down3);
@@ -1084,7 +1084,7 @@ void main() {
10841084
didEndScale = true;
10851085
};
10861086

1087-
final TestPointer pointer1 = TestPointer(2);
1087+
final TestPointer pointer1 = TestPointer(2, PointerDeviceKind.trackpad);
10881088

10891089
final PointerPanZoomStartEvent start = pointer1.panZoomStart(Offset.zero);
10901090
scale.addPointerPanZoom(start);

packages/flutter_test/lib/src/test_pointer.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,12 @@ class TestPointer {
314314
Duration timeStamp = Duration.zero
315315
}) {
316316
assert(!isPanZoomActive);
317+
assert(kind == PointerDeviceKind.trackpad);
317318
_location = location;
318319
_pan = Offset.zero;
319320
_isPanZoomActive = true;
320321
return PointerPanZoomStartEvent(
321322
timeStamp: timeStamp,
322-
kind: kind,
323323
device: _device,
324324
pointer: pointer,
325325
position: location,
@@ -341,12 +341,12 @@ class TestPointer {
341341
Duration timeStamp = Duration.zero,
342342
}) {
343343
assert(isPanZoomActive);
344+
assert(kind == PointerDeviceKind.trackpad);
344345
_location = location;
345346
final Offset panDelta = pan - _pan!;
346347
_pan = pan;
347348
return PointerPanZoomUpdateEvent(
348349
timeStamp: timeStamp,
349-
kind: kind,
350350
device: _device,
351351
pointer: pointer,
352352
position: location,
@@ -366,11 +366,11 @@ class TestPointer {
366366
Duration timeStamp = Duration.zero
367367
}) {
368368
assert(isPanZoomActive);
369+
assert(kind == PointerDeviceKind.trackpad);
369370
_isPanZoomActive = false;
370371
_pan = null;
371372
return PointerPanZoomEndEvent(
372373
timeStamp: timeStamp,
373-
kind: kind,
374374
device: _device,
375375
pointer: pointer,
376376
position: location!,

0 commit comments

Comments
 (0)