From cd597066c2fdb8dffb0e890db46c4bc3a8b4b91e Mon Sep 17 00:00:00 2001 From: vkprogrammer-001 Date: Wed, 7 Feb 2024 16:31:49 +0530 Subject: [PATCH 1/6] Fix for Future Date Validation in Beacon Project --- lib/services/local_notification.dart | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/services/local_notification.dart b/lib/services/local_notification.dart index 623ad5ae..337c9604 100644 --- a/lib/services/local_notification.dart +++ b/lib/services/local_notification.dart @@ -46,6 +46,13 @@ class LocalNotification { } Future scheduleNotification(Beacon beacon) async { + DateTime now = DateTime.now(); + DateTime beaconStart = DateTime.fromMillisecondsSinceEpoch(beacon.startsAt); + + if (beaconStart.difference(now).inMinutes < 0) { + print('Beacon start time must be in the future'); + return; + } await flutterLocalNotificationsPlugin.zonedSchedule( beacon.id.hashCode, 'Hike ' + beacon.title + ' has started', From c0b04d0d5dac79d49008997cd4a2ba32d06d63ce Mon Sep 17 00:00:00 2001 From: vkprogrammer-001 Date: Wed, 7 Feb 2024 17:10:30 +0530 Subject: [PATCH 2/6] Fix for Future Date Validation in Beacon Project --- lib/services/local_notification.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/services/local_notification.dart b/lib/services/local_notification.dart index 337c9604..5748665b 100644 --- a/lib/services/local_notification.dart +++ b/lib/services/local_notification.dart @@ -49,8 +49,8 @@ class LocalNotification { DateTime now = DateTime.now(); DateTime beaconStart = DateTime.fromMillisecondsSinceEpoch(beacon.startsAt); - if (beaconStart.difference(now).inMinutes < 0) { - print('Beacon start time must be in the future'); + if (beaconStart.difference(now).inHours < 1) { + print('Beacon start time must be at least an hour from now'); return; } await flutterLocalNotificationsPlugin.zonedSchedule( From fdcac65046a806d1232a3db89ad455d7fa606ac0 Mon Sep 17 00:00:00 2001 From: vkprogrammer-001 Date: Thu, 15 Feb 2024 15:45:40 +0530 Subject: [PATCH 3/6] nstance of 'TZDateTime' --- lib/services/local_notification.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/services/local_notification.dart b/lib/services/local_notification.dart index fec67aae..f7871a30 100644 --- a/lib/services/local_notification.dart +++ b/lib/services/local_notification.dart @@ -84,7 +84,8 @@ class LocalNotification { beacon.id.hashCode, 'Reminder: ' + beacon.title! + ' will start in an hour', 'Get Ready!', - scheduledDate, + tz.TZDateTime.from( + DateTime.fromMillisecondsSinceEpoch(beacon.startsAt), tz.local), NotificationDetails( android: AndroidNotificationDetails( 'channel id', From af0889d3ea7c5d9dd3a7a676dfe5b03250e9563b Mon Sep 17 00:00:00 2001 From: vkprogrammer-001 Date: Thu, 15 Feb 2024 16:03:58 +0530 Subject: [PATCH 4/6] [fix] instance of 'TZDateTime' --- 0001-fix-nstance-of-TZDateTime.patch | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 0001-fix-nstance-of-TZDateTime.patch diff --git a/0001-fix-nstance-of-TZDateTime.patch b/0001-fix-nstance-of-TZDateTime.patch new file mode 100644 index 00000000..f1ac71e2 --- /dev/null +++ b/0001-fix-nstance-of-TZDateTime.patch @@ -0,0 +1,26 @@ +From 8e637b73c29e69f875e366a3973cbc52fe5eb4d7 Mon Sep 17 00:00:00 2001 +From: vkprogrammer-001 +Date: Thu, 15 Feb 2024 15:45:40 +0530 +Subject: [PATCH] [fix] nstance of 'TZDateTime' + +--- + lib/services/local_notification.dart | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/lib/services/local_notification.dart b/lib/services/local_notification.dart +index fec67aa..f7871a3 100644 +--- a/lib/services/local_notification.dart ++++ b/lib/services/local_notification.dart +@@ -84,7 +84,8 @@ class LocalNotification { + beacon.id.hashCode, + 'Reminder: ' + beacon.title! + ' will start in an hour', + 'Get Ready!', +- scheduledDate, ++ tz.TZDateTime.from( ++ DateTime.fromMillisecondsSinceEpoch(beacon.startsAt), tz.local), + NotificationDetails( + android: AndroidNotificationDetails( + 'channel id', +-- +2.39.3 (Apple Git-145) + From c4c6db18dfe4b5e7ae909db533caa6cfc19c5d78 Mon Sep 17 00:00:00 2001 From: vipin kumar <143318563+vkprogrammer-001@users.noreply.github.com> Date: Thu, 15 Feb 2024 16:07:24 +0530 Subject: [PATCH 5/6] Delete 0001-fix-nstance-of-TZDateTime.patch --- 0001-fix-nstance-of-TZDateTime.patch | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 0001-fix-nstance-of-TZDateTime.patch diff --git a/0001-fix-nstance-of-TZDateTime.patch b/0001-fix-nstance-of-TZDateTime.patch deleted file mode 100644 index f1ac71e2..00000000 --- a/0001-fix-nstance-of-TZDateTime.patch +++ /dev/null @@ -1,26 +0,0 @@ -From 8e637b73c29e69f875e366a3973cbc52fe5eb4d7 Mon Sep 17 00:00:00 2001 -From: vkprogrammer-001 -Date: Thu, 15 Feb 2024 15:45:40 +0530 -Subject: [PATCH] [fix] nstance of 'TZDateTime' - ---- - lib/services/local_notification.dart | 3 ++- - 1 file changed, 2 insertions(+), 1 deletion(-) - -diff --git a/lib/services/local_notification.dart b/lib/services/local_notification.dart -index fec67aa..f7871a3 100644 ---- a/lib/services/local_notification.dart -+++ b/lib/services/local_notification.dart -@@ -84,7 +84,8 @@ class LocalNotification { - beacon.id.hashCode, - 'Reminder: ' + beacon.title! + ' will start in an hour', - 'Get Ready!', -- scheduledDate, -+ tz.TZDateTime.from( -+ DateTime.fromMillisecondsSinceEpoch(beacon.startsAt), tz.local), - NotificationDetails( - android: AndroidNotificationDetails( - 'channel id', --- -2.39.3 (Apple Git-145) - From 46bcc1ed91ee556bda0c888852881c1624ba1dae Mon Sep 17 00:00:00 2001 From: vkprogrammer-001 Date: Thu, 15 Feb 2024 17:06:48 +0530 Subject: [PATCH 6/6] [fix] Exception: Invalid argument --- lib/services/local_notification.dart | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/services/local_notification.dart b/lib/services/local_notification.dart index f7871a30..bf2babac 100644 --- a/lib/services/local_notification.dart +++ b/lib/services/local_notification.dart @@ -48,6 +48,8 @@ class LocalNotification { } Future scheduleNotification(Beacon beacon) async { + var scheduledDate = await tz.TZDateTime.from( + DateTime.fromMillisecondsSinceEpoch(beacon.startsAt!), tz.local); await flutterLocalNotificationsPlugin.zonedSchedule( beacon.id.hashCode, 'Hike ' + beacon.title! + ' has started', @@ -77,15 +79,12 @@ class LocalNotification { // We have to check if the hike is after 1 hour or not scheduledDate = await tz.TZDateTime.from( - DateTime.fromMillisecondsSinceEpoch(beacon.startsAt!), - tz.local, - ).subtract(Duration(hours: 1)); + DateTime.fromMillisecondsSinceEpoch(beacon.startsAt!),tz.local); await flutterLocalNotificationsPlugin.zonedSchedule( beacon.id.hashCode, 'Reminder: ' + beacon.title! + ' will start in an hour', 'Get Ready!', - tz.TZDateTime.from( - DateTime.fromMillisecondsSinceEpoch(beacon.startsAt), tz.local), + scheduledDate, NotificationDetails( android: AndroidNotificationDetails( 'channel id', @@ -108,4 +107,4 @@ class LocalNotification { payload: beacon.id, ); } -} +} \ No newline at end of file