---
title: Initialization
canonical: https://developer.unico.io/dual-api/developers/sdks-and-tools/flutter/initialization
locale: en
generated_by: markdown-export
---

## Where to initialize

Initialize the SDK on **application load** — typically in `main()` or in `initState()` of your entry widget. See [Best practices](/developers/sdks-and-tools/flutter/resources) for details on why you should **not** initialize on the capture button click.

## Embedding credentials

Instantiate a `UnicoConfig` object for each platform with the credentials provided by the Onboarding team:

```dart
final _configIos = UnicoConfig(
    getBundleIdentifier: "Your BundleIdentifier Ios",
    getHostKey: "Your HostKey Ios");

final _configAndroid = UnicoConfig(
    getBundleIdentifier: "Your BundleIdentifier Android",
    getHostKey: "Your HostKey Android");

void initUnicoCamera() {
  // UnicoCheck() returns a UnicoCheckBuilder — use it to chain configuration and call build()
  _unicoCheck = new UnicoCheck(
      listener: this,
      unicoConfigIos: _configIos,
      unicoConfigAndroid: _configAndroid);
}
```

## Implement UnicoListener

Implement the `UnicoListener` interface in your widget state class and override the callback methods with your application's business logic:

```dart
class _MyHomePageState extends State<MyHomePage> implements UnicoListener {

  late UnicoCheckBuilder _unicoCheck;

  @override
  void onErrorUnico(UnicoError error) {}

  @override
  void onUserClosedCameraManually() {}

  @override
  void onSystemChangedTypeCameraTimeoutFaceInference() {}

  @override
  void onSystemClosedCameraTimeoutSession() {}
}
```

:::warning[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.
:::

## Environment selection

The choice of environment is made during initialization. Use the `UnicoEnvironment` enum:

- `UnicoEnvironment.PROD` — production environment
- `UnicoEnvironment.UAT` — UAT environment

```dart
_unicoCheck.setEnvironment(unicoEnvironment: UnicoEnvironment.UAT);
```

For the full list of available environment types, refer to [API Reference > Initialization API](/developers/sdks-and-tools/flutter/api-reference/initialization-api).

## Lifecycle

SDK authentication with the backend takes a few seconds. **Initialize early** (cold start of the app), not when the user taps the capture button — otherwise the user experiences lag between the tap and the camera opening.