> For the complete documentation index, see [llms.txt](https://docs.caf.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.caf.io/caf-sdk/caf-sdk-pt-br/flutter/standalone-modules/faceliveness/lifecycle.md). Agents can also search and read this documentation through its [MCP server](https://docs.caf.io/~gitbook/mcp).

# Ciclo de vida do SDK

## CafLivenessListener (Flutter)

O `CafLivenessListener` no Flutter lida com eventos-chave durante o processo de detecção de vivacidade do SDK. Abaixo estão os eventos que você pode ouvir para FaceLiveness:

| **Evento**                      | **Descrição**                                                                                              |
| ------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| **FaceLivenessEventConnecting** | Indica que o SDK está inicializando ou se conectando ao servidor.                                          |
| **FaceLivenessEventConnected**  | Disparado quando o SDK estiver totalmente conectado, e a interface do usuário será exibida.                |
| **FaceLivenessEventClosed**     | Disparado quando o usuário cancela o processo de detecção de vivacidade.                                   |
| **FaceLivenessEventSuccess**    | Disparado após a detecção de vivacidade bem-sucedida, fornecendo o resultado em `signedResponse`.          |
| **FaceLivenessEventFailure**    | Chamado quando ocorre uma falha no SDK, fornecendo detalhes do erro como `errorType` e `errorDescription`. |

### Exemplo de implementação

Abaixo está um exemplo de como lidar com `CafLivenessListener` eventos no Flutter:

```dart
void _setupFaceLivenessListener(Stream<FaceLivenessEvent> stream) {
  stream.listen((event) {
    if (event is FaceLivenessEventConnecting) {
      print('Conectando ao FaceLiveness...');
    } else if (event is FaceLivenessEventConnected) {
      print('Conectado ao FaceLiveness.');
    } else if (event is FaceLivenessEventClosed) {
      print('SDK encerrado pelo usuário.');
    } else if (event is FaceLivenessEventSuccess) {
      print('Sucesso! SignedResponse: ${event.signedResponse}');
    } else if (event is FaceLivenessEventFailure) {
      print(
        'Falha! Tipo de erro: ${event.errorType}, '
        'Descrição do erro: ${event.errorDescription}',
      );
    }
  });
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.caf.io/caf-sdk/caf-sdk-pt-br/flutter/standalone-modules/faceliveness/lifecycle.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
