Reputation: 141
I'm developing and app where on double tap I need to perform some actions, but they require the position where that double tap was executed. That information is normally carried by the details in events like "onTapDown/Up".
Now, I know you can call both "onTapDown" and "doubleTap" on a GestureDetector, but if you have a child that takes the "onTap" gesture the "onTapDown" won't fire when a double tap occurs. In my case I have a WebView under the GestureDetector, so only "onDoubleTap" fires.
I've already commented in this request (https://github.com/flutter/flutter/issues/20000) to the Flutter team to add "details" to "onDoubleTap", but it looks like it is going to take a while.
In that same thread they suggest a couple of solutions that I have already tried. 1st using this code:
var lastTapDown = 0;
onTapDown: (details) {
var now = DateTime.now().millisecondsSinceEpoch;
if (now - lastTapDown < 200) {
print("Double Tap!")
}
lastTapDown = now;
},
...
This first solutions works, but I can't use it as I need the "onTap" to be claimed by the WebView.
And the other using this plugin: https://github.com/tomwyr/positioned-tap-detector, which I did and it is great but it bumps into the same problem as me, "onTapDown" won't fire if you have a child that wins "onTap" on the arena.
So if anyone can help me get that positions it would be much appreciated. :)
Thanks.
Upvotes: 2
Views: 4257
Reputation: 1439
Available with version 1.22.0 (release date: 01/10/2020) you can get the details with onDoubleTapDown
.
TapDownDetails _doubleTapDetails;
void _handleDoubleTapDown(TapDownDetails details) {
_doubleTapDetails = details;
}
void _handleDoubleTap() {
print('Double tap on position ${_doubleTapDetails.localPosition}');
}
@override
Widget build(BuildContext context) {
return GestureDetector(
/* ... */
onDoubleTapDown: _handleDoubleTapDown,
onDoubleTap: _handleDoubleTap,
);
}
Upvotes: 5