- Customizable tap count: Define the exact number of taps required to trigger an action
- Custom actions: Execute any desired action when the specified number of taps is reached
- Haptic feedback: Optionally enable haptic feedback with different types (light, medium, heavy, or selection click)
- Tap reset duration: Set a time window to reset the tap counter if no further taps are detected
- Callback for every tap: Get the current tap count on every tap for additional control.
Install it using pub:
flutter pub add multi_tap_action
And import the package:
import 'package:multi_tap_action/multi_tap_action.dart';
Detect a triple tap and perform an action:
MultiTapAction(
taps: 3, // Number of taps to detect
onActionTriggered: (taps) {
print('$taps taps detected!'); // Action to perform when the specified number of taps is reached
},
child: Container(
color: Colors.yellow,
width: 100,
height: 100,
),
)
Detect a double tap with haptic feedback and a custom reset duration:
MultiTapAction(
taps: 2,
onActionTriggered: (taps) {
print('$taps taps detected!');
},
onTap: (currentTapCount) {
print('Current tap count: $currentTapCount');
},
resetDuration: Duration(seconds: 2), // Reset tap counter after 2 seconds
enableHapticFeedback: true, // Enable haptic feedback
hapticFeedbackType: HapticFeedbackType.mediumImpact, // Use medium impact haptic feedback
child: Container(
color: Colors.red,
width: 150,
height: 150,
),
)
Parameters | Type | Description |
---|---|---|
taps | int | Number of taps required to trigger the action. Must be greater than 0. |
onActionTriggered | Function(int taps) | Callback function to execute when the specified number of taps is reached. |
child | Widget | The widget on which taps are detected. |
onTap (optional) | Function(int currentTapCount)? | Callback function to execute on every tap. Returns the current tap count. |
resetDuration (optional) | Duration | Time to reset if no further taps are detected.Defaults to 60seconds. |
enableHapticFeedback (optional) | bool | Enable haptic feedback when the action is triggered. Defaults to false. |
hapticFeedbackType (optional) | HapticFeedbackType | Type of haptic feedback to trigger. Defaults toHapticFeedbackType.lightImpact. |
This package was developed by sawongam