Merge branch '12-benachrichtigung-aufs-handy-erstellen-2' into 'main'

Resolve "Benachrichtigung aufs Handy erstellen"

See merge request Crondung/hsma_cpd!13
main
Julian Gegner 2023-02-26 13:05:37 +00:00
commit 6895638814
8 changed files with 61 additions and 21 deletions

View File

@ -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'
}

View File

@ -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"
}
}

View File

@ -13,7 +13,7 @@
},
"sleep_query": {
"days": ["Dienstag", "Samstag"],
"hours": 11,
"minutes": 30
"hours": 15,
"minutes": 42
}
}

View File

@ -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)
}
}

View File

@ -38,7 +38,9 @@ Future<List<TZDateTime>> getDatesforSleep() async {
List<TZDateTime> createTZDateTimes(
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 ||
selectedHours == null ||
selectedMinutes == null) {
@ -47,10 +49,14 @@ List<TZDateTime> createTZDateTimes(
final Iterable<int?> 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;

View File

@ -18,11 +18,11 @@ class NotificationService {
Future<void> 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<void> 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<void> setAllNotifications() async {
List<TZDateTime> moodDates = await getDatesforMood();
List<TZDateTime> 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,

View File

@ -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:

View File

@ -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: