@@ -59,9 +59,8 @@ typedef GestureVelocityTrackerBuilder = VelocityTracker Function(PointerEvent ev
5959/// consider using one of its subclasses to recognize specific types for drag
6060/// gestures.
6161///
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.
6564///
6665/// See also:
6766///
@@ -84,10 +83,14 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
8483 this .dragStartBehavior = DragStartBehavior .start,
8584 this .velocityTrackerBuilder = _defaultBuilder,
8685 super .supportedDevices,
86+ super .allowedButtonsFilter = _defaultButtonAcceptBehavior,
8787 }) : assert (dragStartBehavior != null );
8888
8989 static VelocityTracker _defaultBuilder (PointerEvent event) => VelocityTracker .withKind (event.kind);
9090
91+ // Accept the input if, and only if, [kPrimaryButton] is pressed.
92+ static bool _defaultButtonAcceptBehavior (int buttons) => buttons == kPrimaryButton;
93+
9194 /// Configure the behavior of offsets passed to [onStart] .
9295 ///
9396 /// If set to [DragStartBehavior.start] , the [onStart] callback will be called
@@ -122,7 +125,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
122125 ///
123126 /// See also:
124127 ///
125- /// * [kPrimaryButton ] , the button this callback responds to .
128+ /// * [allowedButtonsFilter ] , which decides which button will be allowed .
126129 /// * [DragDownDetails] , which is passed as an argument to this callback.
127130 GestureDragDownCallback ? onDown;
128131
@@ -137,7 +140,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
137140 ///
138141 /// See also:
139142 ///
140- /// * [kPrimaryButton ] , the button this callback responds to .
143+ /// * [allowedButtonsFilter ] , which decides which button will be allowed .
141144 /// * [DragStartDetails] , which is passed as an argument to this callback.
142145 GestureDragStartCallback ? onStart;
143146
@@ -151,7 +154,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
151154 ///
152155 /// See also:
153156 ///
154- /// * [kPrimaryButton ] , the button this callback responds to .
157+ /// * [allowedButtonsFilter ] , which decides which button will be allowed .
155158 /// * [DragUpdateDetails] , which is passed as an argument to this callback.
156159 GestureDragUpdateCallback ? onUpdate;
157160
@@ -166,15 +169,15 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
166169 ///
167170 /// See also:
168171 ///
169- /// * [kPrimaryButton ] , the button this callback responds to .
172+ /// * [allowedButtonsFilter ] , which decides which button will be allowed .
170173 /// * [DragEndDetails] , which is passed as an argument to this callback.
171174 GestureDragEndCallback ? onEnd;
172175
173176 /// The pointer that previously triggered [onDown] did not complete.
174177 ///
175178 /// See also:
176179 ///
177- /// * [kPrimaryButton ] , the button this callback responds to .
180+ /// * [allowedButtonsFilter ] , which decides which button will be allowed .
178181 GestureDragCancelCallback ? onCancel;
179182
180183 /// The minimum distance an input pointer drag must have moved to
@@ -251,18 +254,12 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
251254 @override
252255 bool isPointerAllowed (PointerEvent event) {
253256 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 ;
266263 }
267264 } else {
268265 // There can be multiple drags simultaneously. Their effects are combined.
@@ -449,7 +446,6 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
449446 }
450447
451448 void _checkDown () {
452- assert (_initialButtons == kPrimaryButton);
453449 if (onDown != null ) {
454450 final DragDownDetails details = DragDownDetails (
455451 globalPosition: _initialPosition.global,
@@ -460,7 +456,6 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
460456 }
461457
462458 void _checkStart (Duration timestamp, int pointer) {
463- assert (_initialButtons == kPrimaryButton);
464459 if (onStart != null ) {
465460 final DragStartDetails details = DragStartDetails (
466461 sourceTimeStamp: timestamp,
@@ -479,7 +474,6 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
479474 required Offset globalPosition,
480475 Offset ? localPosition,
481476 }) {
482- assert (_initialButtons == kPrimaryButton);
483477 if (onUpdate != null ) {
484478 final DragUpdateDetails details = DragUpdateDetails (
485479 sourceTimeStamp: sourceTimeStamp,
@@ -493,7 +487,6 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
493487 }
494488
495489 void _checkEnd (int pointer) {
496- assert (_initialButtons == kPrimaryButton);
497490 if (onEnd == null ) {
498491 return ;
499492 }
@@ -530,7 +523,6 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
530523 }
531524
532525 void _checkCancel () {
533- assert (_initialButtons == kPrimaryButton);
534526 if (onCancel != null ) {
535527 invokeCallback <void >('onCancel' , onCancel! );
536528 }
@@ -570,6 +562,7 @@ class VerticalDragGestureRecognizer extends DragGestureRecognizer {
570562 )
571563 super .kind,
572564 super .supportedDevices,
565+ super .allowedButtonsFilter,
573566 });
574567
575568 @override
@@ -616,6 +609,7 @@ class HorizontalDragGestureRecognizer extends DragGestureRecognizer {
616609 )
617610 super .kind,
618611 super .supportedDevices,
612+ super .allowedButtonsFilter,
619613 });
620614
621615 @override
@@ -654,6 +648,7 @@ class PanGestureRecognizer extends DragGestureRecognizer {
654648 PanGestureRecognizer ({
655649 super .debugOwner,
656650 super .supportedDevices,
651+ super .allowedButtonsFilter,
657652 });
658653
659654 @override
0 commit comments