Skip to main content

Document capture

Capture of identity documents. The SDK presents a frame to assist the user in positioning the document; after positioning, the user clicks the button to capture the photo.

No content validation

The SDK does not perform any type of validation on what is being captured.

Available document frames
FrameDescription
DocumentCameraTypes.CPFCapture the CPF
DocumentCameraTypes.CNHCapture the open CNH
DocumentCameraTypes.CNH_FRENTECapture the front of the CNH
DocumentCameraTypes.CNH_VERSOCapture the back of the CNH
DocumentCameraTypes.RG_FRENTECapture the front of the RG
DocumentCameraTypes.RG_VERSOCapture the back of the RG
DocumentCameraTypes.OUTROS("descrição")Generic frame for any other document
Generic frame

If you need to capture a document for which there is no specific frame (e.g., RNE), use DocumentCameraTypes.OUTROS("description") — a generic, rectangular frame that can be used to guide any capture.

For the full list of supported document types, see API Reference > Enums.

Starting a document capture
Step 1 — Implement UnicoListener

UnicoListener handles the SDK lifecycle callbacks. Implement the four mandatory methods:

MethodWhen it's called
onErrorUnico(error)An error occurred during SDK operation
onUserClosedCameraManually()The user manually closed the camera
onSystemClosedCameraTimeoutSession()The 40-second session limit was reached
onSystemChangedTypeCameraTimeoutFaceInference()No face detected for 13 seconds — switches to manual capture
class _MyHomePageState extends State<MyHomePage> implements UnicoListener {
late UnicoCheckBuilder _unicoCheck;

@override
void onErrorUnico(UnicoError error) {}

@override
void onUserClosedCameraManually() {}

@override
void onSystemClosedCameraTimeoutSession() {}

@override
void onSystemChangedTypeCameraTimeoutFaceInference() {}
}
Mandatory listener methods

All four listener methods above must be created in your project (even without any logic). Otherwise, the project will not compile successfully.

Step 2 — Implement the document listeners

Add the document callbacks to your state class:

MethodDescription
onSuccessDocument(ResultCamera resultCamera)Capture succeeded — returns ResultCamera with base64 (preview) and encrypted (JWT for the API)
onErrorDocument(UnicoError error)Capture failed — returns a UnicoError with code and description
@override
void onSuccessDocument(ResultCamera resultCamera) { }

@override
void onErrorDocument(UnicoError error) { }
Step 3 — Call openCameraDocument

The openCameraDocument() method is provided through the object generated with an instance of the UnicoCheck class. It takes:

  • A JSON file with the credentials, generated in the credential setup step;
  • The document type to be captured (DocumentType enum);
  • The listener configured in Step 2.

Example using the open CNH:

_unicoCheck.build().openCameraDocument(
jsonFileName: androidJsonFileName,
documentType: DocumentType.CNH,
listener: this,
);

For the full result handling, see Receiving the result.