initializeCafSdk method

  1. @override
Future<bool> initializeCafSdk({
  1. required CafSdkConfiguration cafSdkConfiguration,
  2. CafDocumentDetectorConfiguration? documentDetectorConfiguration,
  3. CafDocumentDetectorUIConfiguration? documentDetectorUIConfiguration,
  4. CafFaceLivenessConfiguration? faceLivenessConfiguration,
  5. CafFaceLivenessUIConfiguration? faceLivenessUIConfiguration,
})
override

Implementation

@override
Future<bool> initializeCafSdk({
  required CafSdkConfiguration cafSdkConfiguration,
  CafDocumentDetectorConfiguration? documentDetectorConfiguration,
  CafDocumentDetectorUIConfiguration? documentDetectorUIConfiguration,
  CafFaceLivenessConfiguration? faceLivenessConfiguration,
  CafFaceLivenessUIConfiguration? faceLivenessUIConfiguration,
}) async {
  CafSdkValidator.validatePresentationOrder(
    cafSdkConfiguration.configuration.presentationOrder,
  );

  final initResult = await methodChannel.invokeMethod<bool>('initialize', {
    "jsonString": jsonEncode(cafSdkConfiguration),
  });
  if (initResult != true) return false;

  if (documentDetectorConfiguration != null) {
    final result = await methodChannel.invokeMethod<bool>('applyCafDocumentDetector', {
      "jsonString": jsonEncode(documentDetectorConfiguration),
    });
    if (result != true) return false;
  }

  if (documentDetectorUIConfiguration != null) {
    final result = await methodChannel.invokeMethod<bool>('applyCafDocumentDetectorUI', {
      "jsonString": jsonEncode(documentDetectorUIConfiguration),
    });
    if (result != true) return false;
  }

  if (faceLivenessConfiguration != null) {
    final result = await methodChannel.invokeMethod<bool>('applyCafFaceLiveness', {
      "jsonString": jsonEncode(faceLivenessConfiguration),
      "timestamp": DateTime.now().toIso8601String(),
    });
    if (result != true) return false;
  }

  if (faceLivenessUIConfiguration != null) {
    final result = await methodChannel.invokeMethod<bool>('applyCafFaceLivenessUI', {
      "jsonString": jsonEncode(faceLivenessUIConfiguration),
      "timestamp": DateTime.now().toIso8601String(),
    });
    if (result != true) return false;
  }

  final startResult = await methodChannel.invokeMethod<bool>('start');
  return startResult == true;
}