zonedSchedule method
- int id,
- String? title,
- String? body,
- TZDateTime scheduledDate,
- NotificationDetails notificationDetails, {
- required UILocalNotificationDateInterpretation uiLocalNotificationDateInterpretation,
- required bool androidAllowWhileIdle,
- String? payload,
- DateTimeComponents? matchDateTimeComponents,
Schedules a notification to be shown at the specified date and time relative to a specific time zone.
Note that to get the appropriate representation of the time at the native level (i.e. Android/iOS), the plugin needs to pass the time over the platform channel in yyyy-mm-dd hh:mm:ss format. Therefore, the precision is at the best to the second.
The androidAllowWhileIdle
parameter determines if the notification
should still be shown at the exact time even when the device is in a
low-power idle mode.
The uiLocalNotificationDateInterpretation
is for iOS versions older
than 10 as the APIs have limited support for time zones. With this
parameter, it is used to determine if the scheduled date should be
interpreted as absolute time or wall clock time.
If a value for matchDateTimeComponents
parameter is given, this tells
the plugin to schedule a recurring notification that matches the
specified date and time components. Specifying
DateTimeComponents.time would result in a daily notification at the
same time whilst DateTimeComponents.dayOfWeekAndTime would result
in a weekly notification that occurs on the same day of the week and time.
This is similar to how recurring notifications on iOS/macOS work using a
calendar trigger. Note that when a value is given, the scheduledDate
may not represent the first time the notification will be shown. An
example would be if the date and time is currently 2020-10-19 11:00
(i.e. 19th October 2020 11:00AM) and scheduledDate
is 2020-10-21
10:00 and the value of the matchDateTimeComponents
is
DateTimeComponents.time, then the next time a notification will
appear is 2020-10-20 10:00.
Implementation
Future<void> zonedSchedule(
int id,
String? title,
String? body,
TZDateTime scheduledDate,
NotificationDetails notificationDetails, {
required UILocalNotificationDateInterpretation
uiLocalNotificationDateInterpretation,
required bool androidAllowWhileIdle,
String? payload,
DateTimeComponents? matchDateTimeComponents,
}) async {
if (kIsWeb) {
return;
}
if (defaultTargetPlatform == TargetPlatform.android) {
await resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()!
.zonedSchedule(
id, title, body, scheduledDate, notificationDetails.android,
payload: payload,
androidAllowWhileIdle: androidAllowWhileIdle,
matchDateTimeComponents: matchDateTimeComponents);
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
await resolvePlatformSpecificImplementation<
IOSFlutterLocalNotificationsPlugin>()
?.zonedSchedule(
id, title, body, scheduledDate, notificationDetails.iOS,
uiLocalNotificationDateInterpretation:
uiLocalNotificationDateInterpretation,
payload: payload,
matchDateTimeComponents: matchDateTimeComponents);
} else if (defaultTargetPlatform == TargetPlatform.macOS) {
await resolvePlatformSpecificImplementation<
MacOSFlutterLocalNotificationsPlugin>()
?.zonedSchedule(
id, title, body, scheduledDate, notificationDetails.macOS,
payload: payload,
matchDateTimeComponents: matchDateTimeComponents);
}
}