gesture_x_detector 0.0.1 copy "gesture_x_detector: ^0.0.1" to clipboard
gesture_x_detector: ^0.0.1 copied to clipboard

outdated

A gesture detector which supports among type (Tap, DoubleTap, Scale, Move, Long press).

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)
  • All callbacks can be used simultaneously
  • Customizeable: ignore tap event on double tap, change duration time for detect double tap or long press

Getting Started #

Installation #

Add to pubspec.yaml:

dependencies:
    gesture_x_detector:

Example #

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

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

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

  @override
  Widget build(BuildContext context) {
    return XGestureDetector(
      child: Material(
        child: Center(
          child: Text(
            lastEventName,
            style: TextStyle(fontSize: 30),
          ),
        ),
      ),
      onTap: onTap,
      onDoubleTap: onDoubleTap,
      onLongPress: onLongPress,
      onMoveStart: onMoveStart,
      onMoveEnd: onMoveEnd,
      onMoveUpdate: onMoveUpdate,
      onScaleStart: onScaleStart,
      onScaleUpdate: onScaleUpdate,
      onScaleEnd: onScaleEnd,
    );
  }

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

  void onScaleUpdate(changedFocusPoint, scale) {
    setLastEventName('onScaleUpdate');
    print(
        'onScaleUpdate - changedFocusPoint:  $changedFocusPoint ; scale: $scale');
  }

  void onScaleStart(initialFocusPoint) {
    setLastEventName('onScaleStart');
    print('onScaleStart - initialFocusPoint: ' + initialFocusPoint.toString());
  }

  void onMoveUpdate(localPos, position, localDelta, delta) {
    setLastEventName('onMoveUpdate');
    print('onMoveUpdate - pos: ' + localPos.toString());
  }

  void onMoveEnd(pointer, localPos, position) {
    setLastEventName('onMoveEnd');
    print('onMoveEnd - pos: ' + localPos.toString());
  }

  void onMoveStart(pointer, localPos, position) {
    setLastEventName('onMoveStart');
    print('onMoveStart - pos: ' + localPos.toString());
  }

  void onLongPress(pointer, localPos, position) {
    setLastEventName('onLongPress');
    print('onLongPress - pos: ' + localPos.toString());
  }

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

  void onTap(pointer, localPos, position) {
    setLastEventName('onTap');
    print('onTap - pos: ' + 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
    );
  }
  • Ignore Tap in case Double Tap dectected
@override
  Widget build(BuildContext context) {
    return XGestureDetector(
      child: child,
      bypassTapEventOnDoubleTap: true,      // default is false
    );
  }

Author #

Viet Nguyen - taodo2291@gmail.com

59
likes
0
pub points
92%
popularity

Publisher

unverified uploader

A gesture detector which supports among type (Tap, DoubleTap, Scale, Move, Long press).

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on gesture_x_detector