flutter_recaptcha 0.0.2
flutter_recaptcha: ^0.0.2 copied to clipboard
A lightweight Flutter widget that generates and validates distorted CAPTCHA images with background noise, to secure forms and authentication flows without any external service.
flutter_recaptcha #
A Flutter package that generates and validates distorted CAPTCHA images to secure your forms and authentication flows — no external service or API key required.
Features #
- Custom CAPTCHA rendering — a
CustomPainterdraws randomly rotated, distorted CAPTCHA text. - Background noise & distortion — randomized dots, lines, and circles make the CAPTCHA harder to read programmatically.
- Built-in validation — combines the CAPTCHA display with a text field and reports success/failure through a callback.
- Auto-regeneration — a new CAPTCHA is generated automatically after a failed attempt, or manually via the refresh button.
- Customizable — control the text style, field style, and widget size.
Getting started #
Add the package to your pubspec.yaml:
dependencies:
flutter_recaptcha: ^0.0.2
Then import it:
import 'package:flutter_recaptcha/flutter_recaptcha.dart';
Usage #
import 'package:flutter/material.dart';
import 'package:flutter_recaptcha/flutter_recaptcha.dart';
class CaptchaExample extends StatefulWidget {
const CaptchaExample({super.key});
@override
State<CaptchaExample> createState() => _CaptchaExampleState();
}
class _CaptchaExampleState extends State<CaptchaExample> {
final TextEditingController _controller = TextEditingController();
@override
Widget build(BuildContext context) {
return CaptchaWidget(
textField: TextField(
controller: _controller,
decoration: const InputDecoration(hintText: 'Enter the code above'),
),
onVerified: (isValid) {
if (isValid) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Verified!')),
);
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Incorrect code, try again.')),
);
}
},
);
}
}
Tap the check icon to validate, or the refresh icon to generate a new CAPTCHA at any time.
See the example folder for a complete, runnable app.
Additional information #
Found a bug or want a feature? Open an issue or pull request on the GitHub repository.