something
This commit is contained in:
parent
25edfb6b45
commit
eec578b9c8
|
@ -64,4 +64,13 @@ flutter {
|
|||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:dynamic_color/dynamic_color.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hrt/notification.dart';
|
||||
import 'package:hrt/tasks.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
void main() {
|
||||
|
@ -12,6 +13,7 @@ class App extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
setupBackgroundTasks();
|
||||
return DynamicColorBuilder(
|
||||
builder: ((lightDynamic, darkDynamic) => MaterialApp(
|
||||
title: "HRT",
|
||||
|
|
58
lib/tasks.dart
Normal file
58
lib/tasks.dart
Normal 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),
|
||||
);
|
||||
}
|
14
pubspec.lock
14
pubspec.lock
|
@ -106,10 +106,10 @@ packages:
|
|||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_local_notifications
|
||||
sha256: "3002092e5b8ce2f86c3361422e52e6db6776c23ee21e0b2f71b892bf4259ef04"
|
||||
sha256: "501ed9d54f1c8c0535b7991bade36f9e7e3b45a2346401f03775c1ec7a3c06ae"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "15.1.1"
|
||||
version: "15.1.2"
|
||||
flutter_local_notifications_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -281,7 +281,7 @@ packages:
|
|||
source: hosted
|
||||
version: "0.6.1"
|
||||
timezone:
|
||||
dependency: transitive
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: timezone
|
||||
sha256: "1cfd8ddc2d1cfd836bc93e67b9be88c3adaeca6f40a00ca999104c30693cdca0"
|
||||
|
@ -304,6 +304,14 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
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:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -38,6 +38,8 @@ dependencies:
|
|||
dynamic_color: ^1.6.7
|
||||
flutter_local_notifications: ^15.1.1
|
||||
permission_handler: ^11.0.1
|
||||
workmanager: ^0.5.2
|
||||
timezone: ^0.9.2
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
Loading…
Reference in a new issue