From 597e8d7489fef283e962b74d923aac0c58406fc3 Mon Sep 17 00:00:00 2001 From: Crondung <1922635@stud.hs-mannheim.de> Date: Mon, 20 Feb 2023 14:43:07 +0100 Subject: [PATCH 1/6] wip add ios and android deps --- android/app/build.gradle | 2 ++ android/build.gradle | 2 +- ios/Runner/AppDelegate.swift | 7 +++++ pubspec.lock | 58 +++++++++++++++++++++++++++++++++++- pubspec.yaml | 1 + 5 files changed, 68 insertions(+), 2 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index d8c9ecd..e60e21c 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -51,6 +51,7 @@ android { targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName + multiDexEnabled true } buildTypes { @@ -68,4 +69,5 @@ flutter { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' } diff --git a/android/build.gradle b/android/build.gradle index 83ae220..0f10c23 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -6,7 +6,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:7.1.2' + classpath 'com.android.tools.build:gradle:7.1.2' //needs to be >= 4.2.2 for local notifications classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } diff --git a/ios/Runner/AppDelegate.swift b/ios/Runner/AppDelegate.swift index 70693e4..521aa68 100644 --- a/ios/Runner/AppDelegate.swift +++ b/ios/Runner/AppDelegate.swift @@ -1,5 +1,6 @@ import UIKit import Flutter +import flutter_local_notifications @UIApplicationMain @objc class AppDelegate: FlutterAppDelegate { @@ -7,7 +8,13 @@ import Flutter _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { + FlutterLocalNotificationsPlugin.setPluginRegistrantCallback { (registry) in + GeneratedPluginRegistrant.register(with: registry) + } GeneratedPluginRegistrant.register(with: self) + if #available(iOS 10.0, *) { + UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate + } return super.application(application, didFinishLaunchingWithOptions: launchOptions) } } diff --git a/pubspec.lock b/pubspec.lock index 1cda953..61493d6 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,6 +1,13 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + args: + dependency: transitive + description: + name: args + url: "https://pub.dartlang.org" + source: hosted + version: "2.4.0" async: dependency: transitive description: @@ -43,6 +50,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.5" + dbus: + dependency: transitive + description: + name: dbus + url: "https://pub.dartlang.org" + source: hosted + version: "0.7.8" fake_async: dependency: transitive description: @@ -76,6 +90,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.1" + flutter_local_notifications: + dependency: "direct main" + description: + name: flutter_local_notifications + url: "https://pub.dartlang.org" + source: hosted + version: "13.0.0" + flutter_local_notifications_linux: + dependency: transitive + description: + name: flutter_local_notifications_linux + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.0+1" + flutter_local_notifications_platform_interface: + dependency: transitive + description: + name: flutter_local_notifications_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "6.0.0" flutter_test: dependency: "direct dev" description: flutter @@ -149,6 +184,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.3" + petitparser: + dependency: transitive + description: + name: petitparser + url: "https://pub.dartlang.org" + source: hosted + version: "5.1.0" platform: dependency: transitive description: @@ -266,6 +308,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.4.12" + timezone: + dependency: transitive + description: + name: timezone + url: "https://pub.dartlang.org" + source: hosted + version: "0.9.1" vector_math: dependency: transitive description: @@ -286,7 +335,14 @@ packages: name: xdg_directories url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" + version: "0.2.0+3" + xml: + dependency: transitive + description: + name: xml + url: "https://pub.dartlang.org" + source: hosted + version: "6.1.0" sdks: dart: ">=2.18.2 <3.0.0" flutter: ">=3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index ea481f5..2e92257 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -36,6 +36,7 @@ dependencies: # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 shared_preferences: ^2.0.17 + flutter_local_notifications: ^13.0.0 dev_dependencies: flutter_test: From d917387bb4f3e136e5b5425b57e9e6f82bd0cf1f Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Sat, 25 Feb 2023 14:19:55 +0100 Subject: [PATCH 2/6] Fixed IOS bug --- lib/service/notification_service.dart | 10 ++++++---- pubspec.lock | 2 +- pubspec.yaml | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/service/notification_service.dart b/lib/service/notification_service.dart index daff249..7eca521 100644 --- a/lib/service/notification_service.dart +++ b/lib/service/notification_service.dart @@ -21,8 +21,8 @@ class NotificationService { AndroidInitializationSettings('@mipmap/ic_launcher'); // ios initialization - const IOSInitializationSettings initializationSettingsIOS = - IOSInitializationSettings( + const DarwinInitializationSettings initializationSettingsIOS = + DarwinInitializationSettings( requestAlertPermission: false, requestBadgePermission: false, requestSoundPermission: false, @@ -33,7 +33,9 @@ class NotificationService { android: initializationSettingsAndroid, iOS: initializationSettingsIOS); // the initialization settings are initialized after they are setted - await flutterLocalNotificationsPlugin.initialize(initializationSettings); + bool? initialized = await flutterLocalNotificationsPlugin + .initialize(initializationSettings); + print(initialized); } Future setAllNotifications() async { @@ -63,7 +65,7 @@ class NotificationService { importance: Importance.max, priority: Priority.max), // iOS details - iOS: IOSNotificationDetails( + iOS: DarwinNotificationDetails( sound: 'default.wav', presentAlert: true, presentBadge: true, diff --git a/pubspec.lock b/pubspec.lock index 06d9416..b488967 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -412,7 +412,7 @@ packages: name: timezone url: "https://pub.dartlang.org" source: hosted - version: "0.8.0" + version: "0.9.1" typed_data: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 656fddc..8239b72 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -35,7 +35,7 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 - timezone: ^0.8.0 + timezone: ^0.9.0 shared_preferences: ^2.0.17 audioplayers: ^3.0.1 mobile_scanner: ^3.0.0 From 36abb7da3625be510de585d0a6f66143c6bac002 Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Sat, 25 Feb 2023 14:39:05 +0100 Subject: [PATCH 3/6] fixed dates before now --- lib/service/date_service.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/service/date_service.dart b/lib/service/date_service.dart index be45fe6..257afc1 100644 --- a/lib/service/date_service.dart +++ b/lib/service/date_service.dart @@ -48,7 +48,8 @@ List createTZDateTimes( selectedDays.map((day) => weekDays[day]); for (int i = 0; i < trainingTime; i++) { final DateTime date = DateTime.now().add(Duration(days: i)); - if (selectedDaysInt.contains(date.weekday)) { + if (selectedDaysInt.contains(date.weekday) && + date.isAfter(DateTime.now())) { tzDateTimes.add(TZDateTime.local(date.year, date.month, date.day, selectedHours, selectedMinutes, 0, 0, 0)); } From 09d5e51377e849ea1e1c4a967134330607255bb2 Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Sat, 25 Feb 2023 14:58:10 +0100 Subject: [PATCH 4/6] Test Notification --- android/app/build.gradle | 1 + lib/pages/scanner_page.dart | 2 +- lib/service/notification_service.dart | 25 ++++++++++++++++++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 2ada6e0..af69fb2 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -30,6 +30,7 @@ android { ndkVersion flutter.ndkVersion compileOptions { + coreLibraryDesugaringEnabled true sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } diff --git a/lib/pages/scanner_page.dart b/lib/pages/scanner_page.dart index b21b523..8ab4419 100644 --- a/lib/pages/scanner_page.dart +++ b/lib/pages/scanner_page.dart @@ -68,7 +68,7 @@ class ScannerPageState extends State { textStyle: const TextStyle(fontSize: 20)), onPressed: () { loadSettingsFromLocalJSON(); - NotificationService().setAllNotifications(); + NotificationService().showNotification(); }, child: const Text('Read JSON'), ) diff --git a/lib/service/notification_service.dart b/lib/service/notification_service.dart index 7eca521..a63b3fd 100644 --- a/lib/service/notification_service.dart +++ b/lib/service/notification_service.dart @@ -18,7 +18,7 @@ class NotificationService { Future initNotification() async { // Android initialization const AndroidInitializationSettings initializationSettingsAndroid = - AndroidInitializationSettings('@mipmap/ic_launcher'); + AndroidInitializationSettings('mipmap/ic_launcher'); // ios initialization const DarwinInitializationSettings initializationSettingsIOS = @@ -38,6 +38,29 @@ class NotificationService { print(initialized); } + Future showNotification() async { + await flutterLocalNotificationsPlugin.show( + 0, + 'test', + 'test', +//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, + ), + ), + ); + } + Future setAllNotifications() async { List moodDates = await getDatesforMood(); List sleepDates = await getDatesforSleep(); From a975a44f4e4e12ebb402126e455aed2e7a414f3e Mon Sep 17 00:00:00 2001 From: Parricc35 <63447810+Parricc35@users.noreply.github.com> Date: Sat, 25 Feb 2023 15:52:07 +0100 Subject: [PATCH 5/6] wip --- assets/group3.json | 4 ++-- lib/pages/scanner_page.dart | 2 +- lib/service/date_service.dart | 5 ++++- lib/service/notification_service.dart | 8 ++++++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/assets/group3.json b/assets/group3.json index 623ffc8..55ce9e0 100644 --- a/assets/group3.json +++ b/assets/group3.json @@ -13,7 +13,7 @@ }, "sleep_query": { "days": ["Dienstag", "Samstag"], - "hours": 11, - "minutes": 30 + "hours": 15, + "minutes": 42 } } diff --git a/lib/pages/scanner_page.dart b/lib/pages/scanner_page.dart index 8ab4419..b21b523 100644 --- a/lib/pages/scanner_page.dart +++ b/lib/pages/scanner_page.dart @@ -68,7 +68,7 @@ class ScannerPageState extends State { textStyle: const TextStyle(fontSize: 20)), onPressed: () { loadSettingsFromLocalJSON(); - NotificationService().showNotification(); + NotificationService().setAllNotifications(); }, child: const Text('Read JSON'), ) diff --git a/lib/service/date_service.dart b/lib/service/date_service.dart index 257afc1..f703fa6 100644 --- a/lib/service/date_service.dart +++ b/lib/service/date_service.dart @@ -47,7 +47,10 @@ List createTZDateTimes( final Iterable selectedDaysInt = selectedDays.map((day) => weekDays[day]); for (int i = 0; i < trainingTime; i++) { - final DateTime date = DateTime.now().add(Duration(days: i)); + final DateTime now = DateTime.now(); + 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())) { tzDateTimes.add(TZDateTime.local(date.year, date.month, date.day, diff --git a/lib/service/notification_service.dart b/lib/service/notification_service.dart index a63b3fd..c2e3bfd 100644 --- a/lib/service/notification_service.dart +++ b/lib/service/notification_service.dart @@ -64,13 +64,17 @@ class NotificationService { Future setAllNotifications() async { List moodDates = await getDatesforMood(); List sleepDates = await getDatesforSleep(); + int index = 0; for (var date in moodDates) { - setNotification(1, "Mood", "Evaluate your mood", date); + setNotification(index, "Mood", "Evaluate your mood", date); print("mood"); + index++; } for (var date in sleepDates) { - setNotification(1, "Sleep", "Evaluate your sleep", date); + setNotification(index, "Sleep", "Evaluate your sleep", date); print("sleep"); + print(date); + index++; } } From df38c25bc496128a7a504eb70647c8b4df9b6496 Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Sun, 26 Feb 2023 12:44:01 +0100 Subject: [PATCH 6/6] Fixed Timezone Bug --- lib/service/date_service.dart | 8 +++++--- lib/service/notification_service.dart | 7 +------ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/service/date_service.dart b/lib/service/date_service.dart index f703fa6..b422509 100644 --- a/lib/service/date_service.dart +++ b/lib/service/date_service.dart @@ -38,7 +38,9 @@ Future> getDatesforSleep() async { List createTZDateTimes( List? selectedDays, int? selectedHours, int? selectedMinutes) { - List tzDateTimes = []; + final List tzDateTimes = []; + final DateTime now = DateTime.now(); + final Duration offset = now.timeZoneOffset; if (selectedDays == null || selectedHours == null || selectedMinutes == null) { @@ -47,14 +49,14 @@ List createTZDateTimes( final Iterable selectedDaysInt = selectedDays.map((day) => weekDays[day]); for (int i = 0; i < trainingTime; i++) { - final DateTime now = DateTime.now(); 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())) { tzDateTimes.add(TZDateTime.local(date.year, date.month, date.day, - selectedHours, selectedMinutes, 0, 0, 0)); + selectedHours, selectedMinutes, 0, 0, 0) + .subtract(offset)); } } return tzDateTimes; diff --git a/lib/service/notification_service.dart b/lib/service/notification_service.dart index c2e3bfd..2f564ce 100644 --- a/lib/service/notification_service.dart +++ b/lib/service/notification_service.dart @@ -33,9 +33,7 @@ class NotificationService { android: initializationSettingsAndroid, iOS: initializationSettingsIOS); // the initialization settings are initialized after they are setted - bool? initialized = await flutterLocalNotificationsPlugin - .initialize(initializationSettings); - print(initialized); + await flutterLocalNotificationsPlugin.initialize(initializationSettings); } Future showNotification() async { @@ -67,13 +65,10 @@ class NotificationService { int index = 0; for (var date in moodDates) { setNotification(index, "Mood", "Evaluate your mood", date); - print("mood"); index++; } for (var date in sleepDates) { setNotification(index, "Sleep", "Evaluate your sleep", date); - print("sleep"); - print(date); index++; } }