Implementation
The startOcr method opens the native document capture flow, sends the images to QI Tech's OCR API and returns the keys of the processed images.
Mobile Token
We use a Mobile Token to allow your application authenticated access to our API. It has probably already been sent to you by email. If you have not received your token yet, send an email to suporte.caas@qitech.com.br.
Each environment (sandbox and production) requires a different Mobile Token.
Method signature
Future<OcrReturnValues> startOcr(
CaaSEnvironment environment,
String mobileToken,
CaaSDocumentType document, {
OcrOptions? options,
})
The first three parameters are positional and required. Customizations are optional and passed through the named options parameter, described in The OcrOptions object.
Minimal example
import 'package:flutter_kyc_qitech/flutter_kyc_qitech.dart';
final _qitechFlutterKycPlugin = FlutterKycQitech();
final result = await _qitechFlutterKycPlugin.startOcr(
CaaSEnvironment.sandbox,
'<YOUR_MOBILE_TOKEN_SENT_BY_QITECH>',
CaaSDocumentType.cnh,
);
for (final item in result.documentRecognitionResponse) {
print('${item.documentType}: ${item.ocrKey ?? item.ocrFrontKey ?? item.ocrBackKey}');
}
Complete example
import 'package:flutter/material.dart';
import 'package:flutter_kyc_qitech/flutter_kyc_qitech.dart';
class OcrButton extends StatelessWidget {
const OcrButton({super.key});
static const String _mobileToken = '<YOUR_MOBILE_TOKEN_SENT_BY_QITECH>';
Future<void> _startOcr() async {
final plugin = FlutterKycQitech();
try {
final result = await plugin.startOcr(
CaaSEnvironment.sandbox,
_mobileToken,
CaaSDocumentType.cnh,
options: OcrOptions(
sessionId: '<SESSION_ID>',
fontColor: '#FFFFFF',
backgroundColor: '#000000',
fontFamily: CaaSFontFamily.openSans,
showIntroductionScreens: true,
showSuccessScreen: false,
audioConfiguration: FaceReconAudioConfiguration.enable,
onboardingTextConfiguration: OnboardingTextConfiguration(
onboardingTitle: 'Important tips',
onboardingFirstLabel: 'Go to a well-lit place',
onboardingSecondLabel: 'Remove the document from plastic',
onboardingThirdLabel: 'Make sure the document is properly framed',
),
logLevel: CaaSLogLevel.debug,
),
);
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}');
}
}
} catch (e) {
// startOcr throws a String containing the error message
print('Error executing OCR: $e');
}
}
@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: _startOcr,
child: const Text('Capture document'),
);
}
}
Enable support for the Portrait and Landscape Right orientations in your application for the native iOS SDK to work correctly.
Capture flow by document type
The document parameter defines how many captures the user performs and, consequently, how many items the response contains.
| Document type | Captures | Response |
|---|---|---|
CaaSDocumentType.cnhFull | 1 (open CNH) | 1 item with ocrKey |
CaaSDocumentType.cnhDigital | 1 (digital CNH PDF) | 1 item with ocrKey |
CaaSDocumentType.address | 1 (proof of address) | 1 item with ocrKey |
CaaSDocumentType.rgCinDigital | 1 (digital RG/CIN PDF) | 1 item with ocrKey |
CaaSDocumentType.cnh | 2 (front and back) | 2 items: ocrFrontKey and ocrBackKey |
CaaSDocumentType.rg | 2 (front and back) | 2 items: ocrFrontKey and ocrBackKey |
CaaSDocumentType.rne | 2 (front and back) | 2 items: ocrFrontKey and ocrBackKey |
CaaSDocumentType.crnm | 2 (front and back) | 2 items: ocrFrontKey and ocrBackKey |
Sample app
The plugin repository contains a ready-to-run sample app, under flutter_kyc_qitech/example, demonstrating the use of all three SDKs. To run it, create a .env file in the example folder with the credentials below, then run flutter pub get followed by flutter run with a physical device connected:
FACERECON_API_URL_SANDBOX=''
FACERECON_API_KEY_SANDBOX=''
OCR_MOBILE_TOKEN_SANDBOX=''
DEVICE_SCAN_API_URL_SANDBOX=''
DEVICE_SCAN_API_KEY_SANDBOX=''
If you have not received your credentials yet, contact suporte.caas@qitech.com.br.