/ SDKs / Flutter
SDKs
Chat SDKs Flutter v3
Chat SDKs Flutter
Chat SDKs
Flutter
Version 3
Sendbird Chat SDK v3 for Flutter is no longer supported as a new version is released. Check out our latest Chat SDK v4

Configure notification preferences

Copy link

By registering or unregistering the current user's registration token to the Sendbird server as below, you can turn push notifications on or off in the user's client app. The registration and unregistration methods in the code below should be called after a user has established a connection with the Sendbird server.

// Enable Push Notification.
       await sdk.registerPushToken(
        type: PushTokenType.apns, // or fcm, none.
        token: 'ace8efc363725b65201c07220199a57df9f2cb2f',
      );
      // Disable Push Notifcation.
       await sdk.unregisterPushToken(
        type: PushTokenType.apns, // or fcm, none.
        token: 'ace8efc363725b65201c07220199a57df9f2cb2f',
      );

      // Unregister all Push Notification.
       await sdk.unregisterAllPushToken();

The setPushTriggerOption method allows users to configure when to receive notification messages as well as what types of messages trigger notification messages. The following are the available options.

PushTriggerOption

Copy link
OptionDescription

all

When disconnected from the Sendbird server, the current user receives notifications for all new messages including messages the user has been mentioned in.

mentionOnly

When disconnected from the Sendbird server, the current user only receives notifications for messages the user has been mentioned in.

off

The current user doesn't receive any notifications.

// Send notifications only when the current user is mentioned in messages.
await sdk.setPushTriggerOption(PushTriggerOption.mentionOnly);

The setMyPushTriggerOption method also allows users to configure the trigger for notification messages as well as turn notifications on or off for each channel. For the method, you can pass one of the following GroupChannelPushTriggerOption values to its parameter.

GroupChannelPushTriggerOption

Copy link
OptionDescription

global

The current user’s push notification trigger settings are automatically applied to the channel. This is the default setting.

all

When disconnected from the Sendbird server, the current user receives notifications for all new messages in the channel including messages the user has been mentioned in.

mentionOnly

When disconnected from the Sendbird server, the current user only receives notifications for messages in the channel the user has been mentioned in.

off

The current user doesn't receive any notifications in the channel.

// Apply the user's push notification setting to the channel.
channel.setMyPushTriggerOption(GroupChannelPushTriggerOption.mentionOnly);

If you want to routinely turn off push notification on the current user's client app according to a specified schedule, use our Do Not Disturb feature like the following.

Note: The Do Not Disturb feature can also be set for a user with our update push notification preferences API.

// The current user won't receive notification messages
// during the specified time of the day.
await sdk.setDoNotDisturb(
        enable: true,
        startHour: 12,
        startMin: 12,
        endHour: 12,
        endMin: 40,
        timezone: 'Asia/Seoul',
      );

To snooze notification messages for a specific period of time, use our snooze feature as below.

Note: The snooze notifications can also be set for a user through an API request to update push preferences.

// The current user won't receive notification messages
// during the specified period of time.
await sdk.setSnoozePeriod(
        enable: true,
        startDate: startDate,
        endDate: endDate,
      );