something

This commit is contained in:
Lea 2023-10-06 14:18:35 +02:00
parent 25edfb6b45
commit eec578b9c8
Signed by: Lea
GPG key ID: 1BAFFE8347019C42
5 changed files with 83 additions and 4 deletions

View file

@ -64,4 +64,13 @@ flutter {
source '../..' source '../..'
} }
dependencies {} dependencies {
constraints {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0") {
because("kotlin-stdlib-jdk7 is now a part of kotlin-stdlib")
}
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") {
because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib")
}
}
}

View file

@ -1,6 +1,7 @@
import 'package:dynamic_color/dynamic_color.dart'; import 'package:dynamic_color/dynamic_color.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:hrt/notification.dart'; import 'package:hrt/notification.dart';
import 'package:hrt/tasks.dart';
import 'package:permission_handler/permission_handler.dart'; import 'package:permission_handler/permission_handler.dart';
void main() { void main() {
@ -12,6 +13,7 @@ class App extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
setupBackgroundTasks();
return DynamicColorBuilder( return DynamicColorBuilder(
builder: ((lightDynamic, darkDynamic) => MaterialApp( builder: ((lightDynamic, darkDynamic) => MaterialApp(
title: "HRT", title: "HRT",

58
lib/tasks.dart Normal file
View file

@ -0,0 +1,58 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:hrt/notification.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:workmanager/workmanager.dart';
@pragma('vm:entry-point')
void callbackDispatcher() {
Workmanager().executeTask((taskName, inputData) async {
print("Native called background task: $taskName");
if (taskName == 'scheduleNotifications') {
sendNotification();
}
return true;
});
}
void setupBackgroundTasks() async {
WidgetsFlutterBinding.ensureInitialized();
await Workmanager().initialize(
callbackDispatcher,
isInDebugMode: kDebugMode,
);
await Permission.notification.request();
await FlutterLocalNotificationsPlugin().initialize(
const InitializationSettings(
android: AndroidInitializationSettings('estrogen'),
),
// onSelectNotification: handleNotificationClick,
);
var launchDetails =
await FlutterLocalNotificationsPlugin().getNotificationAppLaunchDetails();
// if (launchDetails?.payload != null && launchDetails!.payload!.isNotEmpty) {
// handleNotificationClick(launchDetails.payload);
// }
// Runs every 15 minutes
await Workmanager().registerPeriodicTask(
'schedule_notifications',
'scheduleNotifications',
constraints: Constraints(
networkType: NetworkType.not_required,
requiresCharging: false,
requiresBatteryNotLow: false,
requiresDeviceIdle: false,
requiresStorageNotLow: false,
),
initialDelay: const Duration(seconds: 15),
frequency: const Duration(minutes: 15),
);
}

View file

@ -106,10 +106,10 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
name: flutter_local_notifications name: flutter_local_notifications
sha256: "3002092e5b8ce2f86c3361422e52e6db6776c23ee21e0b2f71b892bf4259ef04" sha256: "501ed9d54f1c8c0535b7991bade36f9e7e3b45a2346401f03775c1ec7a3c06ae"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "15.1.1" version: "15.1.2"
flutter_local_notifications_linux: flutter_local_notifications_linux:
dependency: transitive dependency: transitive
description: description:
@ -281,7 +281,7 @@ packages:
source: hosted source: hosted
version: "0.6.1" version: "0.6.1"
timezone: timezone:
dependency: transitive dependency: "direct main"
description: description:
name: timezone name: timezone
sha256: "1cfd8ddc2d1cfd836bc93e67b9be88c3adaeca6f40a00ca999104c30693cdca0" sha256: "1cfd8ddc2d1cfd836bc93e67b9be88c3adaeca6f40a00ca999104c30693cdca0"
@ -304,6 +304,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.1.4-beta" version: "0.1.4-beta"
workmanager:
dependency: "direct main"
description:
name: workmanager
sha256: ed13530cccd28c5c9959ad42d657cd0666274ca74c56dea0ca183ddd527d3a00
url: "https://pub.dev"
source: hosted
version: "0.5.2"
xdg_directories: xdg_directories:
dependency: transitive dependency: transitive
description: description:

View file

@ -38,6 +38,8 @@ dependencies:
dynamic_color: ^1.6.7 dynamic_color: ^1.6.7
flutter_local_notifications: ^15.1.1 flutter_local_notifications: ^15.1.1
permission_handler: ^11.0.1 permission_handler: ^11.0.1
workmanager: ^0.5.2
timezone: ^0.9.2
dev_dependencies: dev_dependencies:
flutter_test: flutter_test: