scratcher 1.2.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 89

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.2.1"
  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.
imagePathStringPath to the local image asset which could be additionally used to cover the child widget.
imageFitBoxFitDetermines how the image should be drawn in case of remaining space (like contain or cover).
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.

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

example/lib/main.dart

import 'package:flutter/material.dart';

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      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: [
              AdvancedScreen(),
              BasicScreen(),
            ],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  scratcher: ^1.2.1

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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
79
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
89
Learn more about scoring.

We analyzed this package on Nov 15, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

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.7 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test
pedantic ^1.7.0