scratcher 1.3.0

Flutter Android iOS web

Scratch card widget which temporarily hides content from user.

scratcher #

Scratch card widget which temporarily hides content from user.

Version

Demo

Features #

  • Android and iOS support
  • 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: "^1.3.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 #

PropertyTypeDescription
childWidgetWidget rendered under the scratch area.
thresholddoublePercentage level of scratch area which should be revealed to complete.
brushSizedoubleSize of the brush. The bigger it is the faster user can scratch the card.
accuracyScratchAccuracyDetermines how accurate the progress should be reported. Lower accuracy means higher performance.
colorColorColor used to cover the child widget.
imageImageImage widget used to cover the child widget.
onChangeFunctionCallback called when new part of area is revealed (min 0.1% difference).
onThresholdFunctionCallback called when threshold is reached (only when defined).

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));
  },
);
MethodDescription
resetResets the scratcher state to the initial values.
revealReveals 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 #

40
likes
110
pub points
86%
popularity

Publisher

rykowski.dev

Scratch card widget which temporarily hides content from user.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on scratcher