scratcher 1.3.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 92

scratcher #

Scratch card widget which temporarily hides content from user.



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:
 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:
  brushSize: 30,
  threshold: 50,
  onChange: (value) { print("Scratch progress: $value%"); },
  onThreshold: () { print("Threshold reached, you won!"); },
  child: Container(
    height: 300,
    width: 300,

Properties #

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>();

  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.

Resources #

1.3.0 #

  • Added image to support for asset, network & memory images
  • Removed imagePath (use image: Image.asset(...) instead)
  • Removed imageFit (configure through image fields instead)

1.2.1 #

  • Fix issue with scratch area size

1.2.0 #

  • Removed revealDuration parameter - same effect can be now achieved through reveal() method
  • Added programmatic access to scratch widget - reset() and reveal() methods
  • Minor performance improvements and memory management

1.1.0 #

  • Added revealDuration parameter to automatically reveal area on threshold
  • Major performance improvements

1.0.0 #

  • Added accuracy parameter to control performance level
  • Improved algorithm calculating the progress
  • Fixed size of the scratch area
  • More fun & complex example

0.0.5 #

  • Improve code quality (pedantic)

0.0.4 #

  • Fix scratcher size

0.0.3 #

  • Readme images

0.0.2 #

  • Extend documentation
  • Add example project

0.0.1 #

  • Initial release


import 'package:flutter/material.dart';

import 'advanced.dart';
import 'basic.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
      home: DefaultTabController(
        length: 2,
        child: Scaffold(
          bottomNavigationBar: TabBar(
            labelColor: Colors.blueAccent,
            unselectedLabelColor: Colors.blueGrey,
            indicatorColor: Colors.blueAccent,
            indicatorSize: TabBarIndicatorSize.label,
            tabs: [
              Tab(icon: Icon(Icons.looks_one)),
              Tab(icon: Icon(Icons.looks_two)),
          body: TabBarView(
            physics: const NeverScrollableScrollPhysics(),
            children: [

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  scratcher: ^1.3.0

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:scratcher/scratcher.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 21, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
pedantic ^1.7.0