Search packages, repositories and app categories

Package detailsv1.2.0

holding_gesture

A customized GestureDetector that acts on holding a determined Widget.

AndroidiOSWebmacOSWindowsLinux
30-day downloads
17.6K
Likes
49
Pub points
150

Install package

flutter pub add holding_gesture

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

The holding_gesture package provides a customized GestureDetector that triggers actions when a user holds a specific widget for a defined duration. It extends Flutter's built-in GestureDetector with dedicated hold detection, enabling responsive and intuitive interactions such as long-press menus, drag-and-drop initiation, or context-sensitive controls. The package is lightweight and compatible across all major platforms, including mobile, web, and desktop. It simplifies implementing hold-based gestures without writing boilerplate code.

Use cases

  • Long-press context menus
  • Gesture-based navigation triggers
  • Interactive widget activation
  • Drag start detection
  • Customizable hold duration
  • Accessibility-enhanced controls

Key features

  • Precise hold duration control
  • Cross-platform compatibility
  • Simple API integration
  • Configurable hold delay
  • Built-in callback handling
  • Minimal performance overhead

Suitable for

  • Developers building interactive UIs
  • Apps requiring long-press functionality
  • Cross-platform Flutter projects
  • Accessibility-focused interfaces
  • Gesture-heavy applications

Considerations

  • Requires careful timing configuration
  • May conflict with other gesture detectors
  • Not suitable for rapid tap sequences
  • Needs testing on all target platforms
  • Limited to single-widget hold detection
  • Depends on Flutter's gesture system stability

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

holding_gesture

A customized GestureDetector that acts on holding a determined Widget.

Getting Started

import 'package:holding_gesture/holding_gesture.dart';
HoldDetector

After importing, all you have to do is use HoldDetector the same way you already used GestureDetector! As it is on the documentation, its onTap override won't work when using a child that has onPressed or a similar callback, so you should pass the single tap behaviour to that.

HoldDetector(
  onHold: _incrementCounter,
  holdTimeout: Duration(milliseconds: 200),
  enableHapticFeedback: true,
  child: ElevatedButton(
    onPressed: _incrementCounter,
    child: Text("onHold"),
  ),
),
HoldTimeoutDetector

HoldTimeoutDetector works differently, you can use it to hold conditions or display something while the user is holding it for a predetermined time, and then execute an action after this duration passes, or canceling it if the hold action ceases. In the example, I'm using it to show a feedback on the button, and on the screen that something is loading, and then executing the increment once the timeout happens.

HoldTimeoutDetector(
  onTimeout: () {
    _incrementCounter();
    _updateLoading(false);
  },
  onTimerInitiated: () => _updateLoading(true),
  onCancel: () => _updateLoading(false),
  holdTimeout: Duration(milliseconds: 3000),
  enableHapticFeedback: true,
  child: ElevatedButton.icon(
    onPressed: () {},
    label: Text("onTimeout"),
    icon: _isLoading
        ? SizedBox(
            width: 16,
            height: 16,
            child: CircularProgressIndicator(
              strokeWidth: 2,
              valueColor: AlwaysStoppedAnimation(Colors.white),
            ),
          )
        : Icon(Icons.timer_3),
  ),
),

The main example, above and in example/, is the same as the default Flutter app, with the adition of a haptic feedback to each tick and the ability to hold the button to keep adding to the counter.

Categories

Source repository

Projects using this package