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

套件詳情v1.2.0

holding_gesture

一個自訂的 GestureDetector,可在按住特定 Widget 時觸發動作。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
1.8萬
喜歡數
49
Pub 分數
150

安裝套件

flutter pub add holding_gesture

套件介紹

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

holding_gesture 套件提供了一個自訂的 GestureDetector,當使用者在特定組件上按住一段指定時間時觸發動作。它擴展了 Flutter 內建的 GestureDetector,具備專用的按住偵測功能,可實現回應式且直覺的互動,例如長按選單、拖曳啟動或情境敏感控制。此套件輕量且相容於所有主要平台,包含行動裝置、網頁與桌面。它簡化了基於按住手勢的實作,無需撰寫重複程式碼。

適用情境

  • 長按上下文選單
  • 基於手勢的導航觸發
  • 互動式 widget 激活
  • 拖曳開始檢測
  • 可自訂的按住持續時間
  • 無障礙增強控制項

主要特色

  • 精確的按壓持續時間控制
  • 跨平台相容性
  • 簡單的 API 結合
  • 可設定的按住延遲
  • 內建回呼處理
  • 最小性能開銷

適合對象

  • 開發互動式 UI 的開發者
  • 需要長按功能的應用
  • 跨平台 Flutter 項目
  • 以可存取性為導向的介面
  • 手勢密集型應用

使用建議

  • 需要仔細配置時間
  • 可能與其他手勢檢測器衝突
  • 不適用於快速點擊序列
  • 需要在所有目標平台進行測試
  • 僅限單個元件按住檢測
  • 依賴於 Flutter 手勢系統的穩定性

原始 README

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

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.

所屬分類

原始碼儲存庫

使用此套件的專案