startVerification method
Future<VerificationResult<ScanResult> >
startVerification({
- String mode = 'match',
- void onDocumentScanned()?,
- void onLivenessCaptured()?,
- void onFaceMatchComplete()?,
Start the complete verification process
This orchestrates the entire verification flow including:
- Document scanning
- Face liveness detection
- Face matching
Parameters:
mode: Verification mode ('match' or 'liveness')onDocumentScanned: Callback when document scan completesonLivenessCaptured: Callback when liveness photo is capturedonFaceMatchComplete: Callback when face matching completes
Returns: A VerificationResult containing either the scan result or an error
Throws:
- SDKInitializationException if SDK is not initialized
Example:
final result = await GetVerified.instance.startVerification(
mode: 'match',
onDocumentScanned: (scanResult) {
print('Document scanned: ${scanResult.name}');
},
onFaceMatchComplete: (matched, similarity) {
print('Face match: $matched (${similarity}%)');
},
);
result.fold(
onSuccess: (data) => print('Success: ${data.name}'),
onFailure: (error) => print('Failed: ${error.message}'),
);
Implementation
Future<VerificationResult<ScanResult>> startVerification({
String mode = 'match',
void Function(ScanResult)? onDocumentScanned,
void Function(Uint8List)? onLivenessCaptured,
void Function(bool matched, double? similarity)? onFaceMatchComplete,
}) async {
if (!_isInitialized) {
return VerificationResult.failure(
const SDKInitializationException(
'SDK not initialized. Call initialize() first.',
code: ErrorCodes.initializationFailed,
),
);
}
try {
final solution = GetVerifiedSolution();
ScanResult? finalResult;
GetVerifiedException? capturedError;
await solution.startProcess(
faceApiUrl: _config!.faceApiUrl!,
mode: mode,
documentReaderConfig: _config!.documentReader,
faceSDKConfig: _config!.faceSDK,
onDocumentFetched: (scanResult) {
onDocumentScanned?.call(scanResult);
},
onFaceMismatch: () {
capturedError = const FaceVerificationException(
'Face verification failed - faces do not match',
code: ErrorCodes.faceMatchFailed,
);
},
onVerificationSuccess: (scanResult) {
finalResult = scanResult;
onFaceMatchComplete?.call(true, null);
},
onError: (error) {
capturedError = error;
},
);
// Wait a bit for async callbacks to complete
await Future.delayed(const Duration(milliseconds: 500));
if (capturedError != null) {
return VerificationResult.failure(capturedError!);
}
if (finalResult != null) {
return VerificationResult.success(finalResult!);
}
return VerificationResult.failure(
const DocumentScanException(
'Verification process did not complete',
code: ErrorCodes.scanFailed,
),
);
} on GetVerifiedException catch (e) {
return VerificationResult.failure(e);
} catch (e, stackTrace) {
return VerificationResult.failure(
GetVerifiedException(
'Unexpected error during verification: $e',
originalError: e,
stackTrace: stackTrace,
),
);
}
}