Search packages, repositories and app categories

Package detailsv1.1.1

gesture_x_detector

a lightweight gesture detector that supports multiple types(Tap, DoubleTap, Scale, Long-Press, Move) and all callbacks can be used simultaneously

AndroidiOSWebmacOSWindowsLinux
30-day downloads
16.6K
Likes
63
Pub points
150

Install package

flutter pub add gesture_x_detector

Package Overview

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

GestureXDetector is a lightweight Flutter package that enables detection of multiple gestures simultaneously, including Tap, DoubleTap, Scale, Long-Press, and Move. It provides flexible callback support for each gesture type, allowing developers to respond to complex user interactions in a unified way. Designed for cross-platform use, it works seamlessly across Android, iOS, Web, macOS, Windows, and Linux. The package is ideal for interactive UIs requiring responsive touch feedback without added complexity.

Use cases

  • Interactive drawing apps
  • Zoomable image viewers
  • Drag-and-drop interfaces
  • Multi-touch gesture recognition
  • Custom gesture-based controls

Key features

  • Supports multiple gestures at once
  • All callbacks available simultaneously
  • Lightweight and efficient
  • Cross-platform compatibility
  • Simple API integration
  • Real-time gesture detection

Suitable for

  • Developers building interactive UIs
  • Apps requiring multi-touch input
  • Projects needing responsive gesture handling
  • Cross-platform touch applications
  • Prototyping gesture-heavy features

Considerations

  • May require careful state management with overlapping gestures
  • Performance impact on very high-frequency gesture events
  • Not optimized for extremely complex gesture chains
  • Limited built-in gesture composition
  • Best suited for moderate to high-level gesture logic

Original README

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

gesture_x_detector

A widget that detects gestures.

Easy to use, lightweight gesture detector for Flutter apps.

Features

  • Detect tap gestures [Tap, DoubleTap, Scale(start, update, end), Long press, Move(start, update, end) and Scroll]
  • All callbacks can be used simultaneously
  • Customize: ignore tap event on double tap, change duration time to detect double tap or long-press

Getting Started

Installation

Add to pubspec.yaml:

dependencies:
    gesture_x_detector:
Example

Checkout the example at https://github.com/taodo2291/xgesture_flutter/tree/master/example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:gesture_x_detector/gesture_x_detector.dart';

void main() {
  runApp(
    MaterialApp(
      home: XGestureExample(),
    ),
  );
}

class XGestureExample extends StatefulWidget {
  @override
  _XGestureExampleState createState() => _XGestureExampleState();
}

class _XGestureExampleState extends State<XGestureExample> {
  String lastEventName = 'Tap on screen';

  @override
  Widget build(BuildContext context) {
    return XGestureDetector(
      child: Material(
        child: Center(
          child: Text(
            lastEventName,
            style: TextStyle(fontSize: 30),
          ),
        ),
      ),
      doubleTapTimeConsider: 300,
      longPressTimeConsider: 350,
      onTap: onTap,
      onDoubleTap: onDoubleTap,
      onLongPress: onLongPress,
      onLongPressEnd: onLongPressEnd,
      onMoveStart: onMoveStart,
      onMoveEnd: onMoveEnd,
      onMoveUpdate: onMoveUpdate,
      onScaleStart: onScaleStart,
      onScaleUpdate: onScaleUpdate,
      onScaleEnd: onScaleEnd,
      bypassTapEventOnDoubleTap: false,
      onLongPressMove: onLongPressMove,
      onScrollEvent: onScrollEvent,
      longPressMaximumRangeAllowed: 25,
    );
  }

  void onScrollEvent(ScrollEvent event) {
    setLastEventName('onLongPressMove');
    print('scrolling - pos: ${event.localPos} delta: ${event.scrollDelta}');
  }

  void onLongPressMove(MoveEvent event) {
    setLastEventName('onLongPressMove');
    print('onMoveUpdate - pos: ${event.localPos} delta: ${event.delta}');
  }

  void onLongPressEnd() {
    setLastEventName('onLongPressEnd');
    print('onLongPressEnd');
  }

  void onScaleEnd() {
    setLastEventName('onScaleEnd');
    print('onScaleEnd');
  }

  void onScaleUpdate(ScaleEvent event) {
    setLastEventName('onScaleUpdate');
    print(
        'onScaleUpdate - changedFocusPoint:  ${event.focalPoint} ; scale: ${event.scale} ;Rotation: ${event.rotationAngle}');
  }

  void onScaleStart(initialFocusPoint) {
    setLastEventName('onScaleStart');
    print('onScaleStart - initialFocusPoint: $initialFocusPoint');
  }

  void onMoveUpdate(MoveEvent event) {
    setLastEventName('onMoveUpdate');
    print('onMoveUpdate - pos: ${event.localPos} delta: ${event.delta}');
  }

  void onMoveEnd(localPos) {
    setLastEventName('onMoveEnd');
    print('onMoveEnd - pos: $localPos');
  }

  void onMoveStart(localPos) {
    setLastEventName('onMoveStart');
    print('onMoveStart - pos: $localPos');
  }

  void onLongPress(TapEvent event) {
    setLastEventName('onLongPress');
    print('onLongPress - pos: ${event.localPos}');
  }

  void onDoubleTap(event) {
    setLastEventName('onDoubleTap');
    print('onDoubleTap - pos: ' + event.localPos.toString());
  }

  void onTap(event) {
    setLastEventName('onTap');
    print('onTap - pos: ' + event.localPos.toString());
  }

  void setLastEventName(String eventName) {
    setState(() {
      lastEventName = eventName;
    });
  }
}

Customize
  • Change DoubleTap and Long press detect
@override
  Widget build(BuildContext context) {
    return XGestureDetector(
      child: child,
      doubleTapTimeConsider: 300,       //customize double tap time
      longPressTimeConsider: 400,       //customize long press time
      longPressMaximumRangeAllowed: 25, //customize the long press behavior, the touch can be move a some pixels (25 is the distanceSquare, that mean we allow move 5 pixels)
    );
  }
  • Ignore Tap in case Double Tap dectected
@override
  Widget build(BuildContext context) {
    return XGestureDetector(
      child: child,
      bypassTapEventOnDoubleTap: true,      // default is false
    );
  }
  • Allow move event after long press event fired without release pointer
@override
  Widget build(BuildContext context) {
    return XGestureDetector(
      child: child,
      bypassMoveEventAfterLongPress: false,      // default is true
    );
  }

Checkout the Canvas playground example at https://github.com/taodo2291/xgesture_flutter/tree/master/example/lib/canvas_playground.dart

Author

Viet Nguyen - taodo2291@gmail.com

Categories

Dependencies

Dependency list 1 items

Source repository

Projects using this package