Skip to main content

scratch_reveal 1.2.1 copy "scratch_reveal: ^1.2.1" to clipboard
scratch_reveal: ^1.2.1 copied to clipboard

Interactive scratch card and scratch-to-reveal canvas widget for Flutter with zero-latency foil scratching, flying particles, and fast bitmask tracking.

scratch_reveal #

Pub Version Pub Points Live Demo Pub Likes CI License

scratch_reveal Showcase

An interactive, high-performance scratch-to-reveal card widget for Flutter. Features zero-latency real-time foil scratching, instant punch holes on touch down, flying metallic foil dust particles, coin serration brushes, and sub-0.1ms spatial bitmask progress calculation.


⚡ Why scratch_reveal? #

Existing scratch card packages on pub.dev suffer from fundamental architectural flaws:

  • 🚫 Touch-Down Latency: Gesture drag detectors ignore the initial touch or delay painting until moving 18px past slop thresholds. scratch_reveal creates an immediate circular punch hole on pointer contact.
  • 🚫 Bitmap Pixel Reading Stutters: Many packages read raw bitmap pixels out of CPU image buffers on every drag frame, causing micro-stutters and frame drops.
  • 🚫 Dropped Repaints: Mutable stroke arrays can prevent CustomPainter from invalidating. scratch_reveal's GPU compositing pipeline renders guaranteed 120 FPS eraser strokes on high-refresh-rate devices.

scratch_reveal solves this with a 2D Spatial Bitmask Grid Engine:

  1. Zero-Latency Touch Response: Immediate contact scratch and real-time streaming line follow.
  2. Sub-0.1ms Progress Calculation: Calculates the exact percentage scratched instantly without querying GPU memory or freezing the UI thread.
  3. GPU BlendMode.clear Pipeline: Buttery smooth 120 FPS eraser strokes on high-refresh-rate mobile devices.
  4. Flying Metallic Foil Dust & Sparkles: Physically simulated foil shavings and sparkle glints fly from the scratch point.
  5. Threshold Auto-Reveal & Animations: Smoothly fades/scales out remaining foil once the target threshold (e.g. 60%) is reached.
  6. Rich Styling: Solid colors, multi-stop metallic gradients (silver/gold foil), or custom widget overlays.
  7. Zero Native C++: 100% pure Flutter & Dart across iOS, Android, Web, macOS, Windows, and Linux.

📦 Installation #

Add scratch_reveal to your pubspec.yaml:

dependencies:
  scratch_reveal: ^1.1.1

Or run:

flutter pub add scratch_reveal

🚀 Quick Start #

1. Metallic Foil Scratch Card with Auto-Reveal #

import 'package:flutter/material.dart';
import 'package:scratch_reveal/scratch_reveal.dart';

class PromoScratchCard extends StatelessWidget {
  const PromoScratchCard({super.key});

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: 320,
      height: 180,
      child: ClipRRect(
        borderRadius: BorderRadius.circular(20),
        child: ScratchReveal(
          brushSize: 40.0,
          threshold: 0.65, // Auto-reveals at 65% scratched
          coverGradient: const LinearGradient(
            colors: [Color(0xFFE2E8F0), Color(0xFF94A3B8), Color(0xFF475569)],
          ),
          cover: const Center(
            child: Text('SCRATCH TO REVEAL', style: TextStyle(fontWeight: FontWeight.bold, color: Colors.white)),
          ),
          revealedChild: Container(
            color: const Color(0xFFD97706),
            alignment: Alignment.center,
            child: const Text('🎉 ₹500 VOUCHER CODE: LUCKY2026', style: TextStyle(color: Colors.white, fontSize: 16)),
          ),
          onThresholdReached: () {
            print('Reward unlocked!');
          },
          onProgressUpdate: (progress) {
            print('Progress: ${(progress * 100).toInt()}%');
          },
        ),
      ),
    );
  }
}

2. Programmatic Reveal & Reset #

final scratchKey = GlobalKey<ScratchRevealState>();

// Reset the card back to unscratched:
scratchKey.currentState?.reset();

// Automatically reveal the reward:
scratchKey.currentState?.reveal();

🛠️ API Reference #

ScratchReveal Properties #

Property Type Default Description
revealedChild Widget Required The underlying prize or content to be revealed.
cover Widget? null Optional visual widget overlay (e.g. icon + text).
coverColor Color Color(0xFF64748B) Solid color of the scratch foil.
coverGradient Gradient? null Gradient for realistic metallic foil textures.
brushSize double 36.0 Thickness of the eraser stroke in logical pixels.
threshold double 0.60 Fraction in [0.0, 1.0] needed to trigger auto-reveal.
autoReveal bool true Whether to animate remaining foil away at threshold.
revealDuration Duration Duration(milliseconds: 600) Transition animation duration.
onThresholdReached VoidCallback? null Fired once when threshold is met.
onProgressUpdate ValueChanged<double>? null Continuous progress callback [0.0, 1.0].
enableHaptics bool false Triggers subtle tactile haptics while scratching.

💖 Support the Project #

If you find this project useful, consider supporting its active maintenance and future development:

Buy Me A Coffee GitHub Sponsors Patreon


📄 License #

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Maintained with ❤️ by Govind Tank.

2
likes
0
points
795
downloads

Publisher

verified publishergovindtank.is-a.dev

Weekly Downloads

Interactive scratch card and scratch-to-reveal canvas widget for Flutter with zero-latency foil scratching, flying particles, and fast bitmask tracking.

Repository (GitHub)
View/report issues

Topics

#scratch-card #scratch-to-reveal #lottery #gamification #animation

Funding

Consider supporting this project:

github.com
buymeacoffee.com

License

unknown (license)

Dependencies

flutter

More

Packages that depend on scratch_reveal