Last active
September 9, 2024 11:14
-
-
Save bizz84/0a57ad7afbe75353236943d30abf6cb0 to your computer and use it in GitHub Desktop.
Custom TripleTapDetector widget using RawGestureDetector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/gestures.dart'; | |
import 'package:flutter/material.dart'; | |
class TripleTapDetector extends StatelessWidget { | |
const TripleTapDetector({ | |
super.key, | |
required this.child, | |
required this.onTripleTap, | |
}); | |
final Widget child; | |
final VoidCallback onTripleTap; | |
@override | |
Widget build(BuildContext context) { | |
return RawGestureDetector( | |
gestures: { | |
SerialTapGestureRecognizer: | |
GestureRecognizerFactoryWithHandlers<SerialTapGestureRecognizer>( | |
() => SerialTapGestureRecognizer(), | |
(SerialTapGestureRecognizer instance) { | |
instance.onSerialTapDown = (SerialTapDownDetails details) { | |
if (details.count == 3) { | |
onTripleTap(); | |
} | |
}; | |
}, | |
), | |
}, | |
child: child, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment