Collecting the Responses
The startOcr method returns a Future<OcrReturnValues>. No manual JSON decoding is needed — the plugin already delivers typed Dart objects.
OcrReturnValues
class OcrReturnValues {
final List<DocumentRecognitionItem> documentRecognitionResponse;
}
| Attribute | Type | Description |
|---|---|---|
| documentRecognitionResponse | List<DocumentRecognitionItem> | List with one entry per capture performed by the user. |
DocumentRecognitionItem
class DocumentRecognitionItem {
final String? ocrKey;
final String? ocrFrontKey;
final String? ocrBackKey;
final String documentType;
}
| Attribute | Type | Description |
|---|---|---|
| ocrKey | String? | Image identification key, present for single-capture documents (cnhFull, cnhDigital, address, rgCinDigital). It can be used in any other service of the QI Tech system. |
| ocrFrontKey | String? | Identification key of the front image, present for dual-capture documents (cnh, rg, rne, crnm). |
| ocrBackKey | String? | Identification key of the back image, present for dual-capture documents (cnh, rg, rne, crnm). |
| documentType | String | Identifies which document that key refers to (e.g. "cnh", "rg", "proof_of_address"). |
Important
Store the returned keys — they are the image identifier in the other products of the QI Tech system, such as the Onboarding API.
Reading the response
final result = await plugin.startOcr(
CaaSEnvironment.sandbox,
'<YOUR_MOBILE_TOKEN_SENT_BY_QITECH>',
CaaSDocumentType.cnh,
);
for (final item in result.documentRecognitionResponse) {
if (item.ocrKey != null) {
print('Ocr key: ${item.ocrKey} document type: ${item.documentType}');
}
if (item.ocrFrontKey != null) {
print('Ocr front key: ${item.ocrFrontKey} document type: ${item.documentType}');
}
if (item.ocrBackKey != null) {
print('Ocr back key: ${item.ocrBackKey} document type: ${item.documentType}');
}
}
Error handling
Warning
Unlike startFaceRecon, which throws a typed FaceReconException, the startOcr method throws a String containing the error message. Use a generic catch (e).
try {
final result = await plugin.startOcr(
CaaSEnvironment.sandbox,
'<YOUR_MOBILE_TOKEN_SENT_BY_QITECH>',
CaaSDocumentType.cnh,
);
// ...
} catch (e) {
print('Error executing OCR: $e');
}
Most common error messages
| Message | Meaning |
|---|---|
User canceled OCR | The user interrupted the capture flow before completing it. |
Error executing OCR: <detail> | The native iOS SDK ended the flow with an error. |
at startOcr: <detail> | A required parameter was missing from the call. |
Activity is null | On Android, the SDK could not obtain the host activity. |