Flutter SDK
Flutter quickstart for the amba Dart package — pubspec dep, Amba.configure(), first track, first collection insert, platform-channel notes for sign-in and push.
Amba for Flutter is published to pub.dev as amba. One package, every platform Flutter supports.
Supported platforms: iOS 13+, Android API 24+, macOS 12+, Windows 10+, Linux (x86_64).
1. Add the dependency
Or in pubspec.yaml:
Run flutter pub get. The pub publisher attaches the prebuilt native binaries per platform, so no separate build step is needed.
2. Configure at app start
Pass the key via --dart-define:
Amba.configure() is idempotent only for the first call — the underlying amba_init rejects re-init with "amba already initialized". To swap tenants in the same process, use the SDK's reset flow (amba_reset via the FFI) before re-calling configure. For typical apps this never matters: configure once at boot.
3. First sign-in (anonymous)
events.track is authenticated server-side — the request needs a session token. Mint one anonymously on first launch:
signInAnonymously() returns a Map<String, dynamic>; cast through your own model classes for type safety. The session token persists across app restarts (amba writes to platform-appropriate storage), so you only mint a new anonymous session on first launch.
4. First event
Once a session exists, track engagement events:
5. Sign in with Apple
Use sign_in_with_apple on iOS, then forward the identity token:
Enable the Sign in with Apple capability in Xcode (ios/Runner/Runner.entitlements) before building.
6. Sign in with Google
Use google_sign_in for the OAuth dance, then forward the idToken:
The serverClientId is the Web OAuth client ID from Google's API credentials console — not iOS or Android. Set up iOS in ios/Runner/Info.plist (CFBundleURLTypes) and Android in android/app/build.gradle per the google_sign_in setup guide.
7. Register for push
Use firebase_messaging on both platforms — it handles APNs registration on iOS and FCM on Android, returning a single token type per platform that you forward to amba:
Add the Push Notifications capability + Background Modes → Remote notifications in Xcode for iOS. For Android, add Firebase the standard way (google-services.json in android/app/).
8. First collection insert
For typed reads, cast through your own model classes or generate them with json_serializable.
9. AI proxy
Constructor DI for tests
AmbaClient accepts an AmbaBindings via the constructor — tests inject a fake, production code goes through the singleton Amba.configure(...) which wires real native bindings.
Platform notes
| Platform | Native library | Notes |
|---|---|---|
| iOS | static lib linked into the app | Statically linked — no .framework to embed. Sign in / push via platform packages above. |
| Android | libamba_core.so in jniLibs/<abi>/ | Same four ABIs as the Kotlin SDK (arm64-v8a, armeabi-v7a, x86_64, x86). |
| macOS | libamba_core.dylib in app bundle | Code-signed; entitlements unchanged from default Flutter macOS apps. |
| Windows | amba_core.dll next to the .exe | Requires MSVC runtime; ships in the standard Flutter Windows installer. |
| Linux | libamba_core.so next to the binary | x86_64 only; tested on Ubuntu 22.04 + Fedora 39. |
| Web | not supported (Flutter for Web) | Use @layers/amba-web from JS interop if you must. |
Common pitfalls
Amba.configurenot called before any otherAmba.*access throwsStateError("Amba.configure must be called before accessing Amba.*"). Always configure inmain()afterWidgetsFlutterBinding.ensureInitialized().- Hot-reload re-running
main()— callingAmba.configure()again throwsAmbaException("amba already initialized")on the second run. Wrap with atry/catchfor development: - Native library not found at runtime — verify it shipped in the build output. For Android:
unzip -l build/app/outputs/flutter-apk/app-release.apk | grep amba_core. For iOS:otool -L Runner.app/Runner | grep amba_core. - Apple sign-in works in simulator, fails on device — the entitlement requires the app to be signed with a provisioning profile that includes the Sign in with Apple capability. Re-fetch the profile in Xcode after enabling.
See also
- Client API reference — HTTP endpoint reference for every namespace.
- Code samples — same operations side-by-side with the other 7 SDKs.
- Push notifications — campaign API, scheduling, fan-out.
- SDK on pub.dev.