scanEmirateID static method
Implementation
static Future<EmirateIdModel?> scanEmirateID({
required File image,
}) async {
List<String> eIdDates = [];
final textDetector = TextRecognizer(script: TextRecognitionScript.latin);
final RecognizedText recognizedText =
await textDetector.processImage(InputImage.fromFilePath(image.path));
if (!recognizedText.text
.toString()
.toLowerCase()
.contains("resident identity card".toLowerCase()) &&
!recognizedText.text
.toString()
.toLowerCase()
.contains("UNITED ARAB EMIRATES".toLowerCase())) {
return null;
}
final listText = recognizedText.text.split('\n');
// attributes
String? name;
String? number;
String? nationality;
String? sex;
for (var element in listText) {
if (_isDate(text: element.trim())) {
eIdDates.add(element.trim());
} else if (_isName(text: element.trim()) != null) {
name = _isName(text: element.trim());
} else if (_isNationality(text: element.trim()) != null) {
nationality = _isNationality(text: element.trim());
} else if (_isSex(text: element.trim()) != null) {
sex = _isSex(text: element.trim());
} else if (_isNumberID(text: element.trim())) {
number = element.trim();
}
}
eIdDates = _sortDateList(dates: eIdDates);
textDetector.close();
return EmirateIdModel(
name: name!,
number: number!,
nationality: nationality,
sex: sex,
dateOfBirth: eIdDates.length == 3 ? eIdDates[0] : null,
issueDate: eIdDates.length == 3 ? eIdDates[1] : null,
expiryDate: eIdDates.length == 3 ? eIdDates[2] : null,
);
}