# Enrolment Flow

In order to use our SDK you need an authorization token. Please check our API "[Authorisation](https://docs.uqudo.com/docs/kyc/uqudo-api/authorisation)" in this regard.

Add the following code at the start-up of your application to initialize the SDK:

```dart
import 'package:uqudosdk_flutter/UqudoIdPlugin.dart';
import 'package:uqudosdk_flutter/uqudosdk_flutter.dart';
...
UqudoIdPlugin.init();
...
```

Use the below method for setting the locale of the application:

```dart
...
UqudoIdPlugin.setLocale(<your locale eg. fr, en etc.>);
...
```

To check if a document supports enrollment, reading and facial recognition you can use the below methods:

```dart
...
var isEnrollmentSupported = await UqudoIdPlugin.isEnrollmentSupported(DocumentType.UAE_ID);
var isReadingSupported = await UqudoIdPlugin.isReadingSupported(DocumentType.UAE_ID);
var isFacialRecognitionSupported = await UqudoIdPlugin.isFacialRecognitionSupported(DocumentType.UAE_ID);
...
```

Below you can find an example on how to initiate the enrolment process for a passport enabling the reading through NFC and facial recognition:

```dart
import 'package:uqudosdk_flutter/UqudoIdPlugin.dart';
import 'package:uqudosdk_flutter/uqudosdk_flutter.dart';
...

String result;
try {
  var token = "your token";
  var doc = new DocumentBuilder()
      .setDocumentType(DocumentType.PASSPORT)
      .enableReading(new ReadingConfigurationBuilder()
          .forceReadingIfSupported(true)
          .build()
      )
      .build();
  var enrollObject = new EnrollmentBuilder()
      .setToken(token)
      .add(doc)
      .setAppearanceMode(AppearanceMode.SYSTEM)
      .build();
  result = await UqudoIdPlugin.enroll(enrollObject);
} on PlatformException catch (exception) {
  result = exception.code;
   // {"code":"USER_CANCEL","message":"User canceled the Enrollment process","task":"SCAN"}
}
```

In order to evaluate all the possible options please refer to section [Enrolment Flow](https://docs.uqudo.com/docs/kyc/uqudo-sdk/integration/android/enrolment-flow). The dart interface is the porting of the JAVA one. In addition you can check the dart files in the plugin ./lib folder or directly from your IDE.

If **successful**, the response is a JSON Web Signature (JWS). Please refer to section "[SDK result](https://docs.uqudo.com/docs/kyc/uqudo-sdk/sdk-result)" for further details.

In case of a **failure**, the callback returns the following object:

<table><thead><tr><th width="122">Property</th><th width="83">Type</th><th width="99">Optional</th><th width="96">Default</th><th>Description</th></tr></thead><tbody><tr><td>code</td><td>String</td><td>No</td><td>None</td><td>See <a href="../../android/enrolment-flow#handling-the-result">Handling the Result</a></td></tr><tr><td>message</td><td>String</td><td>Yes</td><td>null</td><td>Description of the error if any</td></tr><tr><td>task</td><td>String</td><td>Yes</td><td>null</td><td>See <a href="../../android/enrolment-flow#handling-the-result">Handling the Result</a></td></tr></tbody></table>

Add the following event to enable the tracing mechanism as per the code shown below. Please refer to section [Analytics](https://docs.uqudo.com/docs/kyc/uqudo-sdk/integration/android/analytics) for details.

```dart
import 'package:uqudosdk_flutter/UqudoIdPlugin.dart';

class _MyAppState extends State<MyApp> {

  @override
  void initState() {
    super.initState();
    UqudoIdPlugin.init();
    listenNativeEvent();
  }

  static const EventChannel _eventChannel =
      EventChannel('io.uqudo.sdk.id/trace');

  void listenNativeEvent() {
    _eventChannel.receiveBroadcastStream().listen(_onEvent, onError: _onError);
  }

  void _onEvent(Object? event) {
    if (event != null) {
      print("---TraceEvent=${event.toString()}");
    }
  }

  void _onError(Object error) {
    print('---TraceEvent error.');
  }
......
```
