diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index 53b0a76..6eaaa1f 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -2,6 +2,7 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/android/app/src/main/res/drawable/keep.xml b/android/app/src/main/res/drawable/keep.xml
new file mode 100644
index 0000000..c721bb9
--- /dev/null
+++ b/android/app/src/main/res/drawable/keep.xml
@@ -0,0 +1,3 @@
+
+
\ No newline at end of file
diff --git a/lib/main.dart b/lib/main.dart
index 9673440..cd7bd81 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -69,7 +69,7 @@ class _HomePageState extends State {
}
});
- sendNotification();
+ scheduleNotification();
},
),
),
diff --git a/lib/notification.dart b/lib/notification.dart
index 9b3cd72..55b8c55 100644
--- a/lib/notification.dart
+++ b/lib/notification.dart
@@ -1,8 +1,12 @@
// ignore_for_file: avoid_print
+import 'dart:io';
+
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
+import 'package:flutter_native_timezone/flutter_native_timezone.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:timezone/data/latest.dart';
+import 'package:timezone/standalone.dart';
import 'package:timezone/timezone.dart';
const details = NotificationDetails(
@@ -44,17 +48,24 @@ void sendNotification() async {
void scheduleNotification() async {
_initializePlugin();
initializeTimeZones();
+ var timezone = await FlutterNativeTimezone.getLocalTimezone();
+ setLocalLocation(getLocation(timezone));
// [Hours, Minutes]
var times = [
[12, 00],
[18, 00],
+ [19, 50],
+ [19, 51],
+ [20, 52],
+ [20, 53],
];
if (times.isEmpty) return;
final SharedPreferences prefs = await SharedPreferences.getInstance();
var currentTime = TZDateTime.now(local);
+ print(local.name);
// Map the time entries to TZDateTime objects
var notificationTimes = times
@@ -70,13 +81,15 @@ void scheduleNotification() async {
// For all entries in the past, add 1 day
for (var time
- in notificationTimes.where((time) => time.compareTo(currentTime) < 0)) {
+ in notificationTimes.where((time) => time.compareTo(currentTime) <= 0)) {
notificationTimes.remove(time);
notificationTimes.add(time.add(const Duration(days: 1)));
+ print("trolling ${time.toString()}");
}
// Sort the array so we can find the closest time
notificationTimes.sort((a, b) => a.compareTo(b));
+ print(notificationTimes.map((e) => e.toString()).join(" - "));
var notificationTime = notificationTimes[0];
if (prefs.getString('scheduled_notification') ==
diff --git a/lib/tasks.dart b/lib/tasks.dart
index 8efe9c4..cda1cc4 100644
--- a/lib/tasks.dart
+++ b/lib/tasks.dart
@@ -22,7 +22,7 @@ void setupBackgroundTasks() async {
WidgetsFlutterBinding.ensureInitialized();
await Workmanager().initialize(
callbackDispatcher,
- isInDebugMode: kDebugMode,
+ isInDebugMode: true || kDebugMode,
);
await Permission.notification.request();
diff --git a/pubspec.lock b/pubspec.lock
index 35a2af1..0ad553a 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -134,6 +134,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "7.0.0+1"
+ flutter_native_timezone:
+ dependency: "direct main"
+ description:
+ name: flutter_native_timezone
+ sha256: ed7bfb982f036243de1c068e269182a877100c994f05143c8b26a325e28c1b02
+ url: "https://pub.dev"
+ source: hosted
+ version: "2.0.0"
flutter_test:
dependency: "direct dev"
description: flutter
@@ -144,6 +152,14 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
+ js:
+ dependency: transitive
+ description:
+ name: js
+ sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
+ url: "https://pub.dev"
+ source: hosted
+ version: "0.6.7"
lints:
dependency: transitive
description:
diff --git a/pubspec.yaml b/pubspec.yaml
index f632d61..e74d82a 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -41,6 +41,7 @@ dependencies:
workmanager: ^0.5.2
timezone: ^0.9.2
shared_preferences: ^2.2.1
+ flutter_native_timezone: ^2.0.0
dev_dependencies:
flutter_test: