zonedSchedule method

Future<void> zonedSchedule(
  1. int id,
  2. String? title,
  3. String? body,
  4. TZDateTime scheduledDate,
  5. DarwinNotificationDetails? notificationDetails, {
  6. required UILocalNotificationDateInterpretation uiLocalNotificationDateInterpretation,
  7. String? payload,
  8. DateTimeComponents? matchDateTimeComponents,
})

Schedules a notification to be shown at the specified time in the future in a specific time zone.

Due to the limited support for time zones provided the UILocalNotification APIs used on devices using iOS versions older than 10, the uiLocalNotificationDateInterpretation is needed to control how scheduledDate is interpreted. See official docs at https://developer.apple.com/documentation/uikit/uilocalnotification/1616659-timezone for more details. Note that due to this limited support, it's likely that on older iOS devices, there will still be issues with daylight saving time except for when the time zone used in the scheduledDate matches the device's time zone and uiLocalNotificationDateInterpretation is set to UILocalNotificationDateInterpretation.wallClockTime.

Implementation

Future<void> zonedSchedule(
  int id,
  String? title,
  String? body,
  TZDateTime scheduledDate,
  DarwinNotificationDetails? notificationDetails, {
  required UILocalNotificationDateInterpretation
      uiLocalNotificationDateInterpretation,
  String? payload,
  DateTimeComponents? matchDateTimeComponents,
}) async {
  validateId(id);
  validateDateIsInTheFuture(scheduledDate, matchDateTimeComponents);
  ArgumentError.checkNotNull(uiLocalNotificationDateInterpretation,
      'uiLocalNotificationDateInterpretation');
  final Map<String, Object?> serializedPlatformSpecifics =
      notificationDetails?.toMap() ?? <String, Object>{};
  await _channel.invokeMethod(
      'zonedSchedule',
      <String, Object?>{
        'id': id,
        'title': title,
        'body': body,
        'platformSpecifics': serializedPlatformSpecifics,
        'payload': payload ?? '',
        'uiLocalNotificationDateInterpretation':
            uiLocalNotificationDateInterpretation.index,
      }
        ..addAll(scheduledDate.toMap())
        ..addAll(matchDateTimeComponents == null
            ? <String, Object>{}
            : <String, Object>{
                'matchDateTimeComponents': matchDateTimeComponents.index
              }));
}