scratch_card_flutter 1.0.1+0
scratch_card_flutter: ^1.0.1+0 copied to clipboard
Interactive scratch-card widget for Flutter — reveal hidden content with touch, configurable brush size, cover color, and auto-reveal threshold.
scratch_card #
A small Flutter package providing a "scratch-to-reveal" widget.
Overview #
This repository contains the scratch_card package and an example/ app demonstrating how to use it.
The main widget is ScratchCard (exported from lib/scratch_card.dart). It wraps any Flutter Widget and provides a scratchable cover layer that can be cleared by the user. The widget supports customizable brush size, cover color, and an automatic reveal threshold.
Quick Usage #
Import the package and wrap the content you want revealed with ScratchCard:
import 'package:flutter/material.dart';
import 'package:scratch_card/scratch_card.dart';
class Example extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ScratchCard(
revealThreshold: 0.5, // auto-reveal when ~50% scratched
brushSize: 40.0,
coverColor: Colors.grey.shade400,
onRevealed: () => debugPrint('Content revealed'),
child: Center(
child: Text('You won!', style: TextStyle(fontSize: 24)),
),
);
}
}
Key constructor properties:
child(required): The widget shown beneath the scratch cover.brushSize: Radius of the scratch brush in logical pixels.coverColor: Color of the cover layer.revealThreshold: Fraction between0.0and1.0(default0.6) that controls when the widget auto-reveals — e.g.,0.5means approximately 50% of the area must be scratched.onRevealed: Optional callback fired once auto-reveal completes.gridCellSize: Internal tuning parameter (smaller values give more accurate percent estimation).
You can change the UI from outside by providing any widget to the child parameter — full Flutter composition applies. That means you can build complex layouts, images, or animations under the scratch layer and update them from parent state as usual.