For the complete documentation index, see llms.txt. This page is also available as Markdown.

Flutter

Initialization allows the SDK to perform detections in the background. You must always initialize the SDK before interacting with it. Only a limited set of SDK methods are safe to invoke on an uninitialized SDK.

Initialization is asynchronous. This means your Dart code can start running before the native SDK has finished initializing. Most SDK methods fail if called before initialization completes, so in Dart you must await SentianceCore.ensureInitialized() before your first SDK call and handle a possible initialization failure.

Steps

1

Initialize the Sentiance SDK for iOS

Make sure the initialization is triggered before the didFinishLaunchingWithOptions method returns.

  1. Open ios/Runner/AppDelegate.swift

  2. Import the sentiance_core package

  3. Call the initializeAsync method provided by the SentianceCorePlugin class

  4. Log the outcome from the completion handler

AppDelegate.swift
import Flutter
import UIKit
import sentiance_core

@main
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)

    SentianceCorePlugin.shared.initializeAsync(launchOptions: launchOptions) { result, error in
      if result != nil {
        print("Sentiance SDK initialization succeeded")
      } else {
        print("Sentiance SDK initialization failed, reason: \(String(describing: error?.failureReason))")
      }
    }

    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}
2

Initialize the Sentiance SDK for Android

  1. Open the file where your Application class resides, or create a new Application class (make sure to update AndroidManifest.xml to point to the newly created Application class)

  2. Locate the onCreate method

  3. Import the Sentiance core plugin

  4. Call the static initializeAsync method on the CorePlugin class

  5. Log the outcome from the completion listener

MainApplication.kt
package com.your.domain

import android.app.Application
import android.util.Log
import com.sentiance.core_plugin.CorePlugin

class MainApplication : Application() {
    override fun onCreate() {
        super.onCreate()

        CorePlugin.initializeAsync(this)
            .addOnCompleteListener { op ->
                if (op.isSuccessful) {
                    Log.d("Sentiance", "Sentiance SDK initialization succeeded")
                } else {
                    Log.e("Sentiance", "Sentiance SDK initialization failed, reason: ${op.error?.failureReason}")
                    op.error?.throwable?.let { Log.e("Sentiance", "throwable: ${it.message}") }
                }
            }
    }
}

Run the app, open a new Terminal window and verify logs by running the command:

adb logcat | grep Sentiance
3

Ensure the SDK is initialized from Dart code

Because initialization is asynchronous, await SentianceCore.ensureInitialized() before your first SDK call. It completes once initialization finishes, and throws a SdkInitializationError if initialization failed or was never triggered.

app.dart
import 'package:sentiance_core/sentiance_core.dart';

try {
  await SentianceCore.ensureInitialized();
  // The SDK is initialized. It is now safe to call other SDK methods.
} on SdkInitializationError catch (e) {
  switch (e.reason) {
    case SdkInitializationFailureReason.notTriggered:
      // Init was never started, or was started late / off the main thread.
      // Make sure initializeAsync runs synchronously from your native entry point.
      break;
    case SdkInitializationFailureReason.exceptionOrError:
      // An error occurred during initialization, or the native reason was unrecognized.
      break;
      
    // Handle the other cases here  
  }
  print('Sentiance SDK initialization failed: ${e.reason}, ${e.message}');
} on PlatformException catch (e) {
  // An unexpected error occurred while talking to the host platform.
  print('Unexpected error: ${e.message}');
}
4

Next: User Creation

After having successfully initialized the Sentiance SDK, you must now create a user. To do so, follow the instructions on this page.

Last updated