How do I create a GestureRecognizer
in Flutter that only responds to two-finger gestures, and passes single-finger gestures on to other widgets in the arena?
In my Flutter app, I have a GoogleMap
widget inside a SingleChildScrollView
. The GoogleMap
widget takes a gestureRecognizers
parameter which I have set to the following, otherwise it is not even possible to interact with the map (the ScrollView gets all the touch events, at least 95% of the time…)
gestureRecognizers: const {
Factory<OneSequenceGestureRecognizer>(
EagerGestureRecognizer.new,
),
},
With this GestureRecognizer
, the Google Maps widget responds to single-finger gestures (pan) and two-finger gestures (zoom/pan). I want the widget to respond only two-finger gestures, because currently dragging with one finger on the map widget interrupts the user’s ability to scroll the view up or down. So I want single-finger gestures to go to the ScrollView, and two-finger gestures to go to Google Maps. (The Google Maps web widget requires a two-finger gesture for pan, for the same reason…)
How do I replace EagerGestureRecognizer
with a gesture recognizer that causes Maps to only pan if two fingers are down, otherwise to pass the single-finger gesture through to the scroll view?
2
Answers
OK, I figured it out. The trick is that you need to use a
GestureAreaManager
to hold the first touch point until the second touch point goes down:Is this the correct way to use this?
Currently, I am using it like this but the working of single finger pan and two finger pan is still the same.