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] 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();