NotificationService class

Central service for managing notifications in Dreamic-based apps.

This service handles:

  • FCM (Firebase Cloud Messaging) message receiving and parsing
  • Local notification display
  • Notification permission management
  • Notification routing and deep linking
  • Badge count management
  • Rich notifications (images, actions)

Usage

Initialize the service early in your app startup:

await NotificationService().initialize(
  onNotificationTapped: (route, data) {
    if (route != null) {
      appRouter.navigateNamed(route, arguments: data);
    }
  },
);

Request permissions when appropriate:

final status = await NotificationService().requestPermissions();

Optional Feature

This service is completely optional. Apps that don't use notifications:

  • Don't need to import or initialize this service
  • Don't need notification entitlements
  • Won't have notification code in their build (tree-shaking)

Constructors

NotificationService()
Gets the singleton instance of NotificationService.
factory

Properties

badgeCountStream Stream<int>
Stream of badge count changes.
no setter
channelManager NotificationChannelManager?
Gets the channel manager for advanced channel operations.
no setter
hashCode int
The hash code for this object.
no setterinherited
isInitialized bool
Whether the service has been initialized.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
showNotificationsInForeground bool
Whether to show notifications when app is in foreground.
no setter

Methods

cancelAllNotifications() Future<void>
Cancels all notifications.
cancelNotification(int id) Future<void>
Cancels a specific notification by ID.
clearBadge() Future<void>
Clears the app icon badge.
dispose() Future<void>
Disposes of the service and cleans up resources.
getActiveNotifications() Future<List<ActiveNotification>>
Gets a list of currently active (displayed) notifications.
getBadgeCount() int
Gets the current badge count synchronously.
getPermissionDenialCount() Future<int>
Gets the number of times permissions have been denied.
getPermissionRequestCount() Future<int>
Gets the number of times permissions have been requested.
getPermissionStatus() Future<NotificationPermissionStatus>
Gets the current notification permission status.
initialize({NotificationActionCallback? onNotificationTapped, NotificationButtonActionCallback? onNotificationAction, ForegroundMessageCallback? onForegroundMessage, NotificationErrorCallback? onError, bool showNotificationsInForeground = true, int reminderIntervalDays = 30}) Future<void>
Initializes the notification service.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
openSystemSettings() Future<void>
Opens the system settings page for this app.
requestPermissions({bool provisional = false}) Future<NotificationPermissionStatus>
Requests notification permissions from the user.
shouldShowPeriodicReminder() Future<bool>
Checks if enough time has passed to show a permission reminder.
showNotification(NotificationPayload payload) Future<int>
Displays a local notification.
toString() String
A string representation of this object.
inherited
updateBadgeCount(int count) Future<void>
Updates the app icon badge count.
updateLastReminderDate() Future<void>
Updates the last reminder date to now.

Operators

operator ==(Object other) bool
The equality operator.
inherited