From 6d7b7865d9487168851865f7ead4a1cf2f6e8439 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Thu, 15 Feb 2024 02:12:43 +0530 Subject: [PATCH] notifications fixed --- lib/services/local_notification.dart | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/services/local_notification.dart b/lib/services/local_notification.dart index d22cd89..e0134ff 100644 --- a/lib/services/local_notification.dart +++ b/lib/services/local_notification.dart @@ -48,13 +48,13 @@ class LocalNotification { } Future scheduleNotification(Beacon beacon) async { - var scheduledDate = await tz.TZDateTime.from( + var scheduledDate1 = await tz.TZDateTime.from( DateTime.fromMillisecondsSinceEpoch(beacon.startsAt!), tz.local); await flutterLocalNotificationsPlugin.zonedSchedule( beacon.id.hashCode, 'Hike ' + beacon.title! + ' has started', 'Click here to join!', - scheduledDate, + scheduledDate1, NotificationDetails( android: AndroidNotificationDetails( 'channel id', @@ -78,15 +78,21 @@ class LocalNotification { ); // We have to check if the hike is after 1 hour or not - scheduledDate = await tz.TZDateTime.from( + var scheduledDate2 = await tz.TZDateTime.from( DateTime.fromMillisecondsSinceEpoch(beacon.startsAt!), tz.local, ).subtract(Duration(hours: 1)); + + if (!scheduledDate2.isAfter(tz.TZDateTime.from( + DateTime.fromMillisecondsSinceEpoch(beacon.startsAt!), tz.local))) { + return; + } + await flutterLocalNotificationsPlugin.zonedSchedule( beacon.id.hashCode, 'Reminder: ' + beacon.title! + ' will start in an hour', 'Get Ready!', - scheduledDate, + scheduledDate2, NotificationDetails( android: AndroidNotificationDetails( 'channel id',