Quickstart
flutter pub add onesygnalimport 'package:onesygnal/onesygnal.dart';
Future<void> setUpOneSygnal() async {
await OneSygnal().setApiKey('YOUR_API_KEY');
await OneSygnal().initialize();
await OneSygnal().track('page_viewed');
await OneSygnal().identify('user_123', attributes: {'plan': 'pro'});
}That’s it — surveys matching your active trigger rules render automatically as a native
overlay above your app. setApiKey() must be called before initialize(); everything
else can be called in any order after initialize() resolves.
initialize()’s returned Future<bool> only resolves once native init has fully
finished — config fetched, user ensured, surveys fetched, rules engine loaded. On a slow
network this can take several seconds (bounded by the native HTTP timeouts, times up to
four sequential calls in the worst case). Don’t block your UI on
await OneSygnal().initialize() — show an “Initializing…” state instead, or use the
ready event (see Events) if you don’t need the returned
bool.
See Configuration for setLocale() and the rest of
the pre-init calls.