> For the complete documentation index, see [llms.txt](https://docs.sentiance.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sentiance.com/getting-started/sdk-integration/2.-including-the-sdk/flutter.md).

# Flutter

{% stepper %}
{% step %}

### Add the Sentiance SDK package

Add the SDK package from pub.dev

Open a terminal and run the command below from yout flutter project root directory.

```bash
flutter pub get sentiance_core
```

{% endstep %}

{% step %}

### Native platform setup

To include the Sentiance SDK as a dependency, you must complete the native platform setup for each target platform your application supports.

<details>

<summary>iOS</summary>

1. **Add the SDK to your Podfile**

Open your Podfile and add the following line, Replace  `x.y.z` with the specific SDK version you want to install

```objective-c
pod 'SENTSDK', '~> x.y.z'
```

2. **Navigate to your ios folder in Terminal and run** <mark style="color:yellow;">`pod install`</mark>
3. **Configure Capabilities in Xcode**
   1. Open iox/Runner.xcworkspace in Xcode
   2. Go to Signing & Capabilities tab of your Runner target
   3. Add the Background Modes capability if it is not already added.
   4. Enable the following background modes
      * Location updates
      * Background fetch
      * Background processing
4. **Update Permissions in Info.plist**&#x20;
   1. If it doesn’t already exist, add \
      `Permitted background task scheduler identifiers` and include `com.sentiance.backgroundtask.task_processing` as a sub-item.
   2. Add the following keys with the appropriate usage descriptions
      * Location Always and When In Use Usage Description
      * Location Always Usage Description
      * Location When In Use Usage Description
      * Motion Usage Description

</details>

<details>

<summary>Android</summary>

#### Include the Sentiance repository

Add the Maven repository in android/build.gradle file, \
Add the lines below in the allprojects repositories\
make sure to use the correct syntax for your file.

* Kotlin syntax\
  `maven { url = uri("https://repository.sentiance.com") }`
* groovy syntax\
  `maven { url "https://repository.sentiance.com"}`<br>

#### Add dependencies

Open the build.gradle file of your app module and add the following lines in the dependencies section (add this section if it does not exist yet), replace `x.y.+` with the latest version from [Versions & Changelog](/sdk/versions-and-changelog.md)

<pre class="language-kotlin" data-title="android/app/build.gradle" data-expandable="true"><code class="lang-kotlin">...
dependencies {
<strong>    implementation(platform("com.sentiance:sdk-bom:x.y.+"))
</strong>}

flutter {
    source = "../.."
}
</code></pre>

#### Add Permissions to android Manifest

The SDK automatically includes some permissions, others are required to be specifically included in the Android Manifest.\
Include the permissions below in AndroidManifest.xml\
read more about permissions in ....

{% code title="AndroidManifest.xml" %}

```xml
    ...
    <uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
</manifest>

```

{% endcode %}

</details>
{% endstep %}

{% step %}

### SDK Initialization

The SDK must be initialized as early as possible in the native code and on the main thread.\
Follow the instructions below to initialize the SDK for your application’s target platform.

{% tabs %}
{% tab title="iOS: AppDelegate" %}
Follow below instructions to initialize the Sentiance SDK for ios.\
Make sure that initialization happens before the `didFinishLaunchingWithOptions` method returns

1. Open ios/Runner/AppDelegate.swift
2. Import the sentiance\_core package
3. Create a SDK instance and call the initialize method
4. Perform some logic to verify the initialization

<pre class="language-swift"><code class="lang-swift">...
<strong>import sentiance_core
</strong>
...
    GeneratedPluginRegistrant.register(with: self)
<strong>    let sentianceInit = SentianceCorePlugin.shared.initialize()
</strong>    if sentianceInit.isSuccessful {
        print("Sentiance SDK initialized")
    }
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}
</code></pre>

{% endtab %}

{% tab title="Android: Application Class" %}
Follow below instructions to initialize the Sentiance SDK for Android.\
Make sure that initialization happens before the `onCreate` method returns

1. Open the file where your Application class resides. or create a Application class in a new file or in MainActivity.kt. \ <sub><mark style="color:blue;">\* Make sure to update AndroidManifest.xml to point to the newly created Application class<mark style="color:blue;"></sub>
2. Import the Sentiance core plugin
3. Create a SDK instance and call the initialize method
4. Perform some logic to verify the initialization

