multi_tap_action 2.1.1
multi_tap_action: ^2.1.1 copied to clipboard
A Flutter package to detect a specific number of taps on a widget and trigger custom actions. Perfect for implementing multi-tap gestures like double-tap, triple-tap, or more.
Multi Tap Action #
Features #
- 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.
Getting started #
Install it using pub:
flutter pub add multi_tap_action
And import the package:
import 'package:multi_tap_action/multi_tap_action.dart';
Usage #
Basic Example #
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,
),
)
Advanced Example #
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,
),
)
Constructor #
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. |
Author #
This package was developed by sawongam