Skip to main content

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 pairs
  • registerDevice (optional): Whether to register device immediately. Default: true
  • autoHandleLinks (optional): Automatically handle link_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:
lib/main.dart

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:
lib/main.dart
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:
lib/main.dart
Manually handles a link using the plugin’s routing logic. Parameters:
  • link: The link to handle
Returns: void Example:
lib/main.dart

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:
lib/main.dart
Global navigator key for internal route navigation. Must be assigned to your MaterialApp. Type: GlobalKey<NavigatorState> Example:
lib/main.dart

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:
lib/main.dart

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:
lib/main.dart
The plugin handles notification links automatically using smart URL detection:
  • External URLs (with scheme) → Opens in system browser/apps
    • Examples: https://example.com, mailto:[email protected], tel:+1234567890, sms:+1234567890
    • Works automatically with no additional configuration required
  • Internal routes (without scheme) → Navigates using Flutter’s Navigator
    • Examples: /profile, /settings, /dashboard
    • Requires navigatorKey setup (covered in Quick Start)

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.