startFacialComparisonSDK method

  1. @override
Future<BlusaltLivenessResultResponse?> startFacialComparisonSDK({
  1. required String apiKey,
  2. required String appName,
  3. required String clientId,
  4. required bool isDev,
  5. required Uint8List imageData,
  6. LivenessFacialComparisonType livenessFacialComparisonType = LivenessFacialComparisonType.motional,
  7. bool? startProcessOnGettingToFirstScreen,
  8. double? thresholdInPercent,
  9. int? timeoutDurationInSec,
})
override

imageData is the image your want to compare with.

livenessFacialComparisonType can be LivenessFacialComparisonType.motional or LivenessFacialComparisonType.still

thresholdInPercent ranges between 0-100. The higher the value, the stricter the facial comparison. When set to null or no value is passed, it will use the default value from SDK which ranges from 90-94.

timeoutDurationInSec this value can be used top override the timeout duration of networks calls in the SDK. When set to null or no value is passed, it will use the default value from SDK 120s..

Implementation

@override
Future<BlusaltLivenessResultResponse?> startFacialComparisonSDK(
    {required String apiKey,
    required String appName,
    required String clientId,
    required bool isDev,
    required Uint8List imageData,
    LivenessFacialComparisonType livenessFacialComparisonType =
        LivenessFacialComparisonType.motional,
    bool? startProcessOnGettingToFirstScreen,
    double? thresholdInPercent,
    int? timeoutDurationInSec}) async {
  try {
    if (thresholdInPercent != null &&
        (thresholdInPercent < 0 || thresholdInPercent > 100)) {
      return BlusaltLivenessResultResponse(
          livenessResultType: BlusaltLivenessResultType.error,
          message: "Threshold must be between 0 and 100");
    }

    final result =
        await methodChannel.invokeMethod('startFacialComparisonSDK', {
      'apiKey': apiKey,
      'appName': appName,
      'clientId': clientId,
      'isDev': isDev,
      'imageData': imageData,
      'livenessType': livenessFacialComparisonType.name.toUpperCase(),
      'startProcessOnGettingToFirstScreen':
          startProcessOnGettingToFirstScreen ?? false,
      'thresholdInPercent': thresholdInPercent,
      'timeoutDurationInSec': timeoutDurationInSec,
    });

    if (result != null) {
      var response = json.decode(result);

      // Convert string to byte data
      var originalImageByteDataInString =
          (response['comparisonData']?['originalImage'] ?? '').toString();

      // Convert string to byte data
      var byteDataInString =
          (response['faceDetectionData']?['livenessImage'] ?? '').toString();

      return BlusaltLivenessResultResponse(
          livenessResultType: BlusaltLivenessResultType.success,
          isPassProcedureValidation: response['isProcedureValidationPassed'],
          comparisonData: BlusaltFacialComparisonData(
              isPassFaceComparison: response['comparisonData']
                  ['isPassFaceComparison'],
              originalImage: originalImageByteDataInString),
          faceDetectionData: BlusaltFaceDetectionData(
              isPassFaceGenuiness: response['faceDetectionData']
                  ['isPassFaceGenuineness'],
              imageByte: byteDataInString));
    } else {
      return BlusaltLivenessResultResponse(
          livenessResultType: BlusaltLivenessResultType.error,
          message: "Something went wrong");
    }
  } on PlatformException catch (exception) {
    return BlusaltLivenessResultResponse(
        livenessResultType: BlusaltLivenessResultType.error,
        exception: exception,
        message: exception.message,
        code: exception.code);
  } catch (e) {
    return BlusaltLivenessResultResponse(
        livenessResultType: BlusaltLivenessResultType.error,
        message: e.toString());
  }
}