id_doc_kit
A lightweight, production-ready Flutter/Dart package for validating Indian ID documents used in KYC, onboarding, and fintech workflows.
Built with a strict core architecture, structured results, and developer-friendly UI helpers.
๐ Live Demo
Try it out in your browser! ๐ View Live Demo
The demo showcases all supported document types with real-time validation feedback, automatic formatting, and metadata extraction.
โจ Supported Documents
โ
Aadhaar (12-digit UID & 16-digit VID with Verhoeff Checksum)
โ
PAN (with Holder Type detection - Individual, Company, Trust, etc.)
โ
GSTIN (with State detection)
โ
Driving License (Strict RTO rules + Legacy support + Fallback logic)
โ
Voter ID (EPIC)
โ
Passport
โ
PIN Code (India)
โ
Phone Number (India - handles +91 prefix)
โ
Email
๐ Key Features
- ๐ฆ Structured Results: Returns
IdDocumentResultwith error codes, human-friendly messages, and metadata. - โจ๏ธ Smart Formatters: Built-in
TextInputFormatterfor auto-spacing (Aadhaar) and case correction (PAN/GSTIN) with cursor preservation. - ๐ Auto Detection: Identify the document type automatically from a raw string using
validateAuto. - ๐ท Metadata Extraction: Parse state codes, RTO numbers, holder types, and issuance years.
- ๐ฌ Friendly Messages: Pre-configured human-readable messages via the
friendlyMessageextension. - ๐ง Confidence Scores: Deterministic scoring (0.0 to 1.0) for validation certainty.
๐ฆ Result Structure
IdDocumentResult {
type, // IdDocumentType.pan, .aadhaar, etc.
isValid, // Boolean
rawValue, // Original input
normalizedValue, // Stripped of spaces/formatting
metadata, // Map containing State, RTO, Holder Type, etc.
confidence, // 0.0 to 1.0
errorCode, // Machine-readable (e.g., 'PAN_INVALID_FORMAT')
errorMessage // Raw technical error
}
// UI Extension for human-readable feedback
print(result.friendlyMessage); // "Invalid PAN format. Example: ABCDE1234F"
โจ๏ธ Real-time Input Formatting
Enhance UX by applying formatters directly to your TextFormField. These formatters handle cursor position preservation and real-time cleanup.
| Document | Formatting Logic | Keyboard Type |
|---|---|---|
| Aadhaar | 1234 5678 9012 (Auto-space) |
Number |
| PAN | ABCDE1234F (Auto-uppercase) |
Text (Capitalized) |
| Phone | Strips non-digits, handles +91 |
Phone |
Direct usage:
TextFormField(
inputFormatters: [IdInputFormatters.getFormatter(IdDocumentType.aadhaar)],
keyboardType: TextInputType.number,
);
๐จ UI Widgets
1. IdTextField (Quickest Integration)
A specialized TextFormField that handles formatting, keyboard types, capitalization, and validation automatically.
IdTextField(
type: IdDocumentType.pan,
autoFormat: true,
decoration: InputDecoration(labelText: "Enter PAN"),
onValidationChanged: (isValid) {
setState(() => isPanValid = isValid);
},
)
2. IdField (Custom UI Builder)
Use this for full UI control while the library manages the logic, formatting, and result state.
IdField(
type: IdDocumentType.aadhaar,
builder: (context, controller, result) {
return Column(
children: [
TextField(controller: controller),
if (result != null && !result.isValid)
Text(result.friendlyMessage, style: TextStyle(color: Colors.red)),
],
);
},
);
๐งช Advanced Logic
Smart Auto-Detection:
// Input: "ABCDE1234F"
final result = IdValidator.instance.validateAuto(input);
print(result.type); // IdDocumentType.pan
Metadata Extraction:
final result = IdValidator.instance.validate(type: IdDocumentType.pan, value: input);
// Access parsed metadata
final holder = result.metadata?['holderType']; // 'Individual', 'Company', etc.
final state = result.metadata?['stateName']; // 'Karnataka' (for DL/GSTIN)
๐ Disclaimer
This package performs format and structural validation (checksums, regex, and patterns). It does not verify the identity against government databases (UIDAI, NSDL, etc.).
โ Support & Sponsorship
If id_doc_kit saves you development time or helps in production, consider supporting its development.