From 7520da6e13cd9fb8541bf451d913cb901c58dd46 Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Tue, 7 Mar 2023 09:45:54 +0100 Subject: [PATCH] Hotfix show todos --- lib/services/date_service.dart | 3 +- lib/services/notification_service.dart | 50 +++++++++++++------------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/lib/services/date_service.dart b/lib/services/date_service.dart index e4a9617..e96a02a 100644 --- a/lib/services/date_service.dart +++ b/lib/services/date_service.dart @@ -104,8 +104,7 @@ List createTZDateTimes( final DateTime date = DateTime(now.year, now.month, now.day, selectedHours, selectedMinutes, 0, 0, 0) .add(Duration(days: i)); - if (selectedDaysInt.contains(date.weekday) && - date.isAfter(DateTime.now())) { + if (selectedDaysInt.contains(date.weekday)) { tzDateTimes.add(TZDateTime.local(date.year, date.month, date.day, selectedHours, selectedMinutes, 0, 0, 0) .subtract(offset)); diff --git a/lib/services/notification_service.dart b/lib/services/notification_service.dart index 2de386c..ecafbd7 100644 --- a/lib/services/notification_service.dart +++ b/lib/services/notification_service.dart @@ -52,31 +52,33 @@ class NotificationService { Future setNotification( int id, String title, String body, TZDateTime tzDateTime) async { - await flutterLocalNotificationsPlugin.zonedSchedule( - id, - title, - body, - tzDateTime, //schedule the notification to show after 2 seconds. - const NotificationDetails( - // Android details - android: AndroidNotificationDetails('main_channel', 'Main Channel', - channelDescription: "ashwin", - importance: Importance.max, - priority: Priority.max), - // iOS details - iOS: DarwinNotificationDetails( - sound: 'default.wav', - presentAlert: true, - presentBadge: true, - presentSound: true, + if (tzDateTime.isAfter(DateTime.now())) { + await flutterLocalNotificationsPlugin.zonedSchedule( + id, + title, + body, + tzDateTime, //schedule the notification to show after 2 seconds. + const NotificationDetails( + // Android details + android: AndroidNotificationDetails('main_channel', 'Main Channel', + channelDescription: "ashwin", + importance: Importance.max, + priority: Priority.max), + // iOS details + iOS: DarwinNotificationDetails( + sound: 'default.wav', + presentAlert: true, + presentBadge: true, + presentSound: true, + ), ), - ), - // Type of time interpretation - uiLocalNotificationDateInterpretation: - UILocalNotificationDateInterpretation.absoluteTime, - androidAllowWhileIdle: - true, // To show notification even when the app is closed - ); + // Type of time interpretation + uiLocalNotificationDateInterpretation: + UILocalNotificationDateInterpretation.absoluteTime, + androidAllowWhileIdle: + true, // To show notification even when the app is closed + ); + } } }