Skip to content

NotificationManager

Manages user notifications, including creating, scheduling, and canceling notifications.

This manager serves two purposes:

  1. It is used by the AppTaskController to create notification about UserTasks (which are created based on AppTask in the StudyProtocol). This happens automatically, if the app task is configured to send a notification.

  2. It can be used by the app to create, schedule, and cancel app-specific notifications. This is done using the createNotification, scheduleNotification, and scheduleRecurrentNotifications methods, which creates an immediate, scheduled, or recurrent notification, respectively.

The SmartPhoneClientManager uses FlutterLocalNotificationManager, available as SmartPhoneClientManager.notificationManager.

Implementers

Constructors

NotificationManager

NotificationManager()

Constants

CHANNEL_DESCRIPTION

String const CHANNEL_DESCRIPTION

The description of the notification channel as shown in the Settings on Android phones.

CHANNEL_ID

String const CHANNEL_ID

The id of the notification channel for immediate notifications.

CHANNEL_NAME

String const CHANNEL_NAME

The name of the notification channel as shown in the Settings on Android phones.

SCHEDULED_CHANNEL_DESCRIPTION

String const SCHEDULED_CHANNEL_DESCRIPTION

The description of the notification channel as shown in the Settings on Android phones.

SCHEDULED_CHANNEL_ID

String const SCHEDULED_CHANNEL_ID

The id of the notification channel for scheduled notifications.

SCHEDULED_CHANNEL_NAME

String const SCHEDULED_CHANNEL_NAME

The name of the notification channel as shown in the Settings on Android phones.

Properties

notificationTaps

Stream<String> get notificationTaps

The payloads of tapped notifications created with createNotification. Taps on task notifications are handled by the AppTaskController.

pendingNotificationLimit

int pendingNotificationLimit
final

The maximum number of pending scheduled notifications: 64 on iOS and 500 on Android.

pendingNotificationRequestsCount

Future<int> get pendingNotificationRequestsCount

The number of pending notifications.

Note that on iOS there is a limit of 64 pending notifications. See https://pub.dev/packages/flutter_local_notifications#ios-pending-notifications-limit

Methods

cancelNotification

Future<void> cancelNotification(
  1. int id
)

Cancels (i.e., removes) the notification with id.

cancelTaskNotification

Future<void> cancelTaskNotification(
  1. UserTask task
)

Cancels (i.e., removes) the notification for the task.

configure

Future<void> configure()

Configures and sets up the notification manager.

Also tries to get permission to send notifications.

createNotification

Future<int> createNotification({
  1. int? id,
  2. required String title,
  3. String? body,
  4. String? payload,
})

Creates an immediate notification with id, title, and body. If the id is not specified, a random id will be generated. When tapped, payload is emitted on notificationTaps.

Returns the id of the notification created.

createTaskNotification

Future<void> createTaskNotification(
  1. UserTask task
)

Creates an immediate notification for a task.

scheduleNotification

Future<int> scheduleNotification({
  1. int? id,
  2. required String title,
  3. String? body,
  4. required DateTime schedule,
})

Schedules a notification with id, title, and body at the schedule time. If the id is not specified, a random id will be generated.

Returns the id of the notification created.

scheduleRecurrentNotifications

Future<int> scheduleRecurrentNotifications({
  1. int? id,
  2. required String title,
  3. String? body,
  4. required RecurrentScheduledTrigger schedule,
})

Schedules recurrent notifications with id, title, and body at the schedule time.

Allows for daily, weekly, and monthly recurrence according to the schedule.

Note that RecurrentScheduledTrigger.separationCount and RecurrentScheduledTrigger.end are not used, i.e. days / weeks / months cannot be skipped in the schedule and the notifications keeps recurring indefinitely. If you want to stop a recurrent notification schedule, use the cancelNotification method.

If the id is not specified, a random id will be generated.

Returns the id of the notification created.

scheduleTaskNotification

Future<void> scheduleTaskNotification(
  1. UserTask task
)

Schedules a notification for a task at its UserTask.triggerTime.