diff --git a/android/app/build.gradle b/android/app/build.gradle index 4fef84e..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 } @@ -51,6 +52,7 @@ android { targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName + multiDexEnabled true } buildTypes { @@ -68,4 +70,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/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/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/lib/service/date_service.dart b/lib/service/date_service.dart index be45fe6..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,10 +49,14 @@ 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)); - if (selectedDaysInt.contains(date.weekday)) { + 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 daff249..2f564ce 100644 --- a/lib/service/notification_service.dart +++ b/lib/service/notification_service.dart @@ -18,11 +18,11 @@ class NotificationService { Future initNotification() async { // Android initialization const AndroidInitializationSettings initializationSettingsAndroid = - AndroidInitializationSettings('@mipmap/ic_launcher'); + AndroidInitializationSettings('mipmap/ic_launcher'); // ios initialization - const IOSInitializationSettings initializationSettingsIOS = - IOSInitializationSettings( + const DarwinInitializationSettings initializationSettingsIOS = + DarwinInitializationSettings( requestAlertPermission: false, requestBadgePermission: false, requestSoundPermission: false, @@ -36,16 +36,40 @@ class NotificationService { await flutterLocalNotificationsPlugin.initialize(initializationSettings); } + 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(); + int index = 0; for (var date in moodDates) { - setNotification(1, "Mood", "Evaluate your mood", date); - print("mood"); + setNotification(index, "Mood", "Evaluate your mood", date); + index++; } for (var date in sleepDates) { - setNotification(1, "Sleep", "Evaluate your sleep", date); - print("sleep"); + setNotification(index, "Sleep", "Evaluate your sleep", date); + index++; } } @@ -63,7 +87,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 fea7a33..04c064a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -152,21 +152,21 @@ packages: name: flutter_local_notifications url: "https://pub.dartlang.org" source: hosted - version: "9.9.1" + version: "13.0.0" flutter_local_notifications_linux: dependency: transitive description: name: flutter_local_notifications_linux url: "https://pub.dartlang.org" source: hosted - version: "0.5.1" + 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: "5.0.0" + version: "6.0.0" flutter_test: dependency: "direct dev" description: flutter @@ -433,7 +433,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 6e3127c..c4a8789 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -38,11 +38,11 @@ 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 - flutter_local_notifications: ^9.3.1 - timezone: ^0.8.0 + timezone: ^0.9.0 shared_preferences: ^2.0.17 audioplayers: ^3.0.1 mobile_scanner: ^3.0.0 + flutter_local_notifications: ^13.0.0 dev_dependencies: flutter_test: