Flutter SDK
Install agent44 in a Flutter app for iOS and Android: configure it, identify signed-in users with a signature, open the chat and help center, show update prompts and set up push.
AAgent44Updated 12 min read
On this page
- Quick start
- 1. Get your SDK key
- 2. Install the package
- 3. Start the SDK
- 4. Add a chat button
- Tell agent44 who your users are
- Verify your users
- Keep the signature out of backups (recommended with verification)
- Everything you can open
- Update prompts and What's New
- Push notifications (optional)
- Not yet in this version
Add customer support to your Flutter app in a few minutes: a chat with your team and AI agent, a help center, "update your app" screens and What's New. You manage all of it from your agent44 dashboard.
Works on iOS and Android.
Other platforms: iOS (Swift), Android (Kotlin) and React Native have their own SDKs, with the same screens and talking to agent44 in the same way.
The full reference, with every option, is the SDK's README on GitHub: harithwick/agent44-flutter.
Quick start#
1. Get your SDK key#
In agent44, open Settings › Apps, pick your app (or Add app) and click Create SDK key. Copy it: it starts with a44_pub_ and is shown only once.
Your app is on both stores? Add it once for iOS and once for Android. You'll get one key for each.
2. Install the package#
flutter pub add agent44It needs Flutter 3.38.1 or newer, and your app must target Android API 24 (Android 7.0) and iOS 15 or newer:
Android:
webview_flutter,url_launcher,shared_preferencesandimage_pickerneed API 24. SetminSdk = 24inandroid/app/build.gradle.ktsif your app targets less (flutter.minSdkVersionis 24 on Flutter 3.50).iOS:
image_pickerneeds iOS 15 on Flutter 3.47 and newer (its iOS 13 releases are only picked on older Flutter versions, wherefile_pickerstill needs iOS 14). SetIPHONEOS_DEPLOYMENT_TARGET = 15.0in Xcode and, if yourios/Podfilehas one,platform :ios, '15.0'.
iOS: so users can attach photos, add this to ios/Runner/Info.plist (inside <dict>):
<key>NSPhotoLibraryUsageDescription</key>
<string>Attach photos to your messages to support.</string>Android: so release builds can reach agent44, add this to android/app/src/main/AndroidManifest.xml, above <application>. Flutter's template only adds it to debug builds, so without it everything works in debug and nothing loads in release.
<uses-permission android:name="android.permission.INTERNET"/>3. Start the SDK#
Replace your main() with this, using your keys from step 1:
import 'package:agent44/agent44.dart';
import 'package:flutter/material.dart';
final navigatorKey = GlobalKey<NavigatorState>();
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Agent44.configure(
publicKeyIos: 'a44_pub_YOUR_IOS_KEY',
publicKeyAndroid: 'a44_pub_YOUR_ANDROID_KEY',
navigatorKey: navigatorKey,
);
runApp(MaterialApp(
navigatorKey: navigatorKey, // the same key as above
home: const HomeScreen(),
));
}The navigatorKey lets the SDK show update prompts and in-app messages, and open the chat from a notification. Without it they quietly don't appear.
Using a router? Give your router the same key:
// go_router, with MaterialApp.router
final navigatorKey = GlobalKey<NavigatorState>();
final router = GoRouter(navigatorKey: navigatorKey, routes: […]);
await Agent44.configure(…, navigatorKey: navigatorKey);
runApp(MaterialApp.router(routerConfig: router));// auto_route: use the router's own root key
final appRouter = AppRouter();
await Agent44.configure(…, navigatorKey: appRouter.navigatorKey);
runApp(MaterialApp.router(routerConfig: appRouter.config()));4. Add a chat button#
Put the round chat button in the corner of any screen. It shows the unread count, and a tap opens the chat:
Scaffold(
floatingActionButton: const Agent44Launcher(),
floatingActionButtonLocation: Agent44Launcher.location, // left or right, as set in agent44
body: …,
)You can also open it from your own button:
ElevatedButton(
onPressed: () => Agent44.openChat(context),
child: const Text('Chat with us'),
)That's it. Run your app, tap the button and send a message. It appears in your agent44 inbox, and the "Install the SDK" step in your dashboard's setup checklist ticks itself off.
The chat looks like a modern support widget:
a card at the top with your logo, your name, when the team replies and whether it's online
grouped bubbles: the user's on a faint tint of your brand colour, your team's on white cards under their name
a message box with buttons to attach a file or a photo, and a "Send" button
Before you submit to the App Store or Google Play, see "Data the SDK collects" in the SDK's README for the privacy labels and Data safety form.
Tell agent44 who your users are#
Call this after your user signs in, so your team knows who they're talking to and the user sees their conversations on every device:
await Agent44.identify(Agent44User(
userId: user.id, // your app's own user id
email: user.email, // everything else is optional
name: user.name,
phone: user.phone,
avatarUrl: user.photoUrl,
company: const Agent44Company(
name: 'Acme',
url: 'https://acme.com',
employment: Agent44Employment(title: 'CTO'),
geolocation: Agent44Geolocation(city: 'London', country: 'GB'),
),
signature: user.agent44Hash, // see "Verify your users" below
));And when they sign out:
await Agent44.logout();identify throws an Agent44Exception when agent44 can't be reached. Catch it and try again later: the previous identity stays in place until it works. logout never throws for network errors, so it's safe to await in your sign-out flow. "Error handling" in the README lists what every call throws.
People can chat before they sign in too. Their conversations move to their account when you call identify.
Verify your users#
Without verification, agent44 trusts the id you send. Anyone with your app's key and a user's id could then read that user's conversations. Identity verification stops that, and new workspaces start with it enforced: until your server signs user ids, identify is refused (401) and signed-in screens show their error state, while people who haven't signed in chat as usual.
In agent44, open Settings › Identity verification and click Generate secret. The secret starts with
a44_idv_and is shown only once: copy it into your server's configuration. It belongs on your server only. One secret covers every app in the workspace (iOS, Android and web).When your app signs in, have your server compute the HMAC-SHA256 of the user's id, keyed with the whole secret (the
a44_idv_included). Return it as lowercase hex.Pass it as
signaturetoAgent44.identify. The SDK sends it with every request.If Enforce is off in your workspace, click Turn on Enforce once your app version with signatures is live.
// Node, on your server
crypto.createHmac('sha256', process.env.AGENT44_IDENTITY_SECRET).update(user.id).digest('hex');While Enforce is off, nothing is refused: a missing or wrong signature is ignored and the id is trusted as sent, so you can ship the app version that sends signatures first. While it's on, a user id with a missing or wrong signature gets a 401: identify throws an Agent44Exception with statusCode 401 (and nothing is saved), and the screens show their error state. People who haven't signed in are unaffected. If your app has no server that could sign ids, an admin can turn Enforce off in the same place; use ids that can't be guessed then.
Enforce is per workspace: every app's key in it is checked against the same secret, because a user's conversations are shared across your apps.
Rotate secret replaces the secret at once, and signatures made with the old one stop matching. With Enforce on, update your server straight after rotating (or turn Enforce off, rotate, deploy, and turn it back on).
Either way, use ids that can't be guessed: your database id or a UUID, not an email address or a number like 42.
Keep the signature out of backups (recommended with verification)#
The SDK keeps the signature on the device so the user stays signed in. With your app's key, the user id and signature are enough to act as that user, and the signature doesn't expire until you rotate the secret. By default it's in SharedPreferences, which are plain files that Android's auto-backup and iOS device backups copy, so a backup restored to another phone carries it.
To keep it in the iOS Keychain and the Android Keystore instead, add flutter_secure_storage (flutter pub add flutter_secure_storage, version 11 or later), copy this adapter into your app, and wrap it in SecureIdentityStorage:
import 'package:agent44/agent44.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
/// agent44's secure values in the iOS Keychain and the Android Keystore.
class FlutterSecureStorageAdapter implements Agent44Storage {
static const _storage = FlutterSecureStorage(
// Readable after the first unlock (so background launches from a push work),
// and never copied to another device by a backup.
iOptions: IOSOptions(accessibility: KeychainAccessibility.first_unlock_this_device),
);
@override
Future<String?> read(String key) => _storage.read(key: 'agent44.$key');
@override
Future<void> write(String key, String? value) => _storage.write(key: 'agent44.$key', value: value); // null deletes
}
await Agent44.configure(
publicKey: 'a44_pub_…',
storage: SecureIdentityStorage(secure: FlutterSecureStorageAdapter()),
);SecureIdentityStorage puts only the user id and signature in the secure store. Everything else (the anonymous id, the last app version, which messages were seen) stays in SharedPreferences.
Existing installs keep working. A user signed in by an earlier version is moved to the secure store on the next launch and stays signed in.
A reinstall starts signed out. Keychain items outlive the app on iOS, so the SDK ignores what it finds there until this install has written it. Pass the adapter as
storage:directly and everything, the anonymous id included, would come back after a reinstall.logout()clears both stores. If the secure store can't delete, the SDK ignores what's left from then on.If you stop using it, the user is signed out on the next launch (their id stays in the secure store), so call
identifyagain after sign-in as usual.
On Android, a restored backup of flutter_secure_storage's files can't be decrypted on the new phone (the Keystore key isn't backed up). flutter_secure_storage then deletes all of its values, yours included. Leave its two files out of backups. Add android/app/src/main/res/xml/backup_rules.xml (Android 11 and lower):
<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
<exclude domain="sharedpref" path="FlutterSecureStorage.xml" />
<exclude domain="sharedpref" path="FlutterSecureKeyStorage.xml" />
</full-backup-content>and android/app/src/main/res/xml/data_extraction_rules.xml (Android 12 and later):
<?xml version="1.0" encoding="utf-8"?>
<data-extraction-rules>
<cloud-backup>
<exclude domain="sharedpref" path="FlutterSecureStorage.xml" />
<exclude domain="sharedpref" path="FlutterSecureKeyStorage.xml" />
</cloud-backup>
<device-transfer>
<exclude domain="sharedpref" path="FlutterSecureStorage.xml" />
<exclude domain="sharedpref" path="FlutterSecureKeyStorage.xml" />
</device-transfer>
</data-extraction-rules>then point your AndroidManifest.xml at both:
<application
android:fullBackupContent="@xml/backup_rules"
android:dataExtractionRules="@xml/data_extraction_rules"
...>Excluding only some files keeps the rest of your app's backup. If you already have rules files, add these lines to them.
Without a secure store, you can still keep the signature out of Android backups: exclude FlutterSharedPreferences.xml (the file SharedPreferences.getInstance() writes, where the SDK's values are under keys starting with flutter.agent44.) in the same two files. That leaves out every value your app keeps with SharedPreferences.getInstance() too, so its settings won't come back on a new phone; values saved with SharedPreferencesAsync or SharedPreferencesWithCache are in DataStore by default and aren't affected. iOS has no way to leave SharedPreferences out of backups, so there the secure store is the only fix.
Everything you can open#
Each of these is one line, called from any button or menu:
What | Code |
|---|---|
The chat (latest open conversation, or a new one) |
|
Messenger (home, messages, help and updates tabs) |
|
Start a new message |
|
Help center |
|
Search help |
|
Ask AI a question |
|
One help article |
|
What's new (changelog) |
|
The article id is the 10 characters after /articles/ in the article's web address.
Update prompts and What's New#
No extra code needed. Create these in agent44 under Engagement, and the SDK shows them when the app opens:
Force update: a full screen the user can't close until they update. Use it when an old version stops working. Under its button, Contact support opens the chat over it, so someone who can't update can still reach you; closing the chat comes back to the force update.
Recommended update: a sheet asking them to update, which they can skip.
What's New: shown once after the user updates, with your changelog entry.
Announcements, banners and chat messages: for news and offers.
Only the most important one shows each time the app opens.
Users who can't install the update don't see it. Give a force or recommended update a Minimum system in agent44 (the oldest iOS version and Android API level the new build installs on; filled in from App Store Connect and Google Play when they're connected). The SDK sends the device's OS version, and on Android its API level, with each check, so a phone too old for the new build keeps using the app instead of being locked out. Without a minimum, everyone on an older app version sees it, as before.
Send a message to some users only. Every in-app message except a force update can have an Audience: a saved segment from Users (built on attributes, SDK segments from setSegments, versions…). It shows only to users who match it, so call identify and setSegments before the check runs (or check later with showInAppMessages: false). A fresh install agent44 hasn't seen yet matches no segment. Force updates can't be limited to a segment: they go to everyone on an older version.
Want to choose when they show? Turn off the automatic check and call it yourself, for example after your onboarding:
await Agent44.configure(
publicKeyIos: '…',
publicKeyAndroid: '…',
navigatorKey: navigatorKey,
showInAppMessages: false,
);
// later:
await Agent44.checkInAppMessages();Push notifications (optional)#
With push, users get a notification when your team or the AI agent replies (tapping it opens the conversation), and you can send push campaigns from agent44's Engagement. Without push, users with an email address still get replies by email.
agent44 sends straight to Apple (APNs) for iOS and through Firebase Cloud Messaging for Android.
1. In agent44: open Settings › Apps, pick each app and set up Push notifications:
iOS app: your APNs key (the
.p8file from Apple Developer › Keys, with its Key ID and your Team ID). One key works for all your iOS apps.Android app: your Firebase service account key (Firebase console › Project settings › Service accounts › Generate new private key).
2. In your app: the example uses firebase_messaging (run flutter pub add firebase_messaging, and add Firebase to your app if it isn't there yet). Add this after Agent44.configure(...):
import 'dart:io' show Platform;
import 'package:firebase_messaging/firebase_messaging.dart';
final messaging = FirebaseMessaging.instance;
final permission = await messaging.requestPermission();
final allowed = permission.authorizationStatus != AuthorizationStatus.denied;
// Give agent44 this phone's push token.
// iOS: the Apple (APNs) token. Android: the Firebase token.
Future<void> sendToken() async {
final token = Platform.isIOS ? await messaging.getAPNSToken() : await messaging.getToken();
if (token != null) await Agent44.setPushToken(token, enabled: allowed);
}
await sendToken();
messaging.onTokenRefresh.listen((_) => sendToken());
// When a notification is tapped: a reply opens its conversation,
// a campaign opens its link (if it has one).
FirebaseMessaging.onMessageOpenedApp.listen((m) => Agent44.handlePushTap(m.data));
// The tap that launched the app. Fine before runApp: the conversation opens once the app is up.
final initial = await messaging.getInitialMessage();
if (initial != null) Agent44.handlePushTap(initial.data);
// While the app is open: keeps the unread badge and open conversation up to date
FirebaseMessaging.onMessage.listen((m) => Agent44.handleForegroundPush(m.data));Good to know:
Opening a conversation needs the
navigatorKeyfrom step 3, the one yourMaterialApporGoRouter(navigatorKey: …)has. A tap that launched the app waits for that navigator, sogetInitialMessage()works inmain()beforerunAppor later in your first screen. It's dropped if the navigator isn't up within 30 seconds, or if the user signs out first.On iOS,
getAPNSToken()can returnnullfor a moment on first launch. CallingsendToken()again when the app comes back to the foreground covers it.Campaign links can be an
https://page or your app's own deep link (myapp://…). Deep links open only when you list their scheme:Agent44.configure(…, deepLinkSchemes: ['myapp']). Without it onlyhttps://links open; anything else (http:,tel:,intent:, another app's scheme) is ignored, andonOpenUrlonly gets links the SDK would open. To send deep links through your router instead of the system, passonOpenUrl:Agent44.handlePushTap(m.data, onOpenUrl: (url) => router.go(url.path)).Using a different push plugin? Any works: on iOS pass the raw APNs device token (hex), on Android the FCM token, and pass each notification's data to
handlePushTap/handleForegroundPush.Agent44.logout()stops that user's notifications on the phone.Campaign links are stricter than links in messages and articles (below): no
http:,mailto:ortel:.
Not yet in this version#
Nothing: the Flutter SDK is the reference the iOS, Android and React Native SDKs follow, and each of their guides lists what they don't have yet compared with it.