scheduleRecurrentNotifications method
Future<int>
scheduleRecurrentNotifications({
- int? id,
- required String title,
- String? body,
- required RecurrentScheduledTrigger schedule,
override
Schedule 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 scheduled 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.
Implementation
@override
Future<int> scheduleRecurrentNotifications(
{int? id,
required String title,
String? body,
required RecurrentScheduledTrigger schedule}) async {
id ??= _random.nextInt(1000);
final time = tz.TZDateTime.from(
schedule.firstOccurrence, tz.getLocation(Settings().timezone));
DateTimeComponents recurrence = switch (schedule.type) {
RecurrentType.daily => DateTimeComponents.time,
RecurrentType.weekly => DateTimeComponents.dayOfWeekAndTime,
RecurrentType.monthly => DateTimeComponents.dayOfMonthAndTime,
};
await FlutterLocalNotificationsPlugin().zonedSchedule(
id,
title,
body,
time,
_platformChannelSpecifics,
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
matchDateTimeComponents: recurrence,
);
return id;
}