Some Improvements
This commit is contained in:
+30
-9
@@ -11,9 +11,24 @@ import 'package:flutter_background_service/flutter_background_service.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'dart:math';
|
||||
|
||||
String formatMinutes(int minutes) {
|
||||
int hours = minutes ~/ 60;
|
||||
int remainingMinutes = minutes % 60;
|
||||
|
||||
String hoursString = "";
|
||||
String minutesString = "";
|
||||
|
||||
if (hours > 0) {
|
||||
hoursString = "$hours h";
|
||||
}
|
||||
|
||||
minutesString = "$remainingMinutes min";
|
||||
|
||||
return "$hoursString $minutesString";
|
||||
}
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void callbackDispatcher() async {
|
||||
|
||||
Map content = await FileHandler.fileContent;
|
||||
int id = 15;
|
||||
for (String key in content.keys) {
|
||||
@@ -23,16 +38,24 @@ void callbackDispatcher() async {
|
||||
DateTime dueTime = DateTime.parse(current["dueTime"]);
|
||||
bool checked = current["checked"];
|
||||
DateTime currentTime = DateTime.now();
|
||||
int timeDiff = dueTime
|
||||
.difference(currentTime)
|
||||
.inMinutes;
|
||||
if (timeDiff <= 45 && timeDiff >= 0 && !checked) {
|
||||
bool notifiedDay = current["notifiedDay"];
|
||||
bool notifiedHour = current["notifiedHour"];
|
||||
int timeDiff = dueTime.difference(currentTime).inMinutes;
|
||||
if ((timeDiff <= 90 && !notifiedHour ||
|
||||
timeDiff > 23*60 && timeDiff <= 25 * 60 && !notifiedDay) &&
|
||||
timeDiff >= 0 &&
|
||||
!checked) {
|
||||
String notifyType = timeDiff <= 90 ? "notifiedHour" : "notifiedDay";
|
||||
|
||||
await FileHandler.saveNotified(key, title, notifyType, true);
|
||||
|
||||
AwesomeNotifications().createNotification(
|
||||
content: NotificationContent(
|
||||
id: id,
|
||||
channelKey: "reminder_channel",
|
||||
title: "Task due!",
|
||||
body: "Task $title due in $timeDiff minutes!"));
|
||||
body:
|
||||
"Task $title due in ${formatMinutes(timeDiff)} !"));
|
||||
}
|
||||
id++;
|
||||
}
|
||||
@@ -55,9 +78,7 @@ Future<void> initService() async {
|
||||
onStart: onStart,
|
||||
isForegroundMode: false,
|
||||
autoStart: true,
|
||||
autoStartOnBoot: true
|
||||
)
|
||||
);
|
||||
autoStartOnBoot: true));
|
||||
|
||||
service.startService();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user