```kotlin
...
import com.sentiance.core_plugin.CorePlugin
import android.app.Application

class MainApplication : Application() {
    override fun onCreate() {
        val sentianceInit = CorePlugin.initialize(this)
        if(sentianceInit.isSuccessful){
            // Succesfull initialization
        } else {
            // Failed initialization
        }
    }
}
```

{% endtab %}
{% endtabs %}
{% endstep %}
{% endstepper %}

## External Dependencies

In addition to the core Flutter SDK, the Sentiance Flutter SDKs have a dependency on the [equatable](https://pub.dev/packages/equatable) package.

For external dependencies in the native SDKs, check out [the following section](/getting-started/sdk-integration/2.-including-the-sdk/android.md#external-dependencies) for Android and [this section](/getting-started/sdk-integration/2.-including-the-sdk/ios.md#external-dependencies) for iOS.

## Steps

{% stepper %}
{% step %}

### **Install the Sentiance Core Flutter package**

Run the command in Terminal:

{% code title="Terminal" %}

```shellscript
flutter pub get sentiance_core
```

{% endcode %}

The module should now be added to your project's **pubspec.yaml** file.

{% code title="pubspec.yaml" %}

```yaml
dependencies:
  flutter:
    sdk: flutter
  sentiance_core: ^6.23.0
  ...
```

{% endcode %}
{% endstep %}

{% step %}

### **Setup the Build Dependencies in the native folders**

#### iOS Build Dependencies

1. In the terminal, navigate to your project's iOS directory&#x20;
2. Run the command in Terminal:

{% code title="Terminal" %}

```bash
pod install --repo-update
```

{% endcode %}

#### Android Build Dependencies

Add the Sentiance repository to your project-level <mark style="color:$success;">**`build.gradle`**</mark> file:

```kotlin
allprojects {
    repositories {
        ...
        maven { url "https://repository.sentiance.com" }
    }
}
```

This will allow Gradle to find and download the necessary native Sentiance SDK libraries.
{% endstep %}

{% step %}

### Configuration and permissions

Next, we'll configure the project settings and permissions for both iOS and Android.

#### **iOS Configuration and Permissions**

Open your existing app project in Xcode.

For **project and permission settings**, follow these 3 steps from the Native iOS Setup guide:<br>

1. [Configure the Project Capabilities](/getting-started/sdk-integration/2.-including-the-sdk/ios.md#configure-the-project-capabilities)
2. [Include the Background Task Identifier](/getting-started/sdk-integration/2.-including-the-sdk/ios.md#include-the-background-task-identifier)
3. [Configure Privacy Permission Descriptions](/getting-started/sdk-integration/2.-including-the-sdk/ios.md#configure-privacy-permission-descriptions)

#### **Android Configuration**

When the Sentiance SDK runs in the background, it starts a foreground service. This causes Android to display a notification in the notification shade, and an icon on the system bar.

To **customize this notification**, you can update the <mark style="color:$success;">**`AndroidManifest.xml`**</mark> file as follows:

{% code title="AndroidManifest.xml" %}

```xml
<application ...>
    <meta-data android:name="com.sentiance.flutter.core.notification_id" android:value="1001"/>
    <meta-data android:name="com.sentiance.flutter.core.notification_title" android:resource="@string/app_name"/>
    <meta-data android:name="com.sentiance.flutter.core.notification_text" android:value="Touch to open."/>
    <meta-data android:name="com.sentiance.flutter.core.notification_icon" android:resource="@mipmap/ic_launcher"/>
    <meta-data android:name="com.sentiance.flutter.core.notification_channel_name" android:value="Detections"/>
    <meta-data android:name="com.sentiance.flutter.core.notification_channel_id" android:value="sentiance_detections"/>
    
    ...
</application>
```

{% endcode %}

By customizing the notification, you can tailor the appearance and behavior of the notification to match the branding and user experience of your application. This allows you to provide a seamless and consistent experience to your users while the Sentiance SDK operates in the background.

Please note that customizing the notification should be done carefully to ensure that it complies with Android guidelines and user preferences. By doing so, you can enhance the overall user experience and maintain a cohesive presentation of your app and the Sentiance SDK's background functionality.
{% endstep %}

{% step %}

### Next: Initialize the SDK

After having included the Sentiance SDK, proceed to [initializing the SDK](/getting-started/sdk-integration/3.-sdk-initialization/android.md#steps).
{% endstep %}
{% endstepper %}
