directApiMultiSideScan static method

Future<void> directApiMultiSideScan(
  1. BuildContext context,
  2. String sdkLicenseKey,
  3. BlinkidFlutter blinkIdPlugin, {
  4. required MicroblinkErrorCallback onError,
  5. required MicroblinkSuccessCallback onSuccess,
})

Implementation

static Future<void> directApiMultiSideScan(
  BuildContext context,
  String sdkLicenseKey,
  BlinkidFlutter blinkIdPlugin, {
  required MicroblinkErrorCallback onError,
  required MicroblinkSuccessCallback onSuccess,
}) async {
  try {
    /// Get the front and the back side of the document with the pickMultiImage method
    /// First select the front and the then back side of the image
    final images = await ImagePicker().pickMultiImage();

    if (images.length < 2) {
      GlUtils.dialog(
        context,
        'Error',
        'Por favor selecione duas imagens: frente e verso do documento.',
      );
      return;
    }

    //_imageFront = File(images[0].path);
    //_imageBack = File(images[1].path);

    /// Convert the first picked image to the Base64 format
    String frontImageBase64 = base64Encode(await images[0].readAsBytes());

    /// Get the second selected image as the back side of the document
    /// Convert the picked image to the Base64 format
    String backImageBase64 = base64Encode(await images[1].readAsBytes());

    /// Set the BlinkID SDK settings
    final sdkSettings = BlinkIdSdkSettings(sdkLicenseKey);
    sdkSettings.downloadResources = true;

    /// Create and modify the Session Settings
    final sessionSettings = BlinkIdSessionSettings();
    sessionSettings.scanningMode = ScanningMode.automatic;

    /// Create and modify the scanning settings
    final scanningSettings = BlinkIdScanningSettings();
    scanningSettings.anonymizationMode = AnonymizationMode.fullResult;
    scanningSettings.glareDetectionLevel = DetectionLevel.mid;

    /// Uncomment the following line if you are passing input images
    /// that consist solely of the cropped document image.
    ///
    /// scanningSettings.scanCroppedDocumentImage = true;

    /// Create and modify the Image settings
    final imageSettings = CroppedImageSettings();
    imageSettings.returnDocumentImage = true;
    imageSettings.returnSignatureImage = true;
    imageSettings.returnFaceImage = true;

    /// Place the image settings in the scanning settings
    scanningSettings.croppedImageSettings = imageSettings;

    /// Place the Scanning settings in the Session settings
    sessionSettings.scanningSettings = scanningSettings;

    /// Call the 'performDirectApiScan' method and handle the results
    /// Check how the results are handled in the blinkid_result_builder.dart file
    await blinkIdPlugin
        .performDirectApiScan(
          sdkSettings,
          sessionSettings,
          frontImageBase64,
          backImageBase64,
        )
        .then((result) {
          if (result != null) {
            result.firstDocumentImage ??= frontImageBase64;
            result.secondDocumentImage ??= backImageBase64;
            onSuccess(result);
          }

          /*setState(() {
            resetImages();
            if (result != null) {
              resultString = BlinkIdResultBuilder.getIdResultString(result);
              setImages(result);
            }
          });*/
        })
        .catchError((scanningError) {
          if (scanningError is PlatformException) {
            final errorMessage = scanningError.message;
            onError(errorMessage ?? "");
          }

          /*setState(() {
            if (scanningError is PlatformException) {
              final errorMessage = scanningError.message;
              resultString = "BlinkID scanning error: $errorMessage";
              resetImages();
            }
          });*/
        });
  } catch (blinkidScanningError) {
    if (blinkidScanningError is PlatformException) {
      final errorMessage = blinkidScanningError.message;
      onError(errorMessage ?? "");
      /*setState(() {
        resultString = "BlinkID scanning error: $errorMessage";
        resetImages();
      });*/
    }
  }
}