Some Improvements
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
description: This file stores settings for Dart & Flutter DevTools.
|
||||||
|
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
|
||||||
|
extensions:
|
||||||
@@ -21,6 +21,13 @@ class FileHandler {
|
|||||||
return js;
|
return js;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<void> saveNotified(String listName, String todoName, String notifyType, bool value) async {
|
||||||
|
Map content = await fileContent;
|
||||||
|
content[listName][todoName][notifyType] = value;
|
||||||
|
|
||||||
|
await saveFile(content);
|
||||||
|
}
|
||||||
|
|
||||||
static Future<void> saveFile(js) async {
|
static Future<void> saveFile(js) async {
|
||||||
File f = await localFile;
|
File f = await localFile;
|
||||||
String content = json.encode(js);
|
String content = json.encode(js);
|
||||||
|
|||||||
+3
-1
@@ -1,10 +1,12 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class Todo {
|
class Todo {
|
||||||
Todo({required this.title, required this.widget, required this.checked, required this.dueTime});
|
Todo({required this.title, required this.widget, required this.checked, required this.dueTime, required this.notifiedDay, required this.notifiedHour});
|
||||||
|
|
||||||
String title;
|
String title;
|
||||||
Widget widget;
|
Widget widget;
|
||||||
DateTime dueTime;
|
DateTime dueTime;
|
||||||
bool checked;
|
bool checked;
|
||||||
|
bool notifiedHour;
|
||||||
|
bool notifiedDay;
|
||||||
}
|
}
|
||||||
+30
-9
@@ -11,9 +11,24 @@ import 'package:flutter_background_service/flutter_background_service.dart';
|
|||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'dart:math';
|
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')
|
@pragma('vm:entry-point')
|
||||||
void callbackDispatcher() async {
|
void callbackDispatcher() async {
|
||||||
|
|
||||||
Map content = await FileHandler.fileContent;
|
Map content = await FileHandler.fileContent;
|
||||||
int id = 15;
|
int id = 15;
|
||||||
for (String key in content.keys) {
|
for (String key in content.keys) {
|
||||||
@@ -23,16 +38,24 @@ void callbackDispatcher() async {
|
|||||||
DateTime dueTime = DateTime.parse(current["dueTime"]);
|
DateTime dueTime = DateTime.parse(current["dueTime"]);
|
||||||
bool checked = current["checked"];
|
bool checked = current["checked"];
|
||||||
DateTime currentTime = DateTime.now();
|
DateTime currentTime = DateTime.now();
|
||||||
int timeDiff = dueTime
|
bool notifiedDay = current["notifiedDay"];
|
||||||
.difference(currentTime)
|
bool notifiedHour = current["notifiedHour"];
|
||||||
.inMinutes;
|
int timeDiff = dueTime.difference(currentTime).inMinutes;
|
||||||
if (timeDiff <= 45 && timeDiff >= 0 && !checked) {
|
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(
|
AwesomeNotifications().createNotification(
|
||||||
content: NotificationContent(
|
content: NotificationContent(
|
||||||
id: id,
|
id: id,
|
||||||
channelKey: "reminder_channel",
|
channelKey: "reminder_channel",
|
||||||
title: "Task due!",
|
title: "Task due!",
|
||||||
body: "Task $title due in $timeDiff minutes!"));
|
body:
|
||||||
|
"Task $title due in ${formatMinutes(timeDiff)} !"));
|
||||||
}
|
}
|
||||||
id++;
|
id++;
|
||||||
}
|
}
|
||||||
@@ -55,9 +78,7 @@ Future<void> initService() async {
|
|||||||
onStart: onStart,
|
onStart: onStart,
|
||||||
isForegroundMode: false,
|
isForegroundMode: false,
|
||||||
autoStart: true,
|
autoStart: true,
|
||||||
autoStartOnBoot: true
|
autoStartOnBoot: true));
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
service.startService();
|
service.startService();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,8 +30,11 @@ class _TodoWidgetState extends State<TodoWidget> {
|
|||||||
DateTime today = DateTime.now();
|
DateTime today = DateTime.now();
|
||||||
DateTime due = widget.dueTime;
|
DateTime due = widget.dueTime;
|
||||||
|
|
||||||
DateTime nowDay = DateTime(2000, 1, today.day);
|
print(today);
|
||||||
DateTime dueDay = DateTime(2000, 1, due.day);
|
print(due);
|
||||||
|
|
||||||
|
DateTime nowDay = DateTime(today.year, today.month, today.day);
|
||||||
|
DateTime dueDay = DateTime(due.year, due.month, due.day);
|
||||||
int diff = dueDay.difference(nowDay).inDays;
|
int diff = dueDay.difference(nowDay).inDays;
|
||||||
|
|
||||||
Map<int, String> monthList = {
|
Map<int, String> monthList = {
|
||||||
@@ -49,6 +52,8 @@ class _TodoWidgetState extends State<TodoWidget> {
|
|||||||
12: "Dez"
|
12: "Dez"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
print(diff);
|
||||||
|
|
||||||
if (diff < 0) {
|
if (diff < 0) {
|
||||||
return [
|
return [
|
||||||
"Over",
|
"Over",
|
||||||
|
|||||||
@@ -24,11 +24,16 @@ class TodoProvider extends ChangeNotifier {
|
|||||||
String title = key2;
|
String title = key2;
|
||||||
bool checked = decode[key2]["checked"];
|
bool checked = decode[key2]["checked"];
|
||||||
DateTime dueTime = DateTime.parse(decode[key2]["dueTime"]);
|
DateTime dueTime = DateTime.parse(decode[key2]["dueTime"]);
|
||||||
|
bool notifiedDay = decode[key2]["notifiedDay"] ?? false;
|
||||||
|
bool notifiedHour = decode[key2]["notifiedHour"] ?? false;
|
||||||
todoLists[key]!.todos.add(Todo(
|
todoLists[key]!.todos.add(Todo(
|
||||||
title: title,
|
title: title,
|
||||||
widget: buildTodoWidget(title, checked, dueTime),
|
widget: buildTodoWidget(title, checked, dueTime),
|
||||||
checked: checked,
|
checked: checked,
|
||||||
dueTime: dueTime));
|
dueTime: dueTime,
|
||||||
|
notifiedDay: notifiedDay,
|
||||||
|
notifiedHour: notifiedHour,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +96,9 @@ class TodoProvider extends ChangeNotifier {
|
|||||||
for (Todo t in todos) {
|
for (Todo t in todos) {
|
||||||
js["${t.title}"] = {
|
js["${t.title}"] = {
|
||||||
"checked": t.checked,
|
"checked": t.checked,
|
||||||
"dueTime": t.dueTime.toString()
|
"dueTime": t.dueTime.toString(),
|
||||||
|
"notifiedDay": t.notifiedDay,
|
||||||
|
"notifiedHour": t.notifiedHour
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
await FileHandler.saveList(js, selectedList);
|
await FileHandler.saveList(js, selectedList);
|
||||||
@@ -99,7 +106,12 @@ class TodoProvider extends ChangeNotifier {
|
|||||||
|
|
||||||
void addTodo(String title, DateTime dueTime) async {
|
void addTodo(String title, DateTime dueTime) async {
|
||||||
todos.add(Todo(
|
todos.add(Todo(
|
||||||
title: title, checked: false, widget: buildTodoWidget(title, false, dueTime), dueTime: dueTime));
|
title: title,
|
||||||
|
checked: false,
|
||||||
|
widget: buildTodoWidget(title, false, dueTime),
|
||||||
|
dueTime: dueTime,
|
||||||
|
notifiedHour: false,
|
||||||
|
notifiedDay: false));
|
||||||
|
|
||||||
await writeTodoChanges();
|
await writeTodoChanges();
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
@@ -117,6 +129,8 @@ class TodoProvider extends ChangeNotifier {
|
|||||||
Todo todo = todoByTitle(oldTitle);
|
Todo todo = todoByTitle(oldTitle);
|
||||||
todo.title = newTitle;
|
todo.title = newTitle;
|
||||||
todo.dueTime = dueTime;
|
todo.dueTime = dueTime;
|
||||||
|
todo.notifiedDay = false;
|
||||||
|
todo.notifiedHour = false;
|
||||||
|
|
||||||
todo.widget = buildTodoWidget(newTitle, todo.checked, dueTime);
|
todo.widget = buildTodoWidget(newTitle, todo.checked, dueTime);
|
||||||
|
|
||||||
@@ -152,6 +166,9 @@ class TodoProvider extends ChangeNotifier {
|
|||||||
title: "None",
|
title: "None",
|
||||||
widget: const SizedBox(),
|
widget: const SizedBox(),
|
||||||
checked: false,
|
checked: false,
|
||||||
dueTime: DateTime.now());
|
dueTime: DateTime.now(),
|
||||||
|
notifiedDay: false,
|
||||||
|
notifiedHour: false,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user