Push notifications
Push notifications in the Flutter SDK.
import 'package:nexus_flutter/nexus.dart';| Symbol | Kind | Summary |
|---|---|---|
PushPlatform | enum | The device platform a push token belongs to. |
PushProvider | enum | The delivery provider a push token targets. |
NexusPush | class | Nexus Push. |
PushPlatform
enumenum PushPlatformThe device platform a push token belongs to.
| Value | Description |
|---|---|
PushPlatform.ios | |
PushPlatform.android | |
PushPlatform.web |
PushProvider
enumenum PushProviderThe delivery provider a push token targets.
| Value | Description |
|---|---|
PushProvider.fcm | |
PushProvider.apns | |
PushProvider.webpush |
NexusPush
classNexus Push. With pushEnabled: true this is fully turn-key — start runs at
init and handles permission, token acquisition, registration, refresh and
open-tracking for you. The manual methods (registerToken/reportOpen) stay
available for BYO-token setups (e.g. raw APNs or your own messaging plugin).
token
propertyString? get tokenThe last token registered this launch.
View sourcelanguage
propertyString? get languageThe language notifications are localized to for this device (or null).
View sourcetags
propertyMap<String, String> get tagsThe subscriber tags currently set on this device.
View sourceonOpened
fieldvoid Function(NexusPushOpen open)? onOpenedCalled when a notification (or one of its action buttons) is opened. Set
this to route the user, or to handle an action button's actionUrl.
setLanguage()
methodFuture<void> setLanguage(String lang)Set the user's app language so campaigns are delivered localized to it
(e.g. setLanguage('en') / setLanguage('ar')). Call it at startup with
the app's current locale, and again whenever the user changes it. The code
is attached to the device token; a campaign with content for that language
is sent in it, otherwise the campaign's default language is used.
Safe to call before or after push is enabled — if a token is already registered it re-registers immediately; otherwise the language is applied on the next registration.
Parameters
Prop
Type
setTag()
methodFuture<void> setTag(String key, String value)Tag this subscriber with a key/value so you can target them in segments —
e.g. setTag('role', 'client'), setTag('username', 'ehs4nnn'). Build
tag-condition segments in the console (Push → Segments → Tag is …).
Safe before or after push is enabled: if a token is already registered the tags sync immediately, otherwise they're attached on the next registration.
Parameters
Prop
Type
setTags()
methodFuture<void> setTags(Map<String, String> tags)Set several tags at once (merged into the existing tags).
Parameters
Prop
Type
removeTag()
methodFuture<void> removeTag(String key)Remove a previously set tag.
Parameters
Prop
Type
clearTags()
methodFuture<void> clearTags()Clear all tags from this subscriber.
View sourcestart()
methodFuture<void> start()Turn-key enable: permission → token → register → refresh + open handlers.
Called automatically when pushEnabled is set. Safe to call again; every
failure is caught and logged so push can never break the app.
registerToken()
methodFuture<void> registerToken(String token, {required PushPlatform platform, PushProvider? provider, String? lang})Register (or refresh) this device's push token, correlated to the journey
identity. Call this yourself only for BYO-token setups; pushEnabled does
it automatically.
Parameters
Prop
Type
unregister()
methodFuture<void> unregister([String? token])Stop delivering to a token (call on logout/uninstall). Defaults to the last registered token.
Parameters
Prop
Type
reportOpen()
methodFuture<void> reportOpen(Map<String, dynamic> data)Report a notification open. Reads nexus_campaign_id from the payload
(Nexus stamps it on every campaign push) to power open-rate + A/B outcomes.
With pushEnabled this is wired for you; call it manually only for BYO setups.
Parameters
Prop
Type
dispose()
methodFuture<void> dispose()Cancel the refresh/open/foreground listeners (called on Nexus dispose / re-init).
View source