flutter_secure_pin_pad 1.0.0
flutter_secure_pin_pad: ^1.0.0 copied to clipboard
An enterprise-grade customizable PIN entry pad widget for Flutter with biometric auth fallback, anti-shoulder surfing shuffle mode, and lockout timers.
import 'package:flutter/material.dart';
import 'package:flutter_secure_pin_pad/flutter_secure_pin_pad.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Secure PIN Pad Demo',
theme: ThemeData.dark(useMaterial3: true),
home: const PinScreen(),
);
}
}
class PinScreen extends StatefulWidget {
const PinScreen({super.key});
@override
State<PinScreen> createState() => _PinScreenState();
}
class _PinScreenState extends State<PinScreen> {
final GlobalKey<State<SecurePinPad>> _pinKey = GlobalKey();
final PinPadController _controller = PinPadController(
pinLength: 4,
maxFailedAttempts: 3,
lockoutDuration: const Duration(seconds: 15),
);
bool _isShuffleEnabled = false;
void _onPinSubmitted(String pin) {
if (pin == '1234') {
_controller.recordSuccess();
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('🎉 Correct PIN entered! Access Granted.'),
backgroundColor: Colors.green,
),
);
} else {
_controller.recordFailedAttempt();
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('❌ Invalid PIN! Please try again.'),
backgroundColor: Colors.redAccent,
),
);
}
}
void _onBiometricPressed() {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('👆 Biometric authentication triggered!')),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('flutter_secure_pin_pad Demo'),
actions: [
IconButton(
icon: Icon(_isShuffleEnabled ? Icons.shuffle_on : Icons.shuffle),
tooltip: 'Toggle Anti-Shoulder Surfing Shuffle Mode',
onPressed: () => setState(() => _isShuffleEnabled = !_isShuffleEnabled),
),
],
),
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
children: [
const SizedBox(height: 20),
const Text(
'Enter Security PIN',
style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold),
),
const SizedBox(height: 8),
Text(
'Correct PIN is 1234 (Shuffle Mode: ${_isShuffleEnabled ? "ON" : "OFF"})',
style: const TextStyle(color: Colors.grey),
),
const Spacer(),
SecurePinPad(
key: _pinKey,
controller: _controller,
onPinSubmitted: _onPinSubmitted,
onBiometricPressed: _onBiometricPressed,
enableDigitShuffle: _isShuffleEnabled,
theme: PinPadTheme.dark(),
),
const Spacer(),
],
),
),
),
);
}
}