Selfie Capture

In this section, you will find all the necessary information for using and integrating the Unico IDCloud platform SDK into your Flutter applications for selfie capture


This guide has been created to help you implement the Flutter SDK quickly and easily. Below is the step-by-step process for the entire integration. After that, if you wish to customize the experience, be sure to check the Flutter Customization section.

Initializing the SDK


To get started, create an instance of the builder (generated through the UnicoCheckBuilder interface), providing the context and environment as parameters, along with the implementation of the UnicoListener class.

The implementation of this class is quite simple and can be done with just a few lines of code. All you need to do is override the callback methods with your application's business logic.

class _MyHomePageState extends State<MyHomePage> implements UnicoListener {

    late UnicoCheckBuilder _unicoCheck;

    
      @override
      void onErrorUnico(UnicoError error) {}

      @override
      void onUserClosedCameraManually() {}

      @override
      void onSystemChangedTypeCameraTimeoutFaceInference() {}

      @override
      void onSystemClosedCameraTimeoutSession() {}
}

Environment configuration


Configure the environment that will be used to run the SDK. Use the enumerated environment that contains the following enumerates:

  • UnicoEnvironment.PROD: for production environment;

  • UnicoEnvironment.UAT: for approval environment.

See how to implement it in the example below:

 _unicoCheck.setEnvironment(unicoEnvironment: UnicoEnvironment.UAT);

Implementing the Callback functions


Note that, as shown in the previous example, the implementation of the UnicoListener class mostly involves configuring the callback methods. Each method will be called in a specific situation based on the SDK's return.

Simply override the methods demonstrated in the previous step with your application's business logic:

1

onErrorUnico(UnicoError error)

When invoked, the method receives a parameter of type UnicoError, which contains details about the error. Learn more about the UnicoError type in the SDK's error handling documentation.

2

onUserClosedCameraManually()

This method is invoked whenever the user manually closes the camera, such as by clicking the "Back" button.

3

onSystemClosedCameraTimeoutSession()

This method is invoked as soon as the maximum session time is reached (without capturing any image).

4

onSystemChangedTypeCameraTimeoutFaceInference()

This method is invoked as soon as the maximum time for detecting a user's face is reached (without detecting anything). In this case, the camera mode is automatically changed to manual capture mode (without the smart capture silhouette).

Configuring Camera Mode


The SDK has intelligent framing and automatic capture configured and enabled by default. As a result, you should configure the camera mode in your builder as follows:

UnicoCheckCameraOpener _opener = new UnicoCheck (this)
    .setAutoCapture(autoCapture: true)
    .setSmartFrame(smartFrame: true)
    .build();

Implementing Listeners for Camera Events


The implementation of these listener methods must be done through an instance of the UnicoSelfie class.

The camera opening method needs to know what to do when it successfully captures an image or encounters an error during the process. "What to do" is informed to the camera opening method by implementing listeners, which are called in cases of success or error.

Through the implementation of these listeners, you can specify what happens in your app in case of error (onErrorSelfie method) or success (onSuccessSelfie method) when capturing images.

onSucessSelfie Method


When successfully capturing an image, this method is invoked and returns an object of type ResultCamera, which is later used in the REST API requests:

@override
void onSuccessSelfie(ResultCamera result) { }

The ResultCamera object returns 2 attributes: base64 and encrypted:

  • The base64 attribute can be used if you want to display a preview of the image in your app.

  • The encrypted attribute must be sent in the REST API calls by Client.

onErrorSelfie Method


If an error occurs during the image capture, this method is invoked and returns an object of type UnicoError:

@override
void onErrorSelfie(UnicoError error) { }

Learn more about the ErrorBio types in the SDK's error handling section.

Preparing and Opening the Camera


The openCameraSelfie method is used to open the camera. This method takes as parameters the implementation of the UnicoSelfie class and the JSON with the credentials, generated in the previous step.

The following example illustrates the steps for configuring the listeners and opening the camera:

_opener.openCameraSelfie(jsonFileName: androidJsonFileName, listener: this)

Making a POST Request to the Client API


Capturing the images is only the first part of the journey. After capturing the image, it is necessary to send the encrypted generated by the SDK to the REST APIs of by Client. Learn more in the CreateProcess section of by Client.


Still need help?

Didn't find something or still need help? If you're already a client or partner, you can reach out through our Help Center.

Last updated

Was this helpful?