Skip to main content
trevosdk_flutter runs experiments and records events in Flutter apps, assigning the same variant the web SDK does for the same user. Written in Dart; its one dependency is path_provider. Flutter 3.24 and later, on iOS and Android.

Create the client

Use a Mobile key (tsk_live_…), passed in at build time with --dart-define. Pass the installed build’s version too; package_info_plus reads it. Create one client for the app’s lifetime:
appVersion is required on purpose: without the real build version, a minAppVersion experiment returns control for everyone. Never hard-code a sample version.

Read a variant

getVariant is synchronous. It returns control until stored state and the first config fetch have loaded, so wait for ready() before showing experiment UI:
Each call records an exposure the first time. Pass trackExposure: false to read without recording one. onChange calls a listener whenever config or identity changes and returns a function that stops it.

Parameters

A parameter lets later experiments change a value with no release:
The default’s type decides the result’s: String, bool, int or double. A value of another type, or a number that isn’t whole for an int, serves the default. A String parameter can carry text per language: pass your app’s own translation as the default and call trevo.setLocale(...) with the locale your app shows, such as Localizations.localeOf(context).toLanguageTag(), since only your app knows it. Without it the SDK reads the device’s language.

Track events and identify users

Events are queued on disk and sent in batches every 15 seconds, when the app moves to the background, and on await trevo.flush(). The SDK keeps its files in trevosdk under the app support directory, which device backups include. A device restored from a backup then shares the anonymous id of the one it came from. On Android you can leave the folder out of backups in your data_extraction_rules.xml (and full_backup_content for Android 11 and older):