Plugin Methods
Complete API documentation for PNTA Flutter plugin
Core Methods
initialize()
Initializes the plugin and optionally registers the device. When registerDevice: true
(default), this method will prompt the user for notification permission and register the device with PNTA. Use registerDevice: false
for delayed registration if you don’t want to prompt the user immediately.
Parameters:
projectId
: Your PNTA project ID (format:prj_XXXXXXXXX
)metadata
(optional): Device metadata as key-value pairsregisterDevice
(optional): Whether to register device immediately. Default:true
autoHandleLinks
(optional): Automatically handlelink_to
URLs when notifications are tapped from background/terminated state. Default:false
showSystemUI
(optional): Show system notification banner/sound when app is in foreground. Default:false
Returns: Future<void>
Examples:
registerDevice()
Registers the device with your PNTA project using metadata from initialize()
. Only needed when using delayed registration (when initialize()
was called with registerDevice: false
).
Returns: Future<void>
Example:
Must call initialize()
first. Only use this method when you initialized with registerDevice: false
.
updateMetadata()
Updates device metadata without re-registering.
Parameters:
metadata
: Updated metadata as key-value pairs
Returns: Future<void>
Example:
handleLink()
Manually handles a link using the plugin’s routing logic.
Parameters:
link
: The link to handle
Returns: void
Example:
Properties
deviceToken
Gets the current device token after successful initialization or registration.
Type: String?
Returns: Device token string if registration was successful, null
otherwise.
Example:
navigatorKey
Global navigator key for internal route navigation. Must be assigned to your MaterialApp
.
Type: GlobalKey<NavigatorState>
Example:
foregroundNotifications
Stream of notification payloads received when app is in foreground.
Type: Stream<Map<String, dynamic>>
Payload Structure:
Both iOS and Android send identical flat payload structures:
Example:
onNotificationTap
Stream of notification payloads when user taps a notification from background/terminated state.
Type: Stream<Map<String, dynamic>>
Payload Structure:
Contains the link_to
field and any custom data fields. System fields (title
, body
) are not available on Android due to platform limitations.
Example:
Link Handling
The plugin handles notification links automatically using smart URL detection:
- External URLs (with scheme) → Opens in system browser/apps
- Examples:
https://example.com
,mailto:test@example.com
,tel:+1234567890
,sms:+1234567890
- Works automatically with no additional configuration required
- Examples:
- Internal routes (without scheme) → Navigates using Flutter’s Navigator
- Examples:
/profile
,/settings
,/dashboard
- Requires
navigatorKey
setup (covered in Quick Start)
- Examples:
Implementing Notification Listeners
App-Level
Global listeners in main.dart
. No disposal needed since the app doesn’t get disposed.
Widget-Level
Listeners in StatefulWidgets. Disposal required to prevent memory leaks.