@@ -59,9 +59,8 @@ typedef GestureVelocityTrackerBuilder = VelocityTracker Function(PointerEvent ev
59
59
/// consider using one of its subclasses to recognize specific types for drag
60
60
/// gestures.
61
61
///
62
- /// [DragGestureRecognizer] competes on pointer events of [kPrimaryButton]
63
- /// only when it has at least one non-null callback. If it has no callbacks, it
64
- /// is a no-op.
62
+ /// [DragGestureRecognizer] competes on pointer events only when it has at
63
+ /// least one non-null callback. If it has no callbacks, it is a no-op.
65
64
///
66
65
/// See also:
67
66
///
@@ -84,10 +83,14 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
84
83
this .dragStartBehavior = DragStartBehavior .start,
85
84
this .velocityTrackerBuilder = _defaultBuilder,
86
85
super .supportedDevices,
86
+ super .allowedButtonsFilter = _defaultButtonAcceptBehavior,
87
87
}) : assert (dragStartBehavior != null );
88
88
89
89
static VelocityTracker _defaultBuilder (PointerEvent event) => VelocityTracker .withKind (event.kind);
90
90
91
+ // Accept the input if, and only if, [kPrimaryButton] is pressed.
92
+ static bool _defaultButtonAcceptBehavior (int buttons) => buttons == kPrimaryButton;
93
+
91
94
/// Configure the behavior of offsets passed to [onStart] .
92
95
///
93
96
/// If set to [DragStartBehavior.start] , the [onStart] callback will be called
@@ -122,7 +125,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
122
125
///
123
126
/// See also:
124
127
///
125
- /// * [kPrimaryButton ] , the button this callback responds to .
128
+ /// * [allowedButtonsFilter ] , which decides which button will be allowed .
126
129
/// * [DragDownDetails] , which is passed as an argument to this callback.
127
130
GestureDragDownCallback ? onDown;
128
131
@@ -137,7 +140,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
137
140
///
138
141
/// See also:
139
142
///
140
- /// * [kPrimaryButton ] , the button this callback responds to .
143
+ /// * [allowedButtonsFilter ] , which decides which button will be allowed .
141
144
/// * [DragStartDetails] , which is passed as an argument to this callback.
142
145
GestureDragStartCallback ? onStart;
143
146
@@ -151,7 +154,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
151
154
///
152
155
/// See also:
153
156
///
154
- /// * [kPrimaryButton ] , the button this callback responds to .
157
+ /// * [allowedButtonsFilter ] , which decides which button will be allowed .
155
158
/// * [DragUpdateDetails] , which is passed as an argument to this callback.
156
159
GestureDragUpdateCallback ? onUpdate;
157
160
@@ -166,15 +169,15 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
166
169
///
167
170
/// See also:
168
171
///
169
- /// * [kPrimaryButton ] , the button this callback responds to .
172
+ /// * [allowedButtonsFilter ] , which decides which button will be allowed .
170
173
/// * [DragEndDetails] , which is passed as an argument to this callback.
171
174
GestureDragEndCallback ? onEnd;
172
175
173
176
/// The pointer that previously triggered [onDown] did not complete.
174
177
///
175
178
/// See also:
176
179
///
177
- /// * [kPrimaryButton ] , the button this callback responds to .
180
+ /// * [allowedButtonsFilter ] , which decides which button will be allowed .
178
181
GestureDragCancelCallback ? onCancel;
179
182
180
183
/// The minimum distance an input pointer drag must have moved to
@@ -251,18 +254,12 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
251
254
@override
252
255
bool isPointerAllowed (PointerEvent event) {
253
256
if (_initialButtons == null ) {
254
- switch (event.buttons) {
255
- case kPrimaryButton:
256
- if (onDown == null &&
257
- onStart == null &&
258
- onUpdate == null &&
259
- onEnd == null &&
260
- onCancel == null ) {
261
- return false ;
262
- }
263
- break ;
264
- default :
265
- return false ;
257
+ if (onDown == null &&
258
+ onStart == null &&
259
+ onUpdate == null &&
260
+ onEnd == null &&
261
+ onCancel == null ) {
262
+ return false ;
266
263
}
267
264
} else {
268
265
// There can be multiple drags simultaneously. Their effects are combined.
@@ -449,7 +446,6 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
449
446
}
450
447
451
448
void _checkDown () {
452
- assert (_initialButtons == kPrimaryButton);
453
449
if (onDown != null ) {
454
450
final DragDownDetails details = DragDownDetails (
455
451
globalPosition: _initialPosition.global,
@@ -460,7 +456,6 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
460
456
}
461
457
462
458
void _checkStart (Duration timestamp, int pointer) {
463
- assert (_initialButtons == kPrimaryButton);
464
459
if (onStart != null ) {
465
460
final DragStartDetails details = DragStartDetails (
466
461
sourceTimeStamp: timestamp,
@@ -479,7 +474,6 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
479
474
required Offset globalPosition,
480
475
Offset ? localPosition,
481
476
}) {
482
- assert (_initialButtons == kPrimaryButton);
483
477
if (onUpdate != null ) {
484
478
final DragUpdateDetails details = DragUpdateDetails (
485
479
sourceTimeStamp: sourceTimeStamp,
@@ -493,7 +487,6 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
493
487
}
494
488
495
489
void _checkEnd (int pointer) {
496
- assert (_initialButtons == kPrimaryButton);
497
490
if (onEnd == null ) {
498
491
return ;
499
492
}
@@ -530,7 +523,6 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
530
523
}
531
524
532
525
void _checkCancel () {
533
- assert (_initialButtons == kPrimaryButton);
534
526
if (onCancel != null ) {
535
527
invokeCallback <void >('onCancel' , onCancel! );
536
528
}
@@ -570,6 +562,7 @@ class VerticalDragGestureRecognizer extends DragGestureRecognizer {
570
562
)
571
563
super .kind,
572
564
super .supportedDevices,
565
+ super .allowedButtonsFilter,
573
566
});
574
567
575
568
@override
@@ -616,6 +609,7 @@ class HorizontalDragGestureRecognizer extends DragGestureRecognizer {
616
609
)
617
610
super .kind,
618
611
super .supportedDevices,
612
+ super .allowedButtonsFilter,
619
613
});
620
614
621
615
@override
@@ -654,6 +648,7 @@ class PanGestureRecognizer extends DragGestureRecognizer {
654
648
PanGestureRecognizer ({
655
649
super .debugOwner,
656
650
super .supportedDevices,
651
+ super .allowedButtonsFilter,
657
652
});
658
653
659
654
@override
0 commit comments