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.
The SDK does not perform any type of validation on what is being captured.
| Frame | Description |
|---|---|
DocumentCameraTypes.CPF | Capture the CPF |
DocumentCameraTypes.CNH | Capture the open CNH |
DocumentCameraTypes.CNH_FRENTE | Capture the front of the CNH |
DocumentCameraTypes.CNH_VERSO | Capture the back of the CNH |
DocumentCameraTypes.RG_FRENTE | Capture the front of the RG |
DocumentCameraTypes.RG_VERSO | Capture the back of the RG |
DocumentCameraTypes.OUTROS("descrição") | Generic frame for any other document |
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.
Step 1 — Implement UnicoListener
UnicoListener handles the SDK lifecycle callbacks. Implement the four mandatory methods:
| Method | When 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() {}
}
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:
| Method | Description |
|---|---|
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 (
DocumentTypeenum); - 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.