flutter_digilocker_aadhar_pan 1.0.1
flutter_digilocker_aadhar_pan: ^1.0.1 copied to clipboard
Flutter plugin for seamless DigiLocker Aadhar and PAN verification integration.
import 'package:flutter/material.dart';
import 'package:flutter_digilocker_aadhar_pan/flutter_digilocker_aadhar_pan.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'DigiLocker Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
useMaterial3: true,
),
home: const DigiLockerDemo(),
);
}
}
class DigiLockerDemo extends StatefulWidget {
const DigiLockerDemo({super.key});
@override
State<DigiLockerDemo> createState() => _DigiLockerDemoState();
}
class _DigiLockerDemoState extends State<DigiLockerDemo> {
bool _showDigiLocker = false;
String _resultText = 'No verification yet';
String _userName = '';
String _aadharNo = '';
String _panNo = '';
// Configure your DigiLocker credentials here
final config = const DigiLockerConfig(
companyName: 'your-company-name',
secretToken: 'your-secret-token',
redirectUrl: 'https://your-redirect-url.com',
documents: 'aadhaar,pan', // Optional: default is 'aadhaar,pan'
panName: '', // Optional: PAN card holder name
panNo: '', // Optional: PAN number
);
void _handleSuccess(DigiLockerResponse response) {
setState(() {
_resultText = 'Verification Successful!';
_userName = response.data?.name ?? 'N/A';
_aadharNo = response.data?.aadharNo ?? 'N/A';
_panNo = response.data?.panNumber ?? 'N/A';
});
// Show success dialog
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('Success'),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Name: $_userName'),
const SizedBox(height: 8),
Text('Aadhar: $_aadharNo'),
const SizedBox(height: 8),
Text('PAN: $_panNo'),
],
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('OK'),
),
],
),
);
// Log success (use a proper logging solution in production)
// ignore: avoid_print
print('DigiLocker Success: ${response.toJson()}');
}
void _handleError(String error) {
setState(() {
_resultText = 'Error: $error';
});
// Show error dialog
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('Error'),
content: Text(error),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('OK'),
),
],
),
);
// Log error (use a proper logging solution in production)
// ignore: avoid_print
print('DigiLocker Error: $error');
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(
'DigiLocker Demo',
style: TextStyle(color: Colors.white),
),
backgroundColor: const Color(0xFF0066CC),
elevation: 2,
),
body: Stack(
children: [
// Main content
Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// Logo or Icon
const Icon(
Icons.verified_user,
size: 80,
color: Color(0xFF0066CC),
),
const SizedBox(height: 32),
// Title
const Text(
'DigiLocker Verification',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 16),
// Description
const Text(
'Verify your Aadhar and PAN documents securely with DigiLocker',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 16,
color: Colors.grey,
),
),
const SizedBox(height: 48),
// Verify Button
ElevatedButton(
onPressed: () {
setState(() {
_showDigiLocker = true;
});
},
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF0066CC),
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
elevation: 2,
),
child: const Text(
'Verify with DigiLocker',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(height: 32),
// Result Card
Card(
elevation: 2,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Verification Result:',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 12),
Text(
_resultText,
style: const TextStyle(fontSize: 14),
),
if (_userName.isNotEmpty) ...[
const SizedBox(height: 12),
const Divider(),
const SizedBox(height: 12),
_buildInfoRow('Name:', _userName),
const SizedBox(height: 8),
_buildInfoRow('Aadhar:', _aadharNo),
const SizedBox(height: 8),
_buildInfoRow('PAN:', _panNo),
],
],
),
),
),
],
),
),
// DigiLocker Modal
if (_showDigiLocker)
DigiLockerWidget(
config: config,
onSuccess: _handleSuccess,
onError: _handleError,
onClose: () {
setState(() {
_showDigiLocker = false;
});
},
),
],
),
);
}
Widget _buildInfoRow(String label, String value) {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 80,
child: Text(
label,
style: const TextStyle(
fontWeight: FontWeight.w600,
color: Colors.grey,
),
),
),
Expanded(
child: Text(
value,
style: const TextStyle(
fontWeight: FontWeight.w500,
),
),
),
],
);
}
}