Fixed Timezone Bug

main
Kai Mannweiler 2023-02-26 12:44:01 +01:00
parent a975a44f4e
commit df38c25bc4
2 changed files with 6 additions and 9 deletions

View File

@ -38,7 +38,9 @@ Future<List<TZDateTime>> getDatesforSleep() async {
List<TZDateTime> createTZDateTimes( List<TZDateTime> createTZDateTimes(
List<String>? selectedDays, int? selectedHours, int? selectedMinutes) { List<String>? selectedDays, int? selectedHours, int? selectedMinutes) {
List<TZDateTime> tzDateTimes = []; final List<TZDateTime> tzDateTimes = [];
final DateTime now = DateTime.now();
final Duration offset = now.timeZoneOffset;
if (selectedDays == null || if (selectedDays == null ||
selectedHours == null || selectedHours == null ||
selectedMinutes == null) { selectedMinutes == null) {
@ -47,14 +49,14 @@ List<TZDateTime> createTZDateTimes(
final Iterable<int?> selectedDaysInt = final Iterable<int?> selectedDaysInt =
selectedDays.map((day) => weekDays[day]); selectedDays.map((day) => weekDays[day]);
for (int i = 0; i < trainingTime; i++) { for (int i = 0; i < trainingTime; i++) {
final DateTime now = DateTime.now();
final DateTime date = DateTime(now.year, now.month, now.day, selectedHours, final DateTime date = DateTime(now.year, now.month, now.day, selectedHours,
selectedMinutes, 0, 0, 0) selectedMinutes, 0, 0, 0)
.add(Duration(days: i)); .add(Duration(days: i));
if (selectedDaysInt.contains(date.weekday) && if (selectedDaysInt.contains(date.weekday) &&
date.isAfter(DateTime.now())) { date.isAfter(DateTime.now())) {
tzDateTimes.add(TZDateTime.local(date.year, date.month, date.day, tzDateTimes.add(TZDateTime.local(date.year, date.month, date.day,
selectedHours, selectedMinutes, 0, 0, 0)); selectedHours, selectedMinutes, 0, 0, 0)
.subtract(offset));
} }
} }
return tzDateTimes; return tzDateTimes;

View File

@ -33,9 +33,7 @@ class NotificationService {
android: initializationSettingsAndroid, android: initializationSettingsAndroid,
iOS: initializationSettingsIOS); iOS: initializationSettingsIOS);
// the initialization settings are initialized after they are setted // the initialization settings are initialized after they are setted
bool? initialized = await flutterLocalNotificationsPlugin await flutterLocalNotificationsPlugin.initialize(initializationSettings);
.initialize(initializationSettings);
print(initialized);
} }
Future<void> showNotification() async { Future<void> showNotification() async {
@ -67,13 +65,10 @@ class NotificationService {
int index = 0; int index = 0;
for (var date in moodDates) { for (var date in moodDates) {
setNotification(index, "Mood", "Evaluate your mood", date); setNotification(index, "Mood", "Evaluate your mood", date);
print("mood");
index++; index++;
} }
for (var date in sleepDates) { for (var date in sleepDates) {
setNotification(index, "Sleep", "Evaluate your sleep", date); setNotification(index, "Sleep", "Evaluate your sleep", date);
print("sleep");
print(date);
index++; index++;
} }
} }