Skip to content

FlutterLocalNotificationManager

A NotificationManager that shows local notifications using the flutter_local_notifications plugin.

The default notification manager of SmartPhoneClientManager. It shows notifications for UserTasks (see AppTaskController) and app-specific notifications. A singleton, accessed as FlutterLocalNotificationManager().

Key points:

  • configure must be called before use. It registers the notification icon and asks for notification permission on Android.
  • Uses exact alarms on Android when SCHEDULE_EXACT_ALARM is granted, otherwise inexact alarms.
  • Task notifications use the hash code of UserTask.id as notification id.
  • Taps on task notifications are sent to AppTaskController.onNotification. Other taps are emitted on notificationTaps.

On iOS, remember to edit the AppDelegate.swift file. See https://pub.dev/packages/flutter_local_notifications#general-setup

On Android, update the AndroidManifest.xml and gradle.build files to add the necessary permissions and service declaration for notifications. Also add an ic_launcher.png square png picture in the <<application_name>>/android/app/src/main/res/drawable/ folder. You can use the default app icon, just make a copy in the drawable folder.

Implemented types

Constructors

FlutterLocalNotificationManager

FlutterLocalNotificationManager()

Properties

notificationTaps

Stream<String> get notificationTaps
override

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

pendingNotificationRequestsCount

Future<int> get pendingNotificationRequestsCount
override

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
)
override

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

cancelTaskNotification

Future<void> cancelTaskNotification(
  1. UserTask task
)
override

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

configure

Future<void> configure()
override

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,
})
override

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
)
override

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,
})
override

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,
})
override

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
)
override

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