readNfcDocument method
Read NFC document
Implementation
Future<PersonDetails?> readNfcDocument(String documentType) async {
try {
// Call the NFC reader plugin directly through the platform channel
// The NFC reader plugin is now included directly in the main app
final result = await _plugin.readNfcDocument(documentType);
if (result != null) {
print('NFC document read successfully');
print('Document info: $result');
// Extract personDetails from the nested structure
final personDetails = result['personDetails'] as Map<String, dynamic>?;
final docType = result['docType'] as String?;
if (personDetails != null) {
// Convert the result to our PersonDetails
return PersonDetails(
name: personDetails['name'] ?? '',
surname: personDetails['surname'] ?? '',
personalNumber: personDetails['personal_number'] ?? '',
gender: personDetails['gender'] ?? '',
dateOfBirth: personDetails['date_of_birth'] ?? '',
dateOfExpiry: personDetails['date_of_expiry'] ?? '',
documentNumber: personDetails['document_number'] ?? '',
nationality: personDetails['nationality'] ?? '',
issuerAuthority: personDetails['issuer_authority'] ?? '',
faceImageBase64: personDetails['faceImageBase64'] ?? '',
documentType: personDetails['document_type'] ?? docType ?? '',
documentCountry: personDetails['document_country'] ?? '',
portraitImageBase64: personDetails['portraitImageBase64'] ?? '',
signatureBase64: personDetails['signatureBase64'] ?? '',
fingerprintsBase64: null, // Not provided by Android NFC activity
);
} else {
print('No personDetails found in NFC result');
return null;
}
} else {
print('NFC reading returned null');
return null;
}
} catch (e) {
print('Error reading NFC document: $e');
rethrow;
}
}