Detect triple tap in Flutter

How Can I Detect a Triple Tap on a Flutter Widget?

I need to detect a triple tap (or more) on a Flutter widget, but the built-in GestureDetector only supports double-tap detection.

What is the simplest way for me to detect a triple tap on a widget?

(The purpose is to unlock some developer options by continually clicking on a part of the screen.)

GestureDetector(
  onDoubleTap: () {
    // ...
  },
  child: Container(
    // ...
  ),
);

You can use the GestureDetector’s onTapDown and onTapUp callbacks to manually detect a triple tap. Here’s an example:

int _tapCount = 0;
DateTime _lastTapTime;

GestureDetector(
  onTapDown: (TapDownDetails details) {
    final now = DateTime.now();
    if (_lastTapTime != null && now.difference(_lastTapTime) < Duration(milliseconds: 500)) {
      _tapCount++;
      if (_tapCount == 3) {
        // Triple tap detected!
        // Do your thing here...
      }
    } else {
      _tapCount = 1;
    }
    _lastTapTime = now;
  },
  child: Container(
    // ...
  ),
);

This code tracks the number of taps within a 500ms window. When the third tap is detected, you can perform your desired action.