in ,

Scratch card widget which temporarily hides content from users


Scratch cards are one of the most popular things that you can find on various shopping apps and payment applications. In the most general way, a scratch card is a card designed for competitions, often made of thin cardstock or plastic to conceal PINs, where one or more areas contain concealed information that can be revealed by scratching off an opaque covering. So, sometimes we wonder how to create scratch cards that temporarily hide content from the users.

In this tutorial article, we will learn about the Scratch card widget, which temporarily hides content from the user. 

scratch card


To begin with Scratch cards, here are some features of it:

  • Android and iOS support
  • Cover content with full color or custom image
  • Track the scratch progress and threshold
  • Fully configurable

Getting started

Let’s get Started

In this step, there are two things you have to do.

  1. First thing you need to do is adding the scratcher as a project dependency in pubspec.yaml:
 scratcher: "^2.1.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:
  brushSize: 30,
  threshold: 50,
  onChange: (value) => print("Scratch progress: $value%"),
  onThreshold: () => print("Threshold reached, you won!"),
  child: Container(
    height: 300,
    width: 300,


childWidgetWidget rendered under the scratch area.
enabledboolWhether new scratches can be applied.
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.
rebuildOnResizeboolDetermines if the scratcher should rebuild itself when space constraints change (resize).
onChangeFunctionCallback called when new part of area is revealed (min 0.1% difference).
onThresholdFunctionCallback called when threshold is reached (only when defined).
onScratchStartFunctionCallback called when scratching starts.
onScratchUpdateFunctionCallback called during scratching.
onScratchEndFunctionCallback called when scratching ends.

Programmatic access

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

final scratchKey = GlobalKey<ScratcherState>();

  key: scratchKey,
  // remaining properties

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

  child: const Text('Reset'),
  onPressed: () {
    scratchKey.currentState.reset(duration: Duration(milliseconds: 2000));

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.


Written by James

Flutterwave landing page animated card deck implemented with Flutter

Flutter-Dart code to display a list of amazing scrollable cards of retail shops