Unverified Commit e74c15ca authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Deprecate `GestureDetector.kind` in favor of new `supportedDevices` (#81858)

parent 8694e19a
This diff is collapsed.
...@@ -15,8 +15,15 @@ import 'recognizer.dart'; ...@@ -15,8 +15,15 @@ import 'recognizer.dart';
class EagerGestureRecognizer extends OneSequenceGestureRecognizer { class EagerGestureRecognizer extends OneSequenceGestureRecognizer {
/// Create an eager gesture recognizer. /// Create an eager gesture recognizer.
/// ///
/// {@macro flutter.gestures.GestureRecognizer.kind} /// {@macro flutter.gestures.GestureRecognizer.supportedDevices}
EagerGestureRecognizer({ PointerDeviceKind? kind }) : super(kind: kind); EagerGestureRecognizer({
@Deprecated(
'Migrate to supportedDevices. '
'This feature was deprecated after v2.3.0-1.0.pre.',
)
PointerDeviceKind? kind,
Set<PointerDeviceKind>? supportedDevices,
}) : super(kind: kind, supportedDevices: supportedDevices);
@override @override
void addAllowedPointer(PointerDownEvent event) { void addAllowedPointer(PointerDownEvent event) {
......
...@@ -116,18 +116,27 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -116,18 +116,27 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
/// to 1.0 for values of `pressure` that are between `pressureMin` and /// to 1.0 for values of `pressure` that are between `pressureMin` and
/// `pressureMax`. /// `pressureMax`.
/// ///
/// {@macro flutter.gestures.GestureRecognizer.kind} /// {@macro flutter.gestures.GestureRecognizer.supportedDevices}
ForcePressGestureRecognizer({ ForcePressGestureRecognizer({
this.startPressure = 0.4, this.startPressure = 0.4,
this.peakPressure = 0.85, this.peakPressure = 0.85,
this.interpolation = _inverseLerp, this.interpolation = _inverseLerp,
Object? debugOwner, Object? debugOwner,
@Deprecated(
'Migrate to supportedDevices. '
'This feature was deprecated after v2.3.0-1.0.pre.',
)
PointerDeviceKind? kind, PointerDeviceKind? kind,
Set<PointerDeviceKind>? supportedDevices,
}) : assert(startPressure != null), }) : assert(startPressure != null),
assert(peakPressure != null), assert(peakPressure != null),
assert(interpolation != null), assert(interpolation != null),
assert(peakPressure > startPressure), assert(peakPressure > startPressure),
super(debugOwner: debugOwner, kind: kind); super(
debugOwner: debugOwner,
kind: kind,
supportedDevices: supportedDevices,
);
/// A pointer is in contact with the screen and has just pressed with a force /// A pointer is in contact with the screen and has just pressed with a force
/// exceeding the [startPressure]. Consequently, if there were other gesture /// exceeding the [startPressure]. Consequently, if there were other gesture
......
...@@ -242,15 +242,23 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer { ...@@ -242,15 +242,23 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
/// ///
/// The [duration] argument can be used to overwrite the default duration /// The [duration] argument can be used to overwrite the default duration
/// after which the long press will be recognized. /// after which the long press will be recognized.
///
/// {@macro flutter.gestures.GestureRecognizer.supportedDevices}
LongPressGestureRecognizer({ LongPressGestureRecognizer({
Duration? duration, Duration? duration,
double? postAcceptSlopTolerance, double? postAcceptSlopTolerance,
@Deprecated(
'Migrate to supportedDevices. '
'This feature was deprecated after v2.3.0-1.0.pre.',
)
PointerDeviceKind? kind, PointerDeviceKind? kind,
Set<PointerDeviceKind>? supportedDevices,
Object? debugOwner, Object? debugOwner,
}) : super( }) : super(
deadline: duration ?? kLongPressTimeout, deadline: duration ?? kLongPressTimeout,
postAcceptSlopTolerance: postAcceptSlopTolerance, postAcceptSlopTolerance: postAcceptSlopTolerance,
kind: kind, kind: kind,
supportedDevices: supportedDevices,
debugOwner: debugOwner, debugOwner: debugOwner,
); );
......
...@@ -63,15 +63,23 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -63,15 +63,23 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
/// ///
/// [dragStartBehavior] must not be null. /// [dragStartBehavior] must not be null.
/// ///
/// {@macro flutter.gestures.GestureRecognizer.kind} /// {@macro flutter.gestures.GestureRecognizer.supportedDevices}
DragGestureRecognizer({ DragGestureRecognizer({
Object? debugOwner, Object? debugOwner,
@Deprecated(
'Migrate to supportedDevices. '
'This feature was deprecated after v2.3.0-1.0.pre.',
)
PointerDeviceKind? kind, PointerDeviceKind? kind,
this.dragStartBehavior = DragStartBehavior.start, this.dragStartBehavior = DragStartBehavior.start,
this.velocityTrackerBuilder = _defaultBuilder, this.velocityTrackerBuilder = _defaultBuilder,
this.supportedDevices = _kAllPointerDeviceKinds Set<PointerDeviceKind>? supportedDevices,
}) : assert(dragStartBehavior != null), }) : assert(dragStartBehavior != null),
super(debugOwner: debugOwner, kind: kind); super(
debugOwner: debugOwner,
kind: kind,
supportedDevices: supportedDevices,
);
static VelocityTracker _defaultBuilder(PointerEvent event) => VelocityTracker.withKind(event.kind); static VelocityTracker _defaultBuilder(PointerEvent event) => VelocityTracker.withKind(event.kind);
/// Configure the behavior of offsets sent to [onStart]. /// Configure the behavior of offsets sent to [onStart].
...@@ -201,11 +209,6 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -201,11 +209,6 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
/// match the native behavior on that platform. /// match the native behavior on that platform.
GestureVelocityTrackerBuilder velocityTrackerBuilder; GestureVelocityTrackerBuilder velocityTrackerBuilder;
/// The device types that this gesture recognizer will accept drags from.
///
/// If not specified, defaults to all pointer kinds.
Set<PointerDeviceKind> supportedDevices;
_DragState _state = _DragState.ready; _DragState _state = _DragState.ready;
late OffsetPair _initialPosition; late OffsetPair _initialPosition;
late OffsetPair _pendingDragOffset; late OffsetPair _pendingDragOffset;
...@@ -236,9 +239,6 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -236,9 +239,6 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
@override @override
bool isPointerAllowed(PointerEvent event) { bool isPointerAllowed(PointerEvent event) {
if (!supportedDevices.contains(event.kind)) {
return false;
}
if (_initialButtons == null) { if (_initialButtons == null) {
switch (event.buttons) { switch (event.buttons) {
case kPrimaryButton: case kPrimaryButton:
...@@ -513,12 +513,20 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -513,12 +513,20 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
class VerticalDragGestureRecognizer extends DragGestureRecognizer { class VerticalDragGestureRecognizer extends DragGestureRecognizer {
/// Create a gesture recognizer for interactions in the vertical axis. /// Create a gesture recognizer for interactions in the vertical axis.
/// ///
/// {@macro flutter.gestures.GestureRecognizer.kind} /// {@macro flutter.gestures.GestureRecognizer.supportedDevices}
VerticalDragGestureRecognizer({ VerticalDragGestureRecognizer({
Object? debugOwner, Object? debugOwner,
@Deprecated(
'Migrate to supportedDevices. '
'This feature was deprecated after v2.3.0-1.0.pre.',
)
PointerDeviceKind? kind, PointerDeviceKind? kind,
Set<PointerDeviceKind> supportedDevices = _kAllPointerDeviceKinds, Set<PointerDeviceKind>? supportedDevices,
}) : super(debugOwner: debugOwner, kind: kind, supportedDevices: supportedDevices); }) : super(
debugOwner: debugOwner,
kind: kind,
supportedDevices: supportedDevices,
);
@override @override
bool isFlingGesture(VelocityEstimate estimate, PointerDeviceKind kind) { bool isFlingGesture(VelocityEstimate estimate, PointerDeviceKind kind) {
...@@ -542,10 +550,6 @@ class VerticalDragGestureRecognizer extends DragGestureRecognizer { ...@@ -542,10 +550,6 @@ class VerticalDragGestureRecognizer extends DragGestureRecognizer {
String get debugDescription => 'vertical drag'; String get debugDescription => 'vertical drag';
} }
const Set<PointerDeviceKind> _kAllPointerDeviceKinds = <PointerDeviceKind>{
...PointerDeviceKind.values,
};
/// Recognizes movement in the horizontal direction. /// Recognizes movement in the horizontal direction.
/// ///
/// Used for horizontal scrolling. /// Used for horizontal scrolling.
...@@ -559,12 +563,20 @@ const Set<PointerDeviceKind> _kAllPointerDeviceKinds = <PointerDeviceKind>{ ...@@ -559,12 +563,20 @@ const Set<PointerDeviceKind> _kAllPointerDeviceKinds = <PointerDeviceKind>{
class HorizontalDragGestureRecognizer extends DragGestureRecognizer { class HorizontalDragGestureRecognizer extends DragGestureRecognizer {
/// Create a gesture recognizer for interactions in the horizontal axis. /// Create a gesture recognizer for interactions in the horizontal axis.
/// ///
/// {@macro flutter.gestures.GestureRecognizer.kind} /// {@macro flutter.gestures.GestureRecognizer.supportedDevices}
HorizontalDragGestureRecognizer({ HorizontalDragGestureRecognizer({
Object? debugOwner, Object? debugOwner,
@Deprecated(
'Migrate to supportedDevices. '
'This feature was deprecated after v2.3.0-1.0.pre.',
)
PointerDeviceKind? kind, PointerDeviceKind? kind,
Set<PointerDeviceKind> supportedDevices = _kAllPointerDeviceKinds, Set<PointerDeviceKind>? supportedDevices,
}) : super(debugOwner: debugOwner, kind: kind, supportedDevices: supportedDevices); }) : super(
debugOwner: debugOwner,
kind: kind,
supportedDevices: supportedDevices,
);
@override @override
bool isFlingGesture(VelocityEstimate estimate, PointerDeviceKind kind) { bool isFlingGesture(VelocityEstimate estimate, PointerDeviceKind kind) {
......
...@@ -199,10 +199,21 @@ abstract class MultiDragPointerState { ...@@ -199,10 +199,21 @@ abstract class MultiDragPointerState {
/// start after a long-press gesture. /// start after a long-press gesture.
abstract class MultiDragGestureRecognizer<T extends MultiDragPointerState> extends GestureRecognizer { abstract class MultiDragGestureRecognizer<T extends MultiDragPointerState> extends GestureRecognizer {
/// Initialize the object. /// Initialize the object.
///
/// {@macro flutter.gestures.GestureRecognizer.supportedDevices}
MultiDragGestureRecognizer({ MultiDragGestureRecognizer({
required Object? debugOwner, required Object? debugOwner,
@Deprecated(
'Migrate to supportedDevices. '
'This feature was deprecated after v2.3.0-1.0.pre.',
)
PointerDeviceKind? kind, PointerDeviceKind? kind,
}) : super(debugOwner: debugOwner, kind: kind); Set<PointerDeviceKind>? supportedDevices,
}) : super(
debugOwner: debugOwner,
kind: kind,
supportedDevices: supportedDevices,
);
/// Called when this class recognizes the start of a drag gesture. /// Called when this class recognizes the start of a drag gesture.
/// ///
...@@ -348,10 +359,21 @@ class _ImmediatePointerState extends MultiDragPointerState { ...@@ -348,10 +359,21 @@ class _ImmediatePointerState extends MultiDragPointerState {
/// start after a long-press gesture. /// start after a long-press gesture.
class ImmediateMultiDragGestureRecognizer extends MultiDragGestureRecognizer<_ImmediatePointerState> { class ImmediateMultiDragGestureRecognizer extends MultiDragGestureRecognizer<_ImmediatePointerState> {
/// Create a gesture recognizer for tracking multiple pointers at once. /// Create a gesture recognizer for tracking multiple pointers at once.
///
/// {@macro flutter.gestures.GestureRecognizer.supportedDevices}
ImmediateMultiDragGestureRecognizer({ ImmediateMultiDragGestureRecognizer({
Object? debugOwner, Object? debugOwner,
@Deprecated(
'Migrate to supportedDevices. '
'This feature was deprecated after v2.3.0-1.0.pre.',
)
PointerDeviceKind? kind, PointerDeviceKind? kind,
}) : super(debugOwner: debugOwner, kind: kind); Set<PointerDeviceKind>? supportedDevices,
}) : super(
debugOwner: debugOwner,
kind: kind,
supportedDevices: supportedDevices,
);
@override @override
_ImmediatePointerState createNewPointerState(PointerDownEvent event) { _ImmediatePointerState createNewPointerState(PointerDownEvent event) {
...@@ -397,10 +419,21 @@ class _HorizontalPointerState extends MultiDragPointerState { ...@@ -397,10 +419,21 @@ class _HorizontalPointerState extends MultiDragPointerState {
class HorizontalMultiDragGestureRecognizer extends MultiDragGestureRecognizer<_HorizontalPointerState> { class HorizontalMultiDragGestureRecognizer extends MultiDragGestureRecognizer<_HorizontalPointerState> {
/// Create a gesture recognizer for tracking multiple pointers at once /// Create a gesture recognizer for tracking multiple pointers at once
/// but only if they first move horizontally. /// but only if they first move horizontally.
///
/// {@macro flutter.gestures.GestureRecognizer.supportedDevices}
HorizontalMultiDragGestureRecognizer({ HorizontalMultiDragGestureRecognizer({
Object? debugOwner, Object? debugOwner,
@Deprecated(
'Migrate to supportedDevices. '
'This feature was deprecated after v2.3.0-1.0.pre.',
)
PointerDeviceKind? kind, PointerDeviceKind? kind,
}) : super(debugOwner: debugOwner, kind: kind); Set<PointerDeviceKind>? supportedDevices,
}) : super(
debugOwner: debugOwner,
kind: kind,
supportedDevices: supportedDevices,
);
@override @override
_HorizontalPointerState createNewPointerState(PointerDownEvent event) { _HorizontalPointerState createNewPointerState(PointerDownEvent event) {
...@@ -446,10 +479,21 @@ class _VerticalPointerState extends MultiDragPointerState { ...@@ -446,10 +479,21 @@ class _VerticalPointerState extends MultiDragPointerState {
class VerticalMultiDragGestureRecognizer extends MultiDragGestureRecognizer<_VerticalPointerState> { class VerticalMultiDragGestureRecognizer extends MultiDragGestureRecognizer<_VerticalPointerState> {
/// Create a gesture recognizer for tracking multiple pointers at once /// Create a gesture recognizer for tracking multiple pointers at once
/// but only if they first move vertically. /// but only if they first move vertically.
///
/// {@macro flutter.gestures.GestureRecognizer.supportedDevices}
VerticalMultiDragGestureRecognizer({ VerticalMultiDragGestureRecognizer({
Object? debugOwner, Object? debugOwner,
@Deprecated(
'Migrate to supportedDevices. '
'This feature was deprecated after v2.3.0-1.0.pre.',
)
PointerDeviceKind? kind, PointerDeviceKind? kind,
}) : super(debugOwner: debugOwner, kind: kind); Set<PointerDeviceKind>? supportedDevices,
}) : super(
debugOwner: debugOwner,
kind: kind,
supportedDevices: supportedDevices,
);
@override @override
_VerticalPointerState createNewPointerState(PointerDownEvent event) { _VerticalPointerState createNewPointerState(PointerDownEvent event) {
...@@ -548,12 +592,23 @@ class DelayedMultiDragGestureRecognizer extends MultiDragGestureRecognizer<_Dela ...@@ -548,12 +592,23 @@ class DelayedMultiDragGestureRecognizer extends MultiDragGestureRecognizer<_Dela
/// remain in the same place for [delay] (up to [kTouchSlop]). The [delay] /// remain in the same place for [delay] (up to [kTouchSlop]). The [delay]
/// defaults to [kLongPressTimeout] to match [LongPressGestureRecognizer] but /// defaults to [kLongPressTimeout] to match [LongPressGestureRecognizer] but
/// can be changed for specific behaviors. /// can be changed for specific behaviors.
///
/// {@macro flutter.gestures.GestureRecognizer.supportedDevices}
DelayedMultiDragGestureRecognizer({ DelayedMultiDragGestureRecognizer({
this.delay = kLongPressTimeout, this.delay = kLongPressTimeout,
Object? debugOwner, Object? debugOwner,
@Deprecated(
'Migrate to supportedDevices. '
'This feature was deprecated after v2.3.0-1.0.pre.',
)
PointerDeviceKind? kind, PointerDeviceKind? kind,
Set<PointerDeviceKind>? supportedDevices,
}) : assert(delay != null), }) : assert(delay != null),
super(debugOwner: debugOwner, kind: kind); super(
debugOwner: debugOwner,
kind: kind,
supportedDevices: supportedDevices,
);
/// The amount of time the pointer must remain in the same place for the drag /// The amount of time the pointer must remain in the same place for the drag
/// to be recognized. /// to be recognized.
......
...@@ -113,11 +113,20 @@ class _TapTracker { ...@@ -113,11 +113,20 @@ class _TapTracker {
class DoubleTapGestureRecognizer extends GestureRecognizer { class DoubleTapGestureRecognizer extends GestureRecognizer {
/// Create a gesture recognizer for double taps. /// Create a gesture recognizer for double taps.
/// ///
/// {@macro flutter.gestures.GestureRecognizer.kind} /// {@macro flutter.gestures.GestureRecognizer.supportedDevices}
DoubleTapGestureRecognizer({ DoubleTapGestureRecognizer({
Object? debugOwner, Object? debugOwner,
@Deprecated(
'Migrate to supportedDevices. '
'This feature was deprecated after v2.3.0-1.0.pre.',
)
PointerDeviceKind? kind, PointerDeviceKind? kind,
}) : super(debugOwner: debugOwner, kind: kind); Set<PointerDeviceKind>? supportedDevices,
}) : super(
debugOwner: debugOwner,
kind: kind,
supportedDevices: supportedDevices,
);
// Implementation notes: // Implementation notes:
// //
...@@ -456,11 +465,22 @@ class MultiTapGestureRecognizer extends GestureRecognizer { ...@@ -456,11 +465,22 @@ class MultiTapGestureRecognizer extends GestureRecognizer {
/// ///
/// The [longTapDelay] defaults to [Duration.zero], which means /// The [longTapDelay] defaults to [Duration.zero], which means
/// [onLongTapDown] is called immediately after [onTapDown]. /// [onLongTapDown] is called immediately after [onTapDown].
///
/// {@macro flutter.gestures.GestureRecognizer.supportedDevices}
MultiTapGestureRecognizer({ MultiTapGestureRecognizer({
this.longTapDelay = Duration.zero, this.longTapDelay = Duration.zero,
Object? debugOwner, Object? debugOwner,
@Deprecated(
'Migrate to supportedDevices. '
'This feature was deprecated after v2.3.0-1.0.pre.',
)
PointerDeviceKind? kind, PointerDeviceKind? kind,
}) : super(debugOwner: debugOwner, kind: kind); Set<PointerDeviceKind>? supportedDevices,
}) : super(
debugOwner: debugOwner,
kind: kind,
supportedDevices: supportedDevices,
);
/// A pointer that might cause a tap has contacted the screen at a particular /// A pointer that might cause a tap has contacted the screen at a particular
/// location. /// location.
......
...@@ -61,12 +61,21 @@ abstract class GestureRecognizer extends GestureArenaMember with DiagnosticableT ...@@ -61,12 +61,21 @@ abstract class GestureRecognizer extends GestureArenaMember with DiagnosticableT
/// The argument is optional and is only used for debug purposes (e.g. in the /// The argument is optional and is only used for debug purposes (e.g. in the
/// [toString] serialization). /// [toString] serialization).
/// ///
/// {@template flutter.gestures.GestureRecognizer.kind} /// {@template flutter.gestures.GestureRecognizer.supportedDevices}
/// It's possible to limit this recognizer to a specific [PointerDeviceKind] /// It's possible to limit this recognizer to a specific set of [PointerDeviceKind]s
/// by providing the optional [kind] argument. If [kind] is null, /// by providing the optional [supportedDevices] argument. If [supportedDevices] is null,
/// the recognizer will accept pointer events from all device kinds. /// the recognizer will accept pointer events from all device kinds.
/// {@endtemplate} /// {@endtemplate}
GestureRecognizer({ this.debugOwner, PointerDeviceKind? kind }) : _kindFilter = kind; GestureRecognizer({
this.debugOwner,
@Deprecated(
'Migrate to supportedDevices. '
'This feature was deprecated after v2.3.0-1.0.pre.',
)
PointerDeviceKind? kind,
Set<PointerDeviceKind>? supportedDevices,
}) : assert(kind == null || supportedDevices == null),
_supportedDevices = kind == null ? supportedDevices : <PointerDeviceKind>{ kind };
/// The recognizer's owner. /// The recognizer's owner.
/// ///
...@@ -74,9 +83,11 @@ abstract class GestureRecognizer extends GestureArenaMember with DiagnosticableT ...@@ -74,9 +83,11 @@ abstract class GestureRecognizer extends GestureArenaMember with DiagnosticableT
/// this gesture recognizer was created, to aid in debugging. /// this gesture recognizer was created, to aid in debugging.
final Object? debugOwner; final Object? debugOwner;
/// The kind of device that's allowed to be recognized. If null, events from /// The kind of devices that are allowed to be recognized as provided by
/// all device kinds will be tracked and recognized. /// `supportedDevices` in the constructor, or the currently deprecated `kind`.
final PointerDeviceKind? _kindFilter; /// These cannot both be set. If both are null, events from all device kinds will be
/// tracked and recognized.
final Set<PointerDeviceKind>? _supportedDevices;
/// Holds a mapping between pointer IDs and the kind of devices they are /// Holds a mapping between pointer IDs and the kind of devices they are
/// coming from. /// coming from.
...@@ -130,7 +141,7 @@ abstract class GestureRecognizer extends GestureArenaMember with DiagnosticableT ...@@ -130,7 +141,7 @@ abstract class GestureRecognizer extends GestureArenaMember with DiagnosticableT
bool isPointerAllowed(PointerDownEvent event) { bool isPointerAllowed(PointerDownEvent event) {
// Currently, it only checks for device kind. But in the future we could check // Currently, it only checks for device kind. But in the future we could check
// for other things e.g. mouse button. // for other things e.g. mouse button.
return _kindFilter == null || _kindFilter == event.kind; return _supportedDevices == null || _supportedDevices!.contains(event.kind);
} }
/// For a given pointer ID, returns the device kind associated with it. /// For a given pointer ID, returns the device kind associated with it.
...@@ -220,11 +231,20 @@ abstract class GestureRecognizer extends GestureArenaMember with DiagnosticableT ...@@ -220,11 +231,20 @@ abstract class GestureRecognizer extends GestureArenaMember with DiagnosticableT
abstract class OneSequenceGestureRecognizer extends GestureRecognizer { abstract class OneSequenceGestureRecognizer extends GestureRecognizer {
/// Initialize the object. /// Initialize the object.
/// ///
/// {@macro flutter.gestures.GestureRecognizer.kind} /// {@macro flutter.gestures.GestureRecognizer.supportedDevices}
OneSequenceGestureRecognizer({ OneSequenceGestureRecognizer({
Object? debugOwner, Object? debugOwner,
@Deprecated(
'Migrate to supportedDevices. '
'This feature was deprecated after v2.3.0-1.0.pre.',
)
PointerDeviceKind? kind, PointerDeviceKind? kind,
}) : super(debugOwner: debugOwner, kind: kind); Set<PointerDeviceKind>? supportedDevices,
}) : super(
debugOwner: debugOwner,
kind: kind,
supportedDevices: supportedDevices,
);
final Map<int, GestureArenaEntry> _entries = <int, GestureArenaEntry>{}; final Map<int, GestureArenaEntry> _entries = <int, GestureArenaEntry>{};
final Set<int> _trackedPointers = HashSet<int>(); final Set<int> _trackedPointers = HashSet<int>();
...@@ -393,13 +413,18 @@ enum GestureRecognizerState { ...@@ -393,13 +413,18 @@ enum GestureRecognizerState {
abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecognizer { abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecognizer {
/// Initializes the [deadline] field during construction of subclasses. /// Initializes the [deadline] field during construction of subclasses.
/// ///
/// {@macro flutter.gestures.GestureRecognizer.kind} /// {@macro flutter.gestures.GestureRecognizer.supportedDevices}
PrimaryPointerGestureRecognizer({ PrimaryPointerGestureRecognizer({
this.deadline, this.deadline,
this.preAcceptSlopTolerance = kTouchSlop, this.preAcceptSlopTolerance = kTouchSlop,
this.postAcceptSlopTolerance = kTouchSlop, this.postAcceptSlopTolerance = kTouchSlop,
Object? debugOwner, Object? debugOwner,
@Deprecated(
'Migrate to supportedDevices. '
'This feature was deprecated after v2.3.0-1.0.pre.',
)
PointerDeviceKind? kind, PointerDeviceKind? kind,
Set<PointerDeviceKind>? supportedDevices,
}) : assert( }) : assert(
preAcceptSlopTolerance == null || preAcceptSlopTolerance >= 0, preAcceptSlopTolerance == null || preAcceptSlopTolerance >= 0,
'The preAcceptSlopTolerance must be positive or null', 'The preAcceptSlopTolerance must be positive or null',
...@@ -408,7 +433,11 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni ...@@ -408,7 +433,11 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
postAcceptSlopTolerance == null || postAcceptSlopTolerance >= 0, postAcceptSlopTolerance == null || postAcceptSlopTolerance >= 0,
'The postAcceptSlopTolerance must be positive or null', 'The postAcceptSlopTolerance must be positive or null',
), ),
super(debugOwner: debugOwner, kind: kind); super(
debugOwner: debugOwner,
kind: kind,
supportedDevices: supportedDevices,
);
/// If non-null, the recognizer will call [didExceedDeadline] after this /// If non-null, the recognizer will call [didExceedDeadline] after this
/// amount of time has elapsed since starting to track the primary pointer. /// amount of time has elapsed since starting to track the primary pointer.
......
...@@ -247,13 +247,22 @@ class _LineBetweenPointers{ ...@@ -247,13 +247,22 @@ class _LineBetweenPointers{
class ScaleGestureRecognizer extends OneSequenceGestureRecognizer { class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
/// Create a gesture recognizer for interactions intended for scaling content. /// Create a gesture recognizer for interactions intended for scaling content.
/// ///
/// {@macro flutter.gestures.GestureRecognizer.kind} /// {@macro flutter.gestures.GestureRecognizer.supportedDevices}
ScaleGestureRecognizer({ ScaleGestureRecognizer({
Object? debugOwner, Object? debugOwner,
@Deprecated(
'Migrate to supportedDevices. '
'This feature was deprecated after v2.3.0-1.0.pre.',
)
PointerDeviceKind? kind, PointerDeviceKind? kind,
Set<PointerDeviceKind>? supportedDevices,
this.dragStartBehavior = DragStartBehavior.down, this.dragStartBehavior = DragStartBehavior.down,
}) : assert(dragStartBehavior != null), }) : assert(dragStartBehavior != null),
super(debugOwner: debugOwner, kind: kind); super(
debugOwner: debugOwner,
kind: kind,
supportedDevices: supportedDevices,
);
/// Determines what point is used as the starting point in all calculations /// Determines what point is used as the starting point in all calculations
/// involving this gesture. /// involving this gesture.
......
...@@ -422,8 +422,8 @@ class _UiKitViewGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -422,8 +422,8 @@ class _UiKitViewGestureRecognizer extends OneSequenceGestureRecognizer {
_UiKitViewGestureRecognizer( _UiKitViewGestureRecognizer(
this.controller, this.controller,
this.gestureRecognizerFactories, { this.gestureRecognizerFactories, {
PointerDeviceKind? kind, Set<PointerDeviceKind>? supportedDevices,
}) : super(kind: kind) { }) : super(supportedDevices: supportedDevices) {
team = GestureArenaTeam() team = GestureArenaTeam()
..captain = this; ..captain = this;
_gestureRecognizers = gestureRecognizerFactories.map( _gestureRecognizers = gestureRecognizerFactories.map(
...@@ -500,8 +500,8 @@ class _PlatformViewGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -500,8 +500,8 @@ class _PlatformViewGestureRecognizer extends OneSequenceGestureRecognizer {
_PlatformViewGestureRecognizer( _PlatformViewGestureRecognizer(
_HandlePointerEvent handlePointerEvent, _HandlePointerEvent handlePointerEvent,
this.gestureRecognizerFactories, { this.gestureRecognizerFactories, {
PointerDeviceKind? kind, Set<PointerDeviceKind>? supportedDevices,
}) : super(kind: kind) { }) : super(supportedDevices: supportedDevices) {
team = GestureArenaTeam() team = GestureArenaTeam()
..captain = this; ..captain = this;
_gestureRecognizers = gestureRecognizerFactories.map( _gestureRecognizers = gestureRecognizerFactories.map(
......
...@@ -553,7 +553,7 @@ class ScrollableState extends State<Scrollable> with TickerProviderStateMixin, R ...@@ -553,7 +553,7 @@ class ScrollableState extends State<Scrollable> with TickerProviderStateMixin, R
case Axis.vertical: case Axis.vertical:
_gestureRecognizers = <Type, GestureRecognizerFactory>{ _gestureRecognizers = <Type, GestureRecognizerFactory>{
VerticalDragGestureRecognizer: GestureRecognizerFactoryWithHandlers<VerticalDragGestureRecognizer>( VerticalDragGestureRecognizer: GestureRecognizerFactoryWithHandlers<VerticalDragGestureRecognizer>(
() => VerticalDragGestureRecognizer(), () => VerticalDragGestureRecognizer(supportedDevices: _configuration.dragDevices),
(VerticalDragGestureRecognizer instance) { (VerticalDragGestureRecognizer instance) {
instance instance
..onDown = _handleDragDown ..onDown = _handleDragDown
...@@ -565,8 +565,7 @@ class ScrollableState extends State<Scrollable> with TickerProviderStateMixin, R ...@@ -565,8 +565,7 @@ class ScrollableState extends State<Scrollable> with TickerProviderStateMixin, R
..minFlingVelocity = _physics?.minFlingVelocity ..minFlingVelocity = _physics?.minFlingVelocity
..maxFlingVelocity = _physics?.maxFlingVelocity ..maxFlingVelocity = _physics?.maxFlingVelocity
..velocityTrackerBuilder = _configuration.velocityTrackerBuilder(context) ..velocityTrackerBuilder = _configuration.velocityTrackerBuilder(context)
..dragStartBehavior = widget.dragStartBehavior ..dragStartBehavior = widget.dragStartBehavior;
..supportedDevices = _configuration.dragDevices;
}, },
), ),
}; };
...@@ -574,7 +573,7 @@ class ScrollableState extends State<Scrollable> with TickerProviderStateMixin, R ...@@ -574,7 +573,7 @@ class ScrollableState extends State<Scrollable> with TickerProviderStateMixin, R
case Axis.horizontal: case Axis.horizontal:
_gestureRecognizers = <Type, GestureRecognizerFactory>{ _gestureRecognizers = <Type, GestureRecognizerFactory>{
HorizontalDragGestureRecognizer: GestureRecognizerFactoryWithHandlers<HorizontalDragGestureRecognizer>( HorizontalDragGestureRecognizer: GestureRecognizerFactoryWithHandlers<HorizontalDragGestureRecognizer>(
() => HorizontalDragGestureRecognizer(), () => HorizontalDragGestureRecognizer(supportedDevices: _configuration.dragDevices),
(HorizontalDragGestureRecognizer instance) { (HorizontalDragGestureRecognizer instance) {
instance instance
..onDown = _handleDragDown ..onDown = _handleDragDown
...@@ -586,8 +585,7 @@ class ScrollableState extends State<Scrollable> with TickerProviderStateMixin, R ...@@ -586,8 +585,7 @@ class ScrollableState extends State<Scrollable> with TickerProviderStateMixin, R
..minFlingVelocity = _physics?.minFlingVelocity ..minFlingVelocity = _physics?.minFlingVelocity
..maxFlingVelocity = _physics?.maxFlingVelocity ..maxFlingVelocity = _physics?.maxFlingVelocity
..velocityTrackerBuilder = _configuration.velocityTrackerBuilder(context) ..velocityTrackerBuilder = _configuration.velocityTrackerBuilder(context)
..dragStartBehavior = widget.dragStartBehavior ..dragStartBehavior = widget.dragStartBehavior;
..supportedDevices = _configuration.dragDevices;
}, },
), ),
}; };
......
...@@ -1383,14 +1383,14 @@ class RawScrollbarState<T extends RawScrollbar> extends State<T> with TickerProv ...@@ -1383,14 +1383,14 @@ class RawScrollbarState<T extends RawScrollbar> extends State<T> with TickerProv
class _ThumbPressGestureRecognizer extends LongPressGestureRecognizer { class _ThumbPressGestureRecognizer extends LongPressGestureRecognizer {
_ThumbPressGestureRecognizer({ _ThumbPressGestureRecognizer({
double? postAcceptSlopTolerance, double? postAcceptSlopTolerance,
PointerDeviceKind? kind, Set<PointerDeviceKind>? supportedDevices,
required Object debugOwner, required Object debugOwner,
required GlobalKey customPaintKey, required GlobalKey customPaintKey,
required Duration pressDuration, required Duration pressDuration,
}) : _customPaintKey = customPaintKey, }) : _customPaintKey = customPaintKey,
super( super(
postAcceptSlopTolerance: postAcceptSlopTolerance, postAcceptSlopTolerance: postAcceptSlopTolerance,
kind: kind, supportedDevices: supportedDevices,
debugOwner: debugOwner, debugOwner: debugOwner,
duration: pressDuration, duration: pressDuration,
); );
......
...@@ -606,4 +606,19 @@ void main() { ...@@ -606,4 +606,19 @@ void main() {
expect(updated, 1); expect(updated, 1);
expect(ended, 1); expect(ended, 1);
}); });
testWidgets('ForecePressGestureRecognizer asserts when kind and supportedDevices are both set', (WidgetTester tester) async {
expect(
() {
ForcePressGestureRecognizer(
kind: PointerDeviceKind.touch,
supportedDevices: <PointerDeviceKind>{ PointerDeviceKind.touch },
);
},
throwsA(
isA<AssertionError>().having((AssertionError error) => error.toString(),
'description', contains('kind == null || supportedDevices == null')),
),
);
});
} }
...@@ -714,4 +714,19 @@ void main() { ...@@ -714,4 +714,19 @@ void main() {
longPress.dispose(); longPress.dispose();
recognized.clear(); recognized.clear();
}); });
testWidgets('LongPressGestureRecognizer asserts when kind and supportedDevices are both set', (WidgetTester tester) async {
expect(
() {
LongPressGestureRecognizer(
kind: PointerDeviceKind.touch,
supportedDevices: <PointerDeviceKind>{ PointerDeviceKind.touch },
);
},
throwsA(
isA<AssertionError>().having((AssertionError error) => error.toString(),
'description', contains('kind == null || supportedDevices == null')),
),
);
});
} }
...@@ -48,6 +48,36 @@ void main() { ...@@ -48,6 +48,36 @@ void main() {
GestureBinding.instance!.handleEvent(up90, HitTestEntry(MockHitTestTarget())); GestureBinding.instance!.handleEvent(up90, HitTestEntry(MockHitTestTarget()));
GestureBinding.instance!.handleEvent(up91, HitTestEntry(MockHitTestTarget())); GestureBinding.instance!.handleEvent(up91, HitTestEntry(MockHitTestTarget()));
}); });
testWidgets('VerticalDragGestureRecognizer asserts when kind and supportedDevices are both set', (WidgetTester tester) async {
expect(
() {
VerticalDragGestureRecognizer(
kind: PointerDeviceKind.touch,
supportedDevices: <PointerDeviceKind>{ PointerDeviceKind.touch },
);
},
throwsA(
isA<AssertionError>().having((AssertionError error) => error.toString(),
'description', contains('kind == null || supportedDevices == null')),
),
);
});
testWidgets('HorizontalDragGestureRecognizer asserts when kind and supportedDevices are both set', (WidgetTester tester) async {
expect(
() {
HorizontalDragGestureRecognizer(
kind: PointerDeviceKind.touch,
supportedDevices: <PointerDeviceKind>{ PointerDeviceKind.touch },
);
},
throwsA(
isA<AssertionError>().having((AssertionError error) => error.toString(),
'description', contains('kind == null || supportedDevices == null')),
),
);
});
} }
class MockHitTestTarget implements HitTestTarget { class MockHitTestTarget implements HitTestTarget {
......
...@@ -89,4 +89,61 @@ void main() { ...@@ -89,4 +89,61 @@ void main() {
expect(didStartDrag, isFalse); expect(didStartDrag, isFalse);
drag.dispose(); drag.dispose();
}); });
testWidgets('ImmediateMultiGestureRecognizer asserts when kind and supportedDevices are both set', (WidgetTester tester) async {
try {
ImmediateMultiDragGestureRecognizer(
kind: PointerDeviceKind.touch,
supportedDevices: <PointerDeviceKind>{ PointerDeviceKind.touch },
);
} catch(error) {
expect(error, isAssertionError);
expect(error.toString(), contains('kind == null || supportedDevices == null'));
}
});
testWidgets('HorizontalMultiDragGestureRecognizer asserts when kind and supportedDevices are both set', (WidgetTester tester) async {
expect(
() {
HorizontalMultiDragGestureRecognizer(
kind: PointerDeviceKind.touch,
supportedDevices: <PointerDeviceKind>{ PointerDeviceKind.touch },
);
},
throwsA(
isA<AssertionError>().having((AssertionError error) => error.toString(),
'description', contains('kind == null || supportedDevices == null')),
),
);
});
testWidgets('VerticalMultiDragGestureRecognizer asserts when kind and supportedDevices are both set', (WidgetTester tester) async {
expect(
() {
VerticalMultiDragGestureRecognizer(
kind: PointerDeviceKind.touch,
supportedDevices: <PointerDeviceKind>{ PointerDeviceKind.touch },
);
},
throwsA(
isA<AssertionError>().having((AssertionError error) => error.toString(),
'description', contains('kind == null || supportedDevices == null')),
),
);
});
testWidgets('DelayedMultiDragGestureRecognizer asserts when kind and supportedDevices are both set', (WidgetTester tester) async {
expect(
() {
DelayedMultiDragGestureRecognizer(
kind: PointerDeviceKind.touch,
supportedDevices: <PointerDeviceKind>{ PointerDeviceKind.touch },
);
},
throwsA(
isA<AssertionError>().having((AssertionError error) => error.toString(),
'description', contains('kind == null || supportedDevices == null')),
),
);
});
} }
...@@ -146,4 +146,34 @@ void main() { ...@@ -146,4 +146,34 @@ void main() {
tap.dispose(); tap.dispose();
}); });
testWidgets('DoubleTapGestureRecognizer asserts when kind and supportedDevices are both set', (WidgetTester tester) async {
expect(
() {
DoubleTapGestureRecognizer(
kind: PointerDeviceKind.touch,
supportedDevices: <PointerDeviceKind>{ PointerDeviceKind.touch },
);
},
throwsA(
isA<AssertionError>().having((AssertionError error) => error.toString(),
'description', contains('kind == null || supportedDevices == null')),
),
);
});
testWidgets('MultiTapGestureRecognizer asserts when kind and supportedDevices are both set', (WidgetTester tester) async {
expect(
() {
MultiTapGestureRecognizer(
kind: PointerDeviceKind.touch,
supportedDevices: <PointerDeviceKind>{ PointerDeviceKind.touch },
);
},
throwsA(
isA<AssertionError>().having((AssertionError error) => error.toString(),
'description', contains('kind == null || supportedDevices == null')),
),
);
});
} }
...@@ -48,6 +48,20 @@ void main() { ...@@ -48,6 +48,20 @@ void main() {
final OffsetPair difference = offset2 - offset1; final OffsetPair difference = offset2 - offset1;
expect(difference.local, const Offset(40, 40)); expect(difference.local, const Offset(40, 40));
expect(difference.global, const Offset(40, 40)); expect(difference.global, const Offset(40, 40));
});
testWidgets('EagerGestureRecognizer asserts when kind and supportedDevices are both set', (WidgetTester tester) async {
expect(
() {
EagerGestureRecognizer(
kind: PointerDeviceKind.touch,
supportedDevices: <PointerDeviceKind>{ PointerDeviceKind.touch },
);
},
throwsA(
isA<AssertionError>().having((AssertionError error) => error.toString(),
'description', contains('kind == null || supportedDevices == null')),
),
);
}); });
} }
...@@ -651,4 +651,19 @@ void main() { ...@@ -651,4 +651,19 @@ void main() {
scale.dispose(); scale.dispose();
}); });
testWidgets('ScaleGestureRecognizer asserts when kind and supportedDevices are both set', (WidgetTester tester) async {
expect(
() {
ScaleGestureRecognizer(
kind: PointerDeviceKind.touch,
supportedDevices: <PointerDeviceKind>{ PointerDeviceKind.touch },
);
},
throwsA(
isA<AssertionError>().having((AssertionError error) => error.toString(),
'description', contains('kind == null || supportedDevices == null')),
),
);
});
} }
...@@ -14,4 +14,40 @@ void main() { ...@@ -14,4 +14,40 @@ void main() {
// Changes made in https://github.com/flutter/flutter/pull/66043 // Changes made in https://github.com/flutter/flutter/pull/66043
VelocityTracker tracker = VelocityTracker(); VelocityTracker tracker = VelocityTracker();
tracker = VelocityTracker(PointerDeviceKind.mouse); tracker = VelocityTracker(PointerDeviceKind.mouse);
// Changes made in https://github.com/flutter/flutter/pull/81858
DragGestureRecognizer();
DragGestureRecognizer(kind: PointerDeviceKind.touch);
VerticalDragGestureRecognizer();
VerticalDragGestureRecognizer(kind: PointerDeviceKind.touch);
HorizontalDragGestureRecognizer();
HorizontalDragGestureRecognizer(kind: PointerDeviceKind.touch);
GestureRecognizer();
GestureRecognizer(kind: PointerDeviceKind.touch);
OneSequenceGestureRecognizer();
OneSequenceGestureRecognizer(kind: PointerDeviceKind.touch);
PrimaryPointerGestureRecognizer();
PrimaryPointerGestureRecognizer(kind: PointerDeviceKind.touch);
EagerGestureRecognizer();
EagerGestureRecognizer(kind: PointerDeviceKind.touch);
ForcePressGestureRecognizer();
ForcePressGestureRecognizer(kind: PointerDeviceKind.touch);
LongPressGestureRecognizer();
LongPressGestureRecognizer(kind: PointerDeviceKind.touch);
MultiDragGestureRecognizer();
MultiDragGestureRecognizer(kind: PointerDeviceKind.touch);
ImmediateMultiDragGestureRecognizer();
ImmediateMultiDragGestureRecognizer(kind: PointerDeviceKind.touch);
HorizontalMultiDragGestureRecognizer();
HorizontalMultiDragGestureRecognizer(kind: PointerDeviceKind.touch);
VerticalMultiDragGestureRecognizer();
VerticalMultiDragGestureRecognizer(kind: PointerDeviceKind.touch);
DelayedMultiDragGestureRecognizer();
DelayedMultiDragGestureRecognizer(kind: PointerDeviceKind.touch);
DoubleTapGestureRecognizer();
DoubleTapGestureRecognizer(kind: PointerDeviceKind.touch);
MultiTapGestureRecognizer();
MultiTapGestureRecognizer(kind: PointerDeviceKind.touch);
ScaleGestureRecognizer();
ScaleGestureRecognizer(kind: PointerDeviceKind.touch);
} }
...@@ -14,4 +14,40 @@ void main() { ...@@ -14,4 +14,40 @@ void main() {
// Changes made in https://github.com/flutter/flutter/pull/66043 // Changes made in https://github.com/flutter/flutter/pull/66043
VelocityTracker tracker = VelocityTracker.withKind(PointerDeviceKind.touch); VelocityTracker tracker = VelocityTracker.withKind(PointerDeviceKind.touch);
tracker = VelocityTracker.withKind(PointerDeviceKind.mouse); tracker = VelocityTracker.withKind(PointerDeviceKind.mouse);
// Changes made in https://github.com/flutter/flutter/pull/81858
DragGestureRecognizer();
DragGestureRecognizer(supportedDevices: <PointerDeviceKind>{PointerDeviceKind.touch});
VerticalDragGestureRecognizer();
VerticalDragGestureRecognizer(supportedDevices: <PointerDeviceKind>{PointerDeviceKind.touch});
HorizontalDragGestureRecognizer();
HorizontalDragGestureRecognizer(supportedDevices: <PointerDeviceKind>{PointerDeviceKind.touch});
GestureRecognizer();
GestureRecognizer(supportedDevices: <PointerDeviceKind>{PointerDeviceKind.touch});
OneSequenceGestureRecognizer();
OneSequenceGestureRecognizer(supportedDevices: <PointerDeviceKind>{PointerDeviceKind.touch});
PrimaryPointerGestureRecognizer();
PrimaryPointerGestureRecognizer(supportedDevices: <PointerDeviceKind>{PointerDeviceKind.touch});
EagerGestureRecognizer();
EagerGestureRecognizer(supportedDevices: <PointerDeviceKind>{PointerDeviceKind.touch});
ForcePressGestureRecognizer();
ForcePressGestureRecognizer(supportedDevices: <PointerDeviceKind>{PointerDeviceKind.touch});
LongPressGestureRecognizer();
LongPressGestureRecognizer(supportedDevices: <PointerDeviceKind>{PointerDeviceKind.touch});
MultiDragGestureRecognizer();
MultiDragGestureRecognizer(supportedDevices: <PointerDeviceKind>{PointerDeviceKind.touch});
ImmediateMultiDragGestureRecognizer();
ImmediateMultiDragGestureRecognizer(supportedDevices: <PointerDeviceKind>{PointerDeviceKind.touch});
HorizontalMultiDragGestureRecognizer();
HorizontalMultiDragGestureRecognizer(supportedDevices: <PointerDeviceKind>{PointerDeviceKind.touch});
VerticalMultiDragGestureRecognizer();
VerticalMultiDragGestureRecognizer(supportedDevices: <PointerDeviceKind>{PointerDeviceKind.touch});
DelayedMultiDragGestureRecognizer();
DelayedMultiDragGestureRecognizer(supportedDevices: <PointerDeviceKind>{PointerDeviceKind.touch});
DoubleTapGestureRecognizer();
DoubleTapGestureRecognizer(supportedDevices: <PointerDeviceKind>{PointerDeviceKind.touch});
MultiTapGestureRecognizer();
MultiTapGestureRecognizer(supportedDevices: <PointerDeviceKind>{PointerDeviceKind.touch});
ScaleGestureRecognizer();
ScaleGestureRecognizer(supportedDevices: <PointerDeviceKind>{PointerDeviceKind.touch});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment