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

scratcher 封面
套件詳情v2.5.0

scratcher

刮獎卡組件,可暫時隱藏使用者內容。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
1.5萬
喜歡數
501
Pub 分數
140

安裝套件

flutter pub add scratcher

套件介紹

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

Scratcher 套件提供了一個 Flutter 小部件,可模擬刮獎卡體驗,暫時隱藏內容,直到使用者『刮除』為止。非常適合遊戲化介面、獎勵系統或應用中的驚喜揭露。該小部件支援所有主要平台(包含行動裝置、網頁與桌面)的觸控互動。可自訂的刮除效果與視覺反饋可提升使用者參與度。專注於效能與易於整合,是希望加入互動元素卻不需複雜實作之開發者的完美選擇。

適用情境

  • 遊戲化應用獎勵
  • 隱藏內容顯示
  • 互動促銷
  • 數位刮刮卡
  • 使用者參與功能

主要特色

  • 跨平台支援
  • 可自訂的刮擦效果
  • 觸控互動處理
  • 平滑動畫
  • 與 Flutter 的輕鬆整合
  • 可設定的刮除不透明度

適合對象

  • 尋求互動式 UI 的應用開發者
  • 遊戲化專案
  • 帶有驚喜元素的行銷活動
  • 具有揭露機制的教育類應用
  • 簡單的基於獎勵的應用程式

使用建議

  • 可能影響低階裝置的效能
  • 對高級刮擦模式的自定義有限
  • 不適合用於高安全性內容隱藏
  • 需要仔細設計以確保可存取性
  • 最適合與輕量級內容一起使用

原始 README

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

scratcher

Scratch card widget which temporarily hides content from the user.

Version

Demo

Features

  • Supported platforms:
    • Android
    • iOS
    • Web (CanvasKit only)
  • Cover content with full color or custom image
  • Track the scratch progress and threshold
  • Fully configurable

Getting started

  1. First thing you need to do is adding the scratcher as a project dependency in pubspec.yaml:
dependencies:
 scratcher: "^2.5.0"
  1. Now you can install it by running flutter pub get or through code editor.

Setting up

  1. Import the library:
import 'package:scratcher/scratcher.dart';
  1. Cover desired widget with the scratch card:
Scratcher(
  brushSize: 30,
  threshold: 50,
  color: Colors.red,
  onChange: (value) => print("Scratch progress: $value%"),
  onThreshold: () => print("Threshold reached, you won!"),
  child: Container(
    height: 300,
    width: 300,
    color: Colors.blue,
  ),
)

Properties

Property Type Description
child Widget Widget rendered under the scratch area.
enabled bool Whether new scratches can be applied.
threshold double Percentage level of scratch area which should be revealed to complete.
brushSize double Size of the brush. The bigger it is the faster user can scratch the card.
accuracy ScratchAccuracy Determines how accurate the progress should be reported. Lower accuracy means higher performance.
color Color Color used to cover the child widget.
image Image Image widget used to cover the child widget.
rebuildOnResize bool Determines if the scratcher should rebuild itself when space constraints change (resize).
onChange Function Callback called when new part of area is revealed (min 0.1% difference).
onThreshold Function Callback called when threshold is reached (only when defined).
onScratchStart Function Callback called when scratching starts.
onScratchUpdate Function Callback called during scratching.
onScratchEnd Function Callback called when scratching ends.

Programmatic access

You can control the Scratcher programmatically by assigning the GlobalKey to the widget.

final scratchKey = GlobalKey<ScratcherState>();

Scratcher(
  key: scratchKey,
  // remaining properties
)

After assigning the key, you can call any exposed methods e.g.:

RaisedButton(
  child: const Text('Reset'),
  onPressed: () {
    scratchKey.currentState.reset(duration: Duration(milliseconds: 2000));
  },
);
Method Description
reset Resets the scratcher state to the initial values.
reveal Reveals the whole scratcher, so than only original child is displayed.

Example Project

There is a crazy example project in the example folder. Check it out to see most of the available options.

Resources

所屬分類

原始碼儲存庫

使用此套件的專案