Skip to content

How to use scale gesture recognizer instead of pan recognizer #115061

@matthew-carroll

Description

@matthew-carroll

A GestureDetector widget allows you to register "pan" callbacks or "scale" callbacks, but not both.

Attempting to register both causes an error:

Incorrect GestureDetector arguments.

Having both a pan gesture recognizer and a scale gesture recognizer is redundant; scale is a superset of pan.

Just use the scale gesture recognizer.

However, as far as I can tell, the scale behavior isn't really a "superset" of the pan behavior.

I tried migrating my existing panning behavior to use scale callbacks because I needed to add scaling to my existing gesture behaviors. In my existing pan behavior, I check the type of device that starts the pan:

void _onPanStart(DragStartDetails details) {
  print("Device type: ${details.kind}");
}

As I mentioned, when I tried to add scaling, I was forced to replace my pan methods with scale methods. But the device type isn't reported. For example, the following doesn't compile:

void _onScaleStart(ScaleStartDetails details) {
  print("Device type: ${details.kind}");
}

Therefore, while it may be true that the touch events that trigger a pan gesture also trigger a scale gesture, the way that information is reported results in different capabilities.

I think that this should be considered a bug.

In the meantime, what can I do to handle pan and scale gestures with device awareness, e.g., Apple pencil vs touch?

Flutter version:

Flutter 3.3.8 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 52b3dc25f6 (28 hours ago) • 2022-11-09 12:09:26 +0800
Engine • revision 857bd6b74c
Tools • Dart 2.18.4 • DevTools 2.15.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: crashStack traces logged to the consolef: gesturesflutter/packages/flutter/gestures repository.found in release: 3.3Found to occur in 3.3frameworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions