Skip to main content

Initialization

Where to initialize

Initialize the SDK on application load — typically in main() or in initState() of your entry widget. See Best practices 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:

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 = 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:

class _MyHomePageState extends State<MyHomePage> implements UnicoListener {

late UnicoCheckBuilder _unicoCheck;

@override
void onErrorUnico(UnicoError error) {}

@override
void onUserClosedCameraManually() {}

@override
void onSystemChangedTypeCameraTimeoutFaceInference() {}

@override
void onSystemClosedCameraTimeoutSession() {}
}
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
_unicoCheck.setEnvironment(unicoEnvironment: UnicoEnvironment.UAT);

For the full list of available environment types, refer to 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.