Flutter integration guide
How to embed the Aarambh SDK in a Flutter app via flutter-plugin/
(aarambh_sdk). The package is a thin pass-through — every Dart method forwards to
com.aarambh.sdk.AarambhSDK over a single MethodChannel. No business logic lives in
the Flutter or Kotlin layers.
Acquiring a session
Before your app calls login(), your own backend registers the agent and
acquires a session token by calling two endpoints on the LSP DMS Gateway. These are server-to-server
calls, made from your backend and never from the mobile app. The full request / response reference,
including authentication, lives in the API integration guide:
POST /v1/agent/create— registers the agent against your subscriber account and returns itsuserCode. Run it once per agent.POST /v1/agent/acquireSession— returns a session token for thatuserCode. Call it whenever your app needs a freshauthTokenfor the SDK (e.g. on each login, not just once at registration).
Map the acquireSession response straight onto AarambhSdk.login():
data.token → authToken, data.currentUser → userDetails,
data.agentDetails → agentDetails (agentDetails needs
aarambh_sdk v0.1.6+ — see API reference below). Call
login() and wait for it to complete before calling launch() — see the
call-order warning below the API reference table.
Installation
The Flutter package is mirrored, read-only, to a dedicated repo
(aarambh-cloud/aarambh-sdk-flutter) on every release — not published to pub.dev, since pub.dev
has no private-package option. Add it as a git dependency in your pubspec.yaml:
dependencies:
aarambh_sdk:
git:
url: https://github.com/aarambh-cloud/aarambh-sdk-flutter.git
ref: v0.1.9 # tag, branch, or commit SHA — ask your integration contact for the latest
Then flutter pub get. The consuming machine needs its own git credentials for this repo (SSH
key or HTTPS PAT with read access), since it's private.
Authenticating the native dependency
The native Android module also depends on com.aarambh.external:sdk, published to GitHub Packages
(Maven) — GitHub Packages requires authentication for reads too, even though the repo itself is
source-visible to the org. Add a Maven repository with a GitHub PAT (read:packages scope) to
your Flutter app's top-level android/build.gradle(.kts):
allprojects {
repositories {
google()
mavenCentral()
maven {
url 'https://maven.pkg.github.com/aarambh-cloud/aarambh-sdk-android'
credentials {
username = <your-github-username>
password = <PAT-with-read:packages-scope>
}
}
}
}
Prefer pulling the username/password from ~/.gradle/gradle.properties or
environment variables rather than hardcoding the PAT in the file.
API reference — AarambhSdk
flutter-plugin exposes the same full surface as the native dummy app's
MainActivity.kt — every public method on native AarambhSDK has a matching
MethodChannel case and Dart method, split into two groups.
Pass-through / dispatch methods
Return Future<void>, resolve with null on success, throw
PlatformException on failure (e.g. launch() called with no attached
Activity throws code NO_ACTIVITY).
| Dart method | Native call | Notes |
|---|---|---|
initialize(config) |
AarambhSDK.initialize() |
Call once at startup, before any other call. See config keys below. |
login({authToken, userDetails, agentDetails}) |
AarambhSDK.login() |
Hands over an existing session instead of driving the SDK's own OTP flow. Only
authToken is required. agentDetails (v0.1.6+) is optional and distinct
from userDetails — omitting it falls back to agentDetails = userDetails.
Must be called before launch() for the initial handoff — see the
call-order warning below. |
launch() |
AarambhSDK.launch(activity) |
Starts SDKActivity. Throws NO_ACTIVITY with no attached Flutter
Activity. |
close() |
AarambhSDK.close() |
Finishes the currently active SDKActivity, if any. |
requestPermissions() (optional) |
AarambhSDK.requestPermissions() |
Not required — only call this if you'd rather not build your own runtime permission flow (location,
battery optimisation, notifications, camera). Triggers the SDK's own step-by-step permission UI
instead. Starts SDKActivity if it isn't already running. |
initialize() config keys
await AarambhSdk.initialize({
'environment': 'sandbox', // 'sandbox' | 'live' — defaults to 'live' if omitted
'subscriberId': 'my-subscriber-id',
'appname': 'My Flutter Host App',
// optional branding:
// 'vendorCode': '...',
// 'clientLogo': '...',
// 'privacy': 'https://...',
// 'terms': 'https://...',
// 'overlayIconUrl': 'https://.../icon.png',
});
clientUri/sseUriare not accepted from the host app — resolved internally fromenvironment, always overwriting anything passed under those keys.environmentdefaults toliveif omitted, so a forgetful integration fails safe to production rather than silently landing on sandbox.overlayIconUrlneeds more than just being present in this config to actually show up — it only reaches the native overlay bubble once the SDK's UI reaches its home screen with a backend-accepted session (a fake/expired token that gets rejected never gets there). It's then fetched and cached lazily the first time the bubble is shown.
login() call order for an initial handofflogin() always stashes the token/details into native's in-memory config synchronously — but
that only reaches the WebView reliably one way: main.ts reads it once via
SdkBridge.getConfig(), before Angular bootstraps inside a freshly started
SDKActivity. Call login() and await it, then call
launch(), and this happens automatically with no race.
Calling login() after launch() instead falls into the live-dispatch
path above — silently dropped unless SDKActivity's bridge has already attached, which is
unlikely if there's no human-scale delay between the two calls. The symptom looks exactly like the token
was never set: the app finds no usable session and falls back to its own OTP login screen. (Calling
login() again after SDKActivity is already visible is the supported
way to switch sessions live, without a launch()/close() round-trip — that's
what live dispatch is actually for.)
Usage example
import 'package:aarambh_sdk/aarambh_sdk.dart';
import 'package:flutter/services.dart';
Future<void> setupAarambhSdk() async {
// Call once at startup — BEFORE login()/launch()/any other call.
// Values are only read when SDKActivity starts up.
await AarambhSdk.initialize({
'environment': 'sandbox',
'subscriberId': 'my-subscriber-id',
'appname': 'My Flutter Host App',
});
}
Future<void> loginAndOpenSdkUi(String authToken, Map<String, dynamic>? userDetails, Map<String, dynamic>? agentDetails) async {
// Your own backend already returned this authToken (e.g. from acquire_session -
// see "Acquiring a session" above). login() MUST complete before launch() - calling
// them the other way round routes through live dispatch instead, which silently
// drops the call unless SDKActivity's bridge has already attached. userDetails and
// agentDetails are both optional; only authToken is required.
await AarambhSdk.login(authToken: authToken, userDetails: userDetails, agentDetails: agentDetails);
try {
await AarambhSdk.launch(); // starts the visible SDKActivity
} on PlatformException catch (e) {
if (e.code == 'NO_ACTIVITY') {
// launch() needs a widget/screen context, not a background isolate.
}
rethrow;
}
}