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.
import 'package:flutter/material.dart';
import 'package:scratch_card_flutter/scratch_card.dart';
void main() => runApp(const ExampleApp());
class ExampleApp extends StatelessWidget {
const ExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Scratch Card Example',
theme: ThemeData(useMaterial3: true),
home: const ExampleHome(),
);
}
}
class ExampleHome extends StatefulWidget {
const ExampleHome({super.key});
@override
State<ExampleHome> createState() => _ExampleHomeState();
}
class _ExampleHomeState extends State<ExampleHome> {
String _message = 'You won 100 points!';
void _openDialog() {
showDialog(
context: context,
builder: (context) {
return Center(
child: SizedBox(
width: 340,
height: 220,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
child: ScratchCard(
brushSize: 36,
coverColor: Colors.blue.shade400,
revealThreshold: .6,
child: _buildCardContent(),
),
),
),
);
},
);
}
Widget _buildCardContent() {
return Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
),
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.celebration, size: 48, color: Colors.orange),
const SizedBox(height: 8),
Text(
_message,
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
],
),
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Scratch Card Example')),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Center(
child: ElevatedButton(
onPressed: _openDialog,
child: const Text('Open Scratch Card in Dialog'),
),
),
),
);
}
}