Skip to main content
// Register push token (FCM on Android)
await CometChatNotifications.registerPushToken(
  PushPlatforms.FCM_FLUTTER_ANDROID,
  fcmToken: "YOUR_FCM_TOKEN",
  onSuccess: (response) => debugPrint("Token registered: $response"),
  onError: (e) => debugPrint("Error: ${e.message}"),
);

// Fetch notification preferences
NotificationPreferences? prefs = await CometChatNotifications.fetchPreferences(
  onSuccess: (prefs) => debugPrint("Preferences: $prefs"),
  onError: (e) => debugPrint("Error: ${e.message}"),
);

// Mute a conversation
await CometChatNotifications.muteConversations(
  [MutedConversation(id: "UID", type: MutedConversationType.ONE_ON_ONE)],
  onSuccess: (response) => debugPrint("Muted: $response"),
  onError: (e) => debugPrint("Error: ${e.message}"),
);
Key classes: CometChatNotifications, NotificationPreferences, MutedConversation, PushPlatforms
The CometChatNotifications class provides methods to manage push notification preferences, register/unregister push tokens, mute/unmute conversations, and manage timezone settings.

Register Push Token

Register a push notification token with CometChat for the current user. The token type depends on your platform and push provider.
await CometChatNotifications.registerPushToken(
  PushPlatforms.FCM_FLUTTER_ANDROID,
  fcmToken: "YOUR_FCM_TOKEN",
  providerId: "YOUR_PROVIDER_ID", // optional
  onSuccess: (String response) {
    debugPrint("Token registered: $response");
  },
  onError: (CometChatException e) {
    debugPrint("Error: ${e.code} - ${e.message}");
  },
);
ParameterTypeDescription
pushPlatformsPushPlatformsThe push platform to register for (required)
fcmTokenString?FCM token (required for FCM_FLUTTER_ANDROID and FCM_FLUTTER_IOS)
deviceTokenString?APNs device token (required for APNS_FLUTTER_DEVICE)
voipTokenString?APNs VoIP token (required for APNS_FLUTTER_VOIP)
providerIdString?Optional provider ID
onSuccessFunction(String)?Called with success response
onErrorFunction(CometChatException)?Called on error

PushPlatforms Enum

ValueDescription
FCM_FLUTTER_ANDROIDFirebase Cloud Messaging on Android
FCM_FLUTTER_IOSFirebase Cloud Messaging on iOS
APNS_FLUTTER_DEVICEApple Push Notification service (device)
APNS_FLUTTER_VOIPApple Push Notification service (VoIP)

Unregister Push Token

Remove the push notification token for the current user.
await CometChatNotifications.unregisterPushToken(
  onSuccess: (String response) {
    debugPrint("Token unregistered: $response");
  },
  onError: (CometChatException e) {
    debugPrint("Error: ${e.message}");
  },
);

Notification Preferences

Fetch Preferences

Retrieve the current notification preferences for the logged-in user.
NotificationPreferences? prefs = await CometChatNotifications.fetchPreferences(
  onSuccess: (NotificationPreferences prefs) {
    debugPrint("1:1 messages: ${prefs.oneOnOnePreferences?.messages}");
    debugPrint("Group messages: ${prefs.groupPreferences?.messages}");
    debugPrint("DND: ${prefs.mutePreferences?.dnd}");
  },
  onError: (CometChatException e) {
    debugPrint("Error: ${e.message}");
  },
);

Update Preferences

Update notification preferences for the logged-in user.
NotificationPreferences prefs = NotificationPreferences(
  usePrivacyTemplate: true,
  oneOnOnePreferences: OneOnOnePreferences(
    messages: MessagesOptions.SUBSCRIBE_TO_ALL,
    replies: RepliesOptions.SUBSCRIBE_TO_ALL,
    reactions: ReactionsOptions.SUBSCRIBE_TO_REACTIONS_ON_OWN_MESSAGES,
  ),
  groupPreferences: GroupPreferences(
    messages: MessagesOptions.SUBSCRIBE_TO_MENTIONS,
    replies: RepliesOptions.SUBSCRIBE_TO_MENTIONS,
    reactions: ReactionsOptions.DONT_SUBSCRIBE,
    memberJoined: MemberActionsOptions.SUBSCRIBE,
    memberLeft: MemberActionsOptions.DONT_SUBSCRIBE,
    memberKicked: MemberActionsOptions.SUBSCRIBE,
    memberBanned: MemberActionsOptions.SUBSCRIBE,
    memberUnbanned: MemberActionsOptions.DONT_SUBSCRIBE,
    memberScopeChanged: MemberActionsOptions.SUBSCRIBE,
    memberAdded: MemberActionsOptions.SUBSCRIBE,
  ),
  mutePreferences: MutePreferences(
    dnd: DNDOptions.DISABLED,
  ),
);

await CometChatNotifications.updatePreferences(prefs,
  onSuccess: (NotificationPreferences updated) {
    debugPrint("Preferences updated");
  },
  onError: (CometChatException e) {
    debugPrint("Error: ${e.message}");
  },
);

Reset Preferences

Reset notification preferences to their default values.
await CometChatNotifications.resetPreferences(
  onSuccess: (NotificationPreferences prefs) {
    debugPrint("Preferences reset to defaults");
  },
  onError: (CometChatException e) {
    debugPrint("Error: ${e.message}");
  },
);

Mute & Unmute Conversations

Get Muted Conversations

Retrieve all conversations muted by the logged-in user.
List<MutedConversation> muted = await CometChatNotifications.getMutedConversations(
  onSuccess: (List<MutedConversation> conversations) {
    for (var conv in conversations) {
      debugPrint("Muted: ${conv.id} (${conv.type}) until ${conv.until}");
    }
  },
  onError: (CometChatException e) {
    debugPrint("Error: ${e.message}");
  },
);

Mute Conversations

Mute one or more conversations.
await CometChatNotifications.muteConversations(
  [
    MutedConversation(
      id: "user_uid",
      type: MutedConversationType.ONE_ON_ONE,
      until: 1700000000, // Unix timestamp, or null for indefinite
    ),
    MutedConversation(
      id: "group_guid",
      type: MutedConversationType.GROUP,
    ),
  ],
  onSuccess: (String response) {
    debugPrint("Conversations muted: $response");
  },
  onError: (CometChatException e) {
    debugPrint("Error: ${e.message}");
  },
);

Unmute Conversations

Unmute one or more conversations.
await CometChatNotifications.unmuteConversations(
  [
    UnmutedConversation(
      id: "user_uid",
      type: MutedConversationType.ONE_ON_ONE,
    ),
  ],
  onSuccess: (String response) {
    debugPrint("Conversations unmuted: $response");
  },
  onError: (CometChatException e) {
    debugPrint("Error: ${e.message}");
  },
);

Timezone

Update Timezone

Update the timezone preference for the logged-in user. This affects DND schedule evaluation.
await CometChatNotifications.updateTimezone("America/New_York",
  onSuccess: (String response) {
    debugPrint("Timezone updated: $response");
  },
  onError: (CometChatException e) {
    debugPrint("Error: ${e.message}");
  },
);

Get Timezone

Retrieve the current timezone preference.
String? timezone = await CometChatNotifications.getTimezone(
  onSuccess: (String tz) {
    debugPrint("Current timezone: $tz");
  },
  onError: (CometChatException e) {
    debugPrint("Error: ${e.message}");
  },
);

Models Reference

NotificationPreferences

PropertyTypeDescription
usePrivacyTemplatebool?Whether to use privacy templates for notifications
oneOnOnePreferencesOneOnOnePreferences?Preferences for 1:1 conversations
groupPreferencesGroupPreferences?Preferences for group conversations
mutePreferencesMutePreferences?Do Not Disturb and schedule settings

OneOnOnePreferences

PropertyTypeDescription
messagesMessagesOptions?Notification preference for messages
repliesRepliesOptions?Notification preference for replies
reactionsReactionsOptions?Notification preference for reactions

GroupPreferences

PropertyTypeDescription
messagesMessagesOptions?Notification preference for group messages
repliesRepliesOptions?Notification preference for group replies
reactionsReactionsOptions?Notification preference for group reactions
memberJoinedMemberActionsOptions?Notify when a member joins
memberLeftMemberActionsOptions?Notify when a member leaves
memberAddedMemberActionsOptions?Notify when a member is added
memberKickedMemberActionsOptions?Notify when a member is kicked
memberBannedMemberActionsOptions?Notify when a member is banned
memberUnbannedMemberActionsOptions?Notify when a member is unbanned
memberScopeChangedMemberActionsOptions?Notify when a member’s scope changes

MutePreferences

PropertyTypeDescription
dndDNDOptions?Do Not Disturb mode
scheduleMap<DayOfWeek, DaySchedule>?Per-day mute schedule

DaySchedule

PropertyTypeDescription
fromint?Start hour (0–23)
toint?End hour (0–23)
dndbool?Whether DND is active for this day

MutedConversation

PropertyTypeDescription
idString?UID (for 1:1) or GUID (for group)
typeMutedConversationType?Conversation type
untilnum?Unix timestamp when mute expires (null = indefinite)

UnmutedConversation

PropertyTypeDescription
idString?UID (for 1:1) or GUID (for group)
typeMutedConversationType?Conversation type

Enums Reference

MessagesOptions

ValueIntDescription
DONT_SUBSCRIBE1Don’t receive message notifications
SUBSCRIBE_TO_ALL2Receive notifications for all messages
SUBSCRIBE_TO_MENTIONS3Only receive notifications for messages that mention you

RepliesOptions

ValueIntDescription
DONT_SUBSCRIBE1Don’t receive reply notifications
SUBSCRIBE_TO_ALL2Receive notifications for all replies
SUBSCRIBE_TO_MENTIONS3Only receive notifications for replies that mention you

ReactionsOptions

ValueIntDescription
DONT_SUBSCRIBE1Don’t receive reaction notifications
SUBSCRIBE_TO_REACTIONS_ON_OWN_MESSAGES2Receive notifications for reactions on your messages
SUBSCRIBE_TO_REACTIONS_ON_ALL_MESSAGES3Receive notifications for reactions on all messages

MemberActionsOptions

ValueIntDescription
DONT_SUBSCRIBE1Don’t receive member action notifications
SUBSCRIBE2Receive member action notifications

DNDOptions

ValueIntDescription
DISABLED1Do Not Disturb is disabled
ENABLED2Do Not Disturb is enabled

MutedConversationType

ValueStringDescription
ONE_ON_ONE"oneOnOne"1:1 conversation
GROUP"group"Group conversation

DayOfWeek

ValueString
MONDAY"monday"
TUESDAY"tuesday"
WEDNESDAY"wednesday"
THURSDAY"thursday"
FRIDAY"friday"
SATURDAY"saturday"
SUNDAY"sunday"

Next Steps

Setup SDK

Installation and initialization guide

Connection Status

Monitor SDK connection state changes

Best Practices

Recommended patterns and practices

Error Codes

Complete SDK error code reference