Flutter
Getting started
The localytics_flutter_sdk
plugin wraps the official Localytics native SDKs for Android and iOS. Native initialization stays in your
platform code (Application on Android, AppDelegate on iOS); after that, call the SDK
from Dart through the Localytics facade.
The plugin ships on pub.dev as localytics_flutter_sdk (the localytics_flutter name
is held by a legacy package). Source and an example app live in the
localytics-flutter GitHub repository.
Native SDK references:
Requirements
| Minimum | |
|---|---|
| Flutter | 3.22.0 (Swift Package Manager enabled) |
| Dart | 3.5.0 |
| Android | minSdk 24 (matches Flutter stable's enforced runtime floor) |
| iOS | 12.0 |
Native SDK versions bundled by the current plugin release:
- Android —
com.localytics.androidx:library:7.1.0from the Localytics public Maven repo. - iOS — Localytics-swiftpm
7.1.1via Swift Package Manager.
Install the plugin
Add the dependency to your app pubspec.yaml:
dependencies:
localytics_flutter_sdk: ^1.0.3
Then fetch packages:
flutter pub get
Import in Dart:
import 'package:localytics_flutter_sdk/localytics_flutter_sdk.dart';
iOS setup
Enable Swift Package Manager
The plugin ships iOS support via SPM only (no CocoaPods podspec). Enable SPM once per machine:
flutter config --enable-swift-package-manager
Verify with flutter config (enable-swift-package-manager: true). The first iOS build
fetches Localytics-swiftpm from GitHub; later builds use the cache.
App key
Unlike Android (localytics.xml), iOS expects the app key when you build the Localytics
instance in AppDelegate. Use either:
- Info.plist + xcconfig —
LocalyticsAppKeyset to$(LOCALYTICS_APP_KEY)in a gitignoredios/Flutter/LocalyticsEnv.xcconfig, included from Debug/Release xcconfig files. - Inline —
.settingAppKey("your-ios-app-key")in the builder.
Push, Places, background modes, and permission delegates follow the iOS integration guide.
Android setup
Maven repository
The plugin adds the Localytics Maven repo, but your app-level Gradle configuration must also expose it (Gradle resolves from the consuming app):
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url 'https://maven.localytics.com/public' }
}
}
localytics.xml
Add android/app/src/main/res/values/localytics.xml with your app key
(ll_app_key). See the Android integration guide for the full template.
Google Play Services Ads Identifier
The plugin pulls play-services-ads-identifier transitively for ADID resolution. Stores without
Google Play Services may exclude that module in the app build.gradle; the SDK proceeds without ADID.
Initialization
This plugin does not wrap native SDK initialization. Use the standard Localytics
Builder / autoIntegrate flow on each platform before calling Dart APIs.
Android
FlutterFragmentActivity
In-app messages require FragmentActivity. Use FlutterFragmentActivity instead of
FlutterActivity:
import io.flutter.embedding.android.FlutterFragmentActivity
class MainActivity : FlutterFragmentActivity()
Application class
Register a custom Application in AndroidManifest.xml and call
Localytics.Builder()…autoIntegrate(this) from onCreate(). The app key comes from
localytics.xml.
iOS
Call Localytics.builder()…autoIntegrate() in
application(_:didFinishLaunchingWithOptions:) before returning from super.
didInitializeImplicitFlutterEngine, not only in didFinishLaunchingWithOptions.
Using the wrong scaffold causes MissingPluginException at runtime.
Scene-based AppDelegate (implements FlutterImplicitEngineDelegate):
import Flutter
import Localytics
import UIKit
@main
@objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
let appKey = (Bundle.main.object(forInfoDictionaryKey: "LocalyticsAppKey") as? String)
?? "YOUR_IOS_APP_KEY"
var builder = Localytics.builder()
.settingAppKey(appKey)
.settingLaunchOptions(launchOptions)
#if DEBUG
builder = builder.settingLoggingEnabled(true)
#endif
builder.build().autoIntegrate()
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) {
GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)
}
}
Legacy scaffold (no SceneDelegate): register via super only; same builder in
didFinishLaunchingWithOptions.
Dart API
After native init, use the Localytics class:
await Localytics.setLoggingEnabled(true);
await Localytics.tagEvent('Onboarding Completed');
await Localytics.setCustomerId('user-123');
await Localytics.upload();
Major API areas:
- Privacy / logging —
setLoggingEnabled,setOptedOut,setPrivacyOptedOut - Session —
openSession,closeSession,upload - Events —
tagEvent,tagScreen, ecommerce and content helpers - Profile —
setProfileAttribute, sets, increment/decrement - In-app —
triggerInAppMessage, dismiss and styling helpers - Diagnostics —
getLibraryVersion,Localytics.pluginVersion
The plugin tags events with a library identifier such as
androida_7.1.0:Flutter_1.0.3 or iosa_7.1.1:Flutter_1.0.3 for dashboard breakdowns.
Push messaging
Complete platform setup (FCM on Android, APNs and capabilities on iOS) using the Android and iOS push guides. Forward notification callbacks into the plugin from Dart:
- Android —
handleFirebaseMessage,registerPush,tagPushReceivedEvent - iOS —
didReceiveNotificationResponse,handleNotification,handleNotificationReceived, authorization helpers
Platform-only methods no-op on the other OS so shared Dart push code does not throw.
In-app messaging
Use triggerInAppMessage and related APIs from Dart. On Android, FlutterFragmentActivity
is required for the native dialog fragment. Customize dismiss button location and session-start triggers via the
Dart surface documented on pub.dev.
Location and Places
setLocationMonitoringEnabled and persistLocationMonitoring configure the native SDK
after your app has obtained location permission (for example with permission_handler). They do not
show the system dialog. Add manifest / Info.plist entries and any iOS delegate wiring described in the
iOS guide.
App Inbox
Inbox campaigns are available through getInboxCampaigns, refreshInboxCampaigns,
read/unread counts, and related methods. See the plugin API reference for InboxCampaign models.
Resources
Before release, smoke-test flutter build apk --release and
flutter build ios --release on a clean consumer app.