> For the complete documentation index, see [llms.txt](https://docs.facephi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.facephi.com/docs.facephi-en/sdks/sdk-mobile/framework-plugins/flutter/componentes/componente-principal.md).

# Main component

It is the SDK's most important component, as it contains the libraries needed to ensure everything works correctly.

Installing the  **Core** **Plugin** is mandatory, regardless of which products need to be used or the defined use case. It contains basic functionality for the SDK to operate, as well as other cross-cutting functionality required by auxiliary plugins.

## Dependencies <a href="#id-2-dependencia" id="id-2-dependencia"></a>

### Flutter:

<pre class="language-swift"><code class="lang-swift">dependencies:
  fphi_sdkmobile_core:
<strong>    hosted:
</strong>      name: fphi_sdkmobile_core
      url: https://facephicorp.jfrog.io/artifactory/api/pub/pub-pro-fphi/
    version: ^&#x3C;Version>
</code></pre>

### Android - Gradle:

```kotlin
api "com.facephi.androidsdk:sdk:$version"
api "com.facephi.androidsdk:core:$version"
implementation "com.facephi.androidsdk:tracking_component:$version"
```

### iOS - CocoaPods:

```swift
s.dependency 'FPHISDKMainComponent', '~> $version'
s.dependency 'FPHISDKTrackingComponent', '~> $version'
s.dependency 'FPHISDKLicensingComponent', '~> $version'
s.dependency 'FPHISDKTokenizeComponent', '~> $version'
s.dependency 'FPHISDKStatusComponent', '~> $version'
```

## Available methods

This component contains several methods that perform different functions:

<table data-header-hidden><thead><tr><th width="233.64453125"></th><th></th></tr></thead><tbody><tr><td><strong>Method</strong></td><td><strong>Description</strong></td></tr><tr><td>initSession</td><td>The component's main controller, which is responsible for validating licenses, among other things.</td></tr><tr><td>initOperation</td><td>Method responsible for generating a new operation. Its ID is retrieved from the result object, in the data parameter.</td></tr><tr><td>getExtraData</td><td>The getExtraData method generates the identifiers required for an operation that needs to continue in the <em>Facephi Validation Service</em> (Backend).</td></tr><tr><td>closeSession</td><td>Before the application is destroyed, the SDK session must be closed to notify the platform that it has ended.</td></tr></tbody></table>

### initSession <a href="#id-2-inicializacion-de-la-sesion" id="id-2-inicializacion-de-la-sesion"></a>

Before using any component, the SDK session must be initialized. This initialization should be performed as early as possible, preferably when the application starts. Likewise, once all operations with the SDK Mobile are complete, the session must be closed.

The current component can be initialized in two ways, depending on how you want to inject the license.

The new licensing method allows licenses to be managed transparently for the integrator. The license can be injected in two ways:

* Obtaining the license through a service using a URL and API key
* Injecting the license directly as a String

In both cases, the result is returned through a Promise, which contains an object of the class **CoreResult**.

```dart
@override
Future<Map> initSession({ required CoreConfigurationInitSession widgetConfigurationJSON }) async {
  final Map res = await methodChannel.invokeMethod('initSession', {"widgetConfigurationJSON": widgetConfigurationJSON.toJson()});
  return res;
}
```

## Basic configuration <a href="#id-5-configuracion-basica" id="id-5-configuracion-basica"></a>

To launch the current component, you must create an object ***CoreConfigurationInitSession*** which will be the component controller's configuration.

The basic configuration required for this is as follows:

```dart
class CoreConfigurationInitSession
{
  String mLicenseUrl;
  String mLicenseApiKey;
  String mLicense;
  String? mLocale;
  bool? mEnableTracking;
  bool? mEnableDebugMode;
  dynamic mInternalOptions
}
```

### Advanced component configuration

All the fields that are part of this class are detailed below.

{% content-ref url="/pages/8de20a0612fefc3ed40ba226ed4e9e4d403555a7" %}
[Init Session Configuration](https://docs.facephi.com/docs.facephi-en/sdks/sdk-mobile/framework-plugins/extras/core/init-session-configuracion.md)
{% endcontent-ref %}

***

### initOperation <a href="#id-3-inicializacion-de-la-operacion" id="id-3-inicializacion-de-la-operacion"></a>

When starting a process or flow, **always** call the initOperation method

```dart
@override
Future<Map> initOperation({ required TrackingConfiguration widgetConfigurationJSON }) async {
  final Map res = await methodChannel.invokeMethod('initOperation', {"widgetConfigurationJSON": widgetConfigurationJSON.toJson()});
  return res;
}
```

## Basic configuration <a href="#id-5-configuracion-basica" id="id-5-configuracion-basica"></a>

To launch the current component, create a ***TrackingConfiguration*** object, which will configure the component's controller.

The basic configuration required for this is as follows:

```dart
class TrackingConfiguration
{
  TrackingOperationType mType;
  String mCustomerId;
}
```

### Advanced component configuration

All the fields that are part of this class are detailed below.

{% content-ref url="/pages/927144262d70be7548c816dd23cee42db3620f0a" %}
[Init Operation Configuration](https://docs.facephi.com/docs.facephi-en/sdks/sdk-mobile/framework-plugins/extras/core/init-operation-configuracion.md)
{% endcontent-ref %}

***

### closeSession <a href="#id-6-cierre-de-sesion" id="id-6-cierre-de-sesion"></a>

Before the application is destroyed, close the SDK session to notify the platform that it has ended. To do so, run the following code snippet:

```dart
@override
Future<Map> closeSession() async {
  final Map res = await methodChannel.invokeMethod('closeSession', {});
  return res;
}
```

***

### getExtraData <a href="#id-7-metodo-extradata" id="id-7-metodo-extradata"></a>

The getExtraData method generates the identifiers required for an operation that must continue in the *Facephi Validation Service* (Backend). This typically occurs when, after obtaining the necessary information in the customer's application, that information must be sent to a specific service for further validation or analysis. If the results of these processes need to be tracked on the Platform, it must be able to link the first part of the process, carried out on the client, with the final part, carried out by the service, since both are part of the same operation.

```dart
@override
Future<Map> getExtraData() async {
  final Map res = await methodChannel.invokeMethod('getExtraData', {});
  return res;
}
```

## Launching IDV <a href="#lanzamiento-de-idv" id="lanzamiento-de-idv"></a>

The IDV process launches a flow configured on the platform using its ID (flowID). To do this, two methods must be called: **initFlow + startFlow**.

### initFlow

This method sets the required configuration: the ID of the flow configured on the platform (flowID) and the customer ID (customerID). See the code:

```dart
await FphiSdkmobileCore().initFlow(widgetConfigurationJSON: FlowConfiguration(
    mCustomerId: customerId,
    mFlow: "f40c098c-a878-4976-aef1-2af6bbf55148"
));
```

To configure the flow controller, create a list of the controllers for the components that will participate in the process so they can be initialized correctly. The order in which they are defined does not matter; the flow itself determines the order in which they are executed. For example:

* **setSelphiFlow**: Face Capture
* **setSelphidFlow**: Document capture

Code to launch:

<pre class="language-dart"><code class="lang-dart">// If initFlow returns STATUS_OK. Call the flows by invoking the controllers one by one
CoreWidget().initFlow().then((r) async
{
  r.map((r) async
  {
    if (r.finishStatus == SdkFinishStatus.STATUS_OK).
    {
      /* Call as many flow setup methods as there are flows in use */
      /* In this example, a typical onboarding flow */
      await SelphiFaceWidget().setSelphiFlow().then((value) {
        if (kDebugMode) {
          print(value);
        }
      });
      await SelphIDWidget().setSelphidFlow().then((value) {
        if (kDebugMode) {
          print(value);
        }
      });
      
      /* At the end of adding the flows, startFlow is launched (provided the previous methods do not fail) */
      await CoreWidget().startFlow().then((value)
      {
        if (kDebugMode) {
          print(value);
        }
      }).onError((error, stackTrace) {
        if (kDebugMode) {
          print(error);
        }
      });
    }
  });
}).onError((error, stackTrace) {
  if (kDebugMode) {
    print(error);
  }
});

/* Results are received by implementing a BasicMessage with the key 'core.flow' */
const channel = BasicMessageChannel&#x3C;dynamic>('core.flow', StringCodec());
channel.setMessageHandler((message) async
{
  if (jsonDecode(message!)['flow'] == "SELPHID")
  {
    if (kDebugMode) {
      print(SelphIDResult.fromMap(jsonDecode(message)));
    }
  }
  else if (jsonDecode(message!)['flow'] == "SELPHI")
  {
    if (kDebugMode) {
      print(SelphiFaceResult.fromMap(jsonDecode(message)));
    }
  }
  else
  {
    if (kDebugMode) {
      print(jsonDecode(message));
    }
  }
  return '';
<strong>});
</strong></code></pre>

## Receiving the result <a href="#id-6-recepcion-del-resultado" id="id-6-recepcion-del-resultado"></a>

Launching  ***ALL*** methods will return information in CoreResult format. A successful launch can be distinguished from an unsuccessful one:

```dart
class CoreResult {
  final SdkFinishStatus finishStatus;
  final String finishStatusDescription;
  final String errorDiagnostic;
  final String? errorMessage;
  final String? data;
}
```

{% content-ref url="/pages/c2409d1f2884ad7ba323fd2108cc99568268a702" %}
[Core Result](https://docs.facephi.com/docs.facephi-en/sdks/sdk-mobile/framework-plugins/extras/core/core-resultado.md)
{% endcontent-ref %}
