搜尋套件、儲存庫與 APP 分類

套件詳情v1.1.1

gesture_x_detector

一個輕量級的手勢檢測器,支援多種類型(點擊、雙擊、縮放、長按、移動),所有回調可同時使用

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
1.7萬
喜歡數
63
Pub 分數
150

安裝套件

flutter pub add gesture_x_detector

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

GestureXDetector 是一個輕量級的 Flutter 套件,可同時偵測多種手勢,包括點擊、雙擊、縮放、長按和移動。它為每種手勢類型提供靈活的回呼支援,讓開發者能以統一的方式回應複雜的使用者互動。專為跨平台使用設計,可在 Android、iOS、Web、macOS、Windows 和 Linux 上順暢運作。此套件非常適合需要響應式觸控反饋卻又不增加複雜度的互動式介面。

適用情境

  • 互動式繪圖應用
  • 可縮放的圖像查看器
  • 拖曳與放置介面
  • 多點觸控手勢識別
  • 基於手勢的自定義控制

主要特色

  • 支援同時多種手勢
  • 所有回呼可同時使用
  • 輕量且高效
  • 跨平台相容性
  • 簡單的 API 結合
  • 即時手勢偵測

適合對象

  • 開發互動式 UI 的開發者
  • 需要多點觸控輸入的應用
  • 需要響應式手勢處理的專案
  • 跨平台觸控應用
  • 原型化手勢密集型功能

使用建議

  • 可能需要仔細管理重疊手勢的狀態
  • 對高頻率手勢事件的效能影響
  • 未針對極其複雜的手勢鏈進行優化
  • 有限的內建手勢組合
  • 最適合中等到高階的手勢邏輯

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

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

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案