kenya_id_ocr 0.1.2
kenya_id_ocr: ^0.1.2 copied to clipboard
A Flutter package for scanning and extracting data from Kenyan National ID cards using Google ML Kit OCR.
kenya_id_ocr #
A Flutter package for scanning and extracting data from Kenyan National ID cards (front side) using Google ML Kit ā fully on-device, no API key required.
Features #
- š· Built-in camera scanner widget with ID card overlay guide
- šļø Parse ID data from an image file or bytes
- š Extracts: ID Number, Full Name, Date of Birth, District of Birth, Gender
- ā” On-device ML Kit OCR ā works offline
- š ļø Handles common OCR misreads (Iā1, Oā0)
Platform setup #
Android #
In android/app/build.gradle, ensure minSdkVersion is at least 21.
Add to android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.CAMERA"/>
<!-- ML Kit model download -->
<application ...>
<meta-data
android:name="com.google.mlkit.vision.DEPENDENCIES"
android:value="ocr"/>
</application>
iOS #
In ios/Runner/Info.plist:
<key>NSCameraUsageDescription</key>
<string>Camera is used to scan your Kenyan National ID</string>
Usage #
Camera scanner widget #
import 'package:kenya_id_ocr/kenya_id_ocr.dart';
final result = await Navigator.push<KenyaIdResult>(
context,
MaterialPageRoute(
builder: (_) => KenyaIdScanner(
onResult: (r) => Navigator.pop(context, r),
minConfidence: 0.6, // optional, default 0.6
),
),
);
if (result != null && result.isValid) {
print(result.idNumber); // "12345678"
print(result.fullName); // "KAMAU JOHN MWANGI"
print(result.dateOfBirth);// "01.01.1990"
print(result.district); // "NAIROBI"
print(result.gender); // "M"
}
Read from an existing image file #
final reader = KenyaIdReader();
final result = await reader.readFromFile(File('/path/to/id_photo.jpg'));
await reader.dispose();
print(result);
Result model #
| Field | Type | Description |
|---|---|---|
idNumber |
String? |
7ā9 digit ID number |
fullName |
String? |
Full name in uppercase |
dateOfBirth |
String? |
As printed, e.g. 01.01.1990 |
dateOfBirthParsed |
DateTime? |
Parsed DateTime |
districtOfBirth |
String? |
District/county name |
gender |
String? |
"M" or "F" |
confidence |
double |
0.0ā1.0 score based on fields found |
isValid |
bool |
True if ID number + name found |
rawText |
String |
Full OCR output for custom parsing |
Notes #
- Lighting and focus significantly affect accuracy. Encourage users to scan in good light.
- The
rawTextfield is exposed so you can build custom parsing logic on top if needed. - This package reads the front side only.
License #
MIT