搜索插件、代码仓与 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

所属分类

源码仓库

使用此插件的项目