From 87f161b4854843291a06bc5f5cfb1942b492a27c Mon Sep 17 00:00:00 2001 From: BadgerHobbs Date: Sat, 21 Dec 2024 13:48:58 +0000 Subject: [PATCH] Added `repeatStartTime` property to periodic notifications. --- .../flutter_local_notifications_plugin.dart | 24 ++++++++++++++----- .../platform_flutter_local_notifications.dart | 18 +++++++++----- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/flutter_local_notifications/lib/src/flutter_local_notifications_plugin.dart b/flutter_local_notifications/lib/src/flutter_local_notifications_plugin.dart index bc866a073..9931d2910 100644 --- a/flutter_local_notifications/lib/src/flutter_local_notifications_plugin.dart +++ b/flutter_local_notifications/lib/src/flutter_local_notifications_plugin.dart @@ -399,6 +399,7 @@ class FlutterLocalNotificationsPlugin { NotificationDetails notificationDetails, { required AndroidScheduleMode androidScheduleMode, String? payload, + int? repeatStartTime, }) async { if (kIsWeb) { return; @@ -409,17 +410,22 @@ class FlutterLocalNotificationsPlugin { ?.periodicallyShow(id, title, body, repeatInterval, notificationDetails: notificationDetails.android, payload: payload, - scheduleMode: androidScheduleMode); + scheduleMode: androidScheduleMode, + repeatStartTime: repeatStartTime); } else if (defaultTargetPlatform == TargetPlatform.iOS) { await resolvePlatformSpecificImplementation< IOSFlutterLocalNotificationsPlugin>() ?.periodicallyShow(id, title, body, repeatInterval, - notificationDetails: notificationDetails.iOS, payload: payload); + notificationDetails: notificationDetails.iOS, + payload: payload, + repeatStartTime: repeatStartTime); } else if (defaultTargetPlatform == TargetPlatform.macOS) { await resolvePlatformSpecificImplementation< MacOSFlutterLocalNotificationsPlugin>() ?.periodicallyShow(id, title, body, repeatInterval, - notificationDetails: notificationDetails.macOS, payload: payload); + notificationDetails: notificationDetails.macOS, + payload: payload, + repeatStartTime: repeatStartTime); } else if (defaultTargetPlatform == TargetPlatform.windows) { throw UnsupportedError('Notifications do not repeat on Windows'); } else { @@ -446,6 +452,7 @@ class FlutterLocalNotificationsPlugin { NotificationDetails notificationDetails, { AndroidScheduleMode androidScheduleMode = AndroidScheduleMode.exact, String? payload, + int? repeatStartTime, }) async { if (kIsWeb) { return; @@ -457,19 +464,24 @@ class FlutterLocalNotificationsPlugin { id, title, body, repeatDurationInterval, notificationDetails: notificationDetails.android, payload: payload, - scheduleMode: androidScheduleMode); + scheduleMode: androidScheduleMode, + repeatStartTime: repeatStartTime); } else if (defaultTargetPlatform == TargetPlatform.iOS) { await resolvePlatformSpecificImplementation< IOSFlutterLocalNotificationsPlugin>() ?.periodicallyShowWithDuration( id, title, body, repeatDurationInterval, - notificationDetails: notificationDetails.iOS, payload: payload); + notificationDetails: notificationDetails.iOS, + payload: payload, + repeatStartTime: repeatStartTime); } else if (defaultTargetPlatform == TargetPlatform.macOS) { await resolvePlatformSpecificImplementation< MacOSFlutterLocalNotificationsPlugin>() ?.periodicallyShowWithDuration( id, title, body, repeatDurationInterval, - notificationDetails: notificationDetails.macOS, payload: payload); + notificationDetails: notificationDetails.macOS, + payload: payload, + repeatStartTime: repeatStartTime); } else { await FlutterLocalNotificationsPlatform.instance .periodicallyShowWithDuration( diff --git a/flutter_local_notifications/lib/src/platform_flutter_local_notifications.dart b/flutter_local_notifications/lib/src/platform_flutter_local_notifications.dart index 7781f4f21..80cac4001 100644 --- a/flutter_local_notifications/lib/src/platform_flutter_local_notifications.dart +++ b/flutter_local_notifications/lib/src/platform_flutter_local_notifications.dart @@ -354,13 +354,14 @@ class AndroidFlutterLocalNotificationsPlugin AndroidNotificationDetails? notificationDetails, String? payload, AndroidScheduleMode scheduleMode = AndroidScheduleMode.exact, + int? repeatStartTime, }) async { validateId(id); await _channel.invokeMethod('periodicallyShow', { 'id': id, 'title': title, 'body': body, - 'calledAt': clock.now().millisecondsSinceEpoch, + 'calledAt': repeatStartTime ?? clock.now().millisecondsSinceEpoch, 'repeatInterval': repeatInterval.index, 'platformSpecifics': _buildPlatformSpecifics(notificationDetails, scheduleMode), @@ -377,6 +378,7 @@ class AndroidFlutterLocalNotificationsPlugin AndroidNotificationDetails? notificationDetails, String? payload, AndroidScheduleMode scheduleMode = AndroidScheduleMode.exact, + int? repeatStartTime, }) async { validateId(id); validateRepeatDurationInterval(repeatDurationInterval); @@ -385,7 +387,7 @@ class AndroidFlutterLocalNotificationsPlugin 'id': id, 'title': title, 'body': body, - 'calledAt': clock.now().millisecondsSinceEpoch, + 'calledAt': repeatStartTime ?? clock.now().millisecondsSinceEpoch, 'repeatIntervalMilliseconds': repeatDurationInterval.inMilliseconds, 'platformSpecifics': _buildPlatformSpecifics(notificationDetails, scheduleMode), @@ -754,13 +756,14 @@ class IOSFlutterLocalNotificationsPlugin RepeatInterval repeatInterval, { DarwinNotificationDetails? notificationDetails, String? payload, + int? repeatStartTime, }) async { validateId(id); await _channel.invokeMethod('periodicallyShow', { 'id': id, 'title': title, 'body': body, - 'calledAt': clock.now().millisecondsSinceEpoch, + 'calledAt': repeatStartTime ?? clock.now().millisecondsSinceEpoch, 'repeatInterval': repeatInterval.index, 'platformSpecifics': notificationDetails?.toMap(), 'payload': payload ?? '' @@ -775,6 +778,7 @@ class IOSFlutterLocalNotificationsPlugin Duration repeatDurationInterval, { DarwinNotificationDetails? notificationDetails, String? payload, + int? repeatStartTime, }) async { validateId(id); validateRepeatDurationInterval(repeatDurationInterval); @@ -783,7 +787,7 @@ class IOSFlutterLocalNotificationsPlugin 'id': id, 'title': title, 'body': body, - 'calledAt': clock.now().millisecondsSinceEpoch, + 'calledAt': repeatStartTime ?? clock.now().millisecondsSinceEpoch, 'repeatIntervalMilliseconds': repeatDurationInterval.inMilliseconds, 'platformSpecifics': notificationDetails?.toMap(), 'payload': payload ?? '' @@ -948,13 +952,14 @@ class MacOSFlutterLocalNotificationsPlugin RepeatInterval repeatInterval, { DarwinNotificationDetails? notificationDetails, String? payload, + int? repeatStartTime, }) async { validateId(id); await _channel.invokeMethod('periodicallyShow', { 'id': id, 'title': title, 'body': body, - 'calledAt': clock.now().millisecondsSinceEpoch, + 'calledAt': repeatStartTime ?? clock.now().millisecondsSinceEpoch, 'repeatInterval': repeatInterval.index, 'platformSpecifics': notificationDetails?.toMap(), 'payload': payload ?? '' @@ -969,6 +974,7 @@ class MacOSFlutterLocalNotificationsPlugin Duration repeatDurationInterval, { DarwinNotificationDetails? notificationDetails, String? payload, + int? repeatStartTime, }) async { validateId(id); validateRepeatDurationInterval(repeatDurationInterval); @@ -977,7 +983,7 @@ class MacOSFlutterLocalNotificationsPlugin 'id': id, 'title': title, 'body': body, - 'calledAt': clock.now().millisecondsSinceEpoch, + 'calledAt': repeatStartTime ?? clock.now().millisecondsSinceEpoch, 'repeatIntervalMilliseconds': repeatDurationInterval.inMilliseconds, 'platformSpecifics': notificationDetails?.toMap(), 'payload': payload ?? ''