holding_gesture
1.2.0, released 3 years ago by gildaswise.com
A widget that detects long presses and triggers callbacks after a hold timeout.
WASM-ready
What it does
HoldDetector extends GestureDetector to call a callback after a specified hold duration. HoldTimeoutDetector triggers callbacks when a hold reaches a timeout, with optional cancel and initiation callbacks.
AI-written summary of version 1.2.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need a button that reacts to long presses with a custom timeout.
- You want haptic feedback on each hold tick.
- You need to perform an action only after the user holds for a set duration.
- You want to cancel the action if the user releases early.
Skip it when
- You only need a simple tap or long press without custom timeout logic.
- You are building a complex gesture system that requires low-level gesture recognizers.
- You need to support gestures on platforms that don't support haptic feedback.
Strengths
- Simple API that mirrors GestureDetector.
- Supports custom hold timeout and haptic feedback.
- Provides both immediate hold and timeout-based callbacks.
- No external dependencies beyond Flutter.
Weaknesses
- Limited to hold gestures; no other gesture types.
- No built-in visual feedback for the hold state.
- Requires manual handling of onPressed conflicts.
- No support for platform-specific gesture nuances.
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 0
HoldDetector(
onHold: _incrementCounter,
holdTimeout: Duration(milliseconds: 200),
enableHapticFeedback: true,
child: ElevatedButton(
onPressed: _incrementCounter,
child: Text("onHold"),
),
)Works with
Packages commonly used together with holding_gesture: ones it builds on, ones built on it, and its own family.