Notifications
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
||||
<application
|
||||
android:label="ToDo"
|
||||
android:name="${applicationName}"
|
||||
@@ -30,6 +31,8 @@
|
||||
<meta-data
|
||||
android:name="flutterEmbedding"
|
||||
android:value="2" />
|
||||
<!--This should make the able to run in background-->
|
||||
<receiver android:name="be.tramckrijte.workmanager.WorkManagerBroadcastReceiver" android:exported="true"/>
|
||||
</application>
|
||||
<!-- Required to query activities that can process text, see:
|
||||
https://developer.android.com/training/package-visibility and
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 28 KiB |
+65
-4
@@ -1,9 +1,72 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:todoapp/elems/filehandler.dart';
|
||||
import 'package:todoapp/pages/Home.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:todoapp/providers/todoprovider.dart';
|
||||
import 'package:awesome_notifications/awesome_notifications.dart';
|
||||
import 'package:workmanager/workmanager.dart';
|
||||
import 'package:disable_battery_optimization/disable_battery_optimization.dart';
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void callbackDispatcher() {
|
||||
Workmanager().executeTask((task, inputData) async {
|
||||
AwesomeNotifications().initialize(
|
||||
null,
|
||||
[
|
||||
NotificationChannel(
|
||||
channelKey: "reminder_channel",
|
||||
channelName: "Reminders",
|
||||
channelDescription: "Reminder for ToDo")
|
||||
]);
|
||||
|
||||
Map content = await FileHandler.fileContent;
|
||||
for (String key in content.keys) {
|
||||
Map list = content[key];
|
||||
for (String title in list.keys) {
|
||||
Map current = list[title];
|
||||
DateTime dueTime = DateTime.parse(current["dueTime"]);
|
||||
bool checked = current["checked"];
|
||||
DateTime currentTime = DateTime.now();
|
||||
int timeDiff = dueTime
|
||||
.difference(currentTime)
|
||||
.inMinutes;
|
||||
if (timeDiff <= 30 && timeDiff >= 0 && !checked) {
|
||||
AwesomeNotifications().createNotification(
|
||||
content: NotificationContent(
|
||||
id: 10,
|
||||
channelKey: "reminder_channel",
|
||||
title: "Task due!",
|
||||
body: "Task $title due in $timeDiff minutes!"
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Future.value(true);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
void main() async {
|
||||
|
||||
|
||||
AwesomeNotifications().initialize(
|
||||
null,
|
||||
[
|
||||
NotificationChannel(
|
||||
channelKey: "reminder_channel",
|
||||
channelName: "Reminders",
|
||||
channelDescription: "Reminder for ToDo")
|
||||
]);
|
||||
|
||||
Workmanager().initialize(
|
||||
callbackDispatcher,
|
||||
isInDebugMode: true
|
||||
);
|
||||
|
||||
Workmanager().registerPeriodicTask("check_nots", "nots_check", frequency: Duration(minutes: 15));
|
||||
// Workmanager().registerOneOffTask("test", "test1");
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
@@ -13,9 +76,7 @@ class MyApp extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider(create: (context) => TodoProvider())
|
||||
],
|
||||
providers: [ChangeNotifierProvider(create: (context) => TodoProvider())],
|
||||
child: MaterialApp(
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
|
||||
@@ -117,6 +117,10 @@ class _ModalEditTodoState extends State<ModalEditTodo> {
|
||||
const SizedBox(height: 20),
|
||||
SegmentedButton(
|
||||
segments: const [
|
||||
ButtonSegment(
|
||||
value: "Delete",
|
||||
label: Text("Delete"),
|
||||
icon: Icon(Icons.delete)),
|
||||
ButtonSegment(
|
||||
value: "Cancel",
|
||||
label: Text("Cancel"),
|
||||
@@ -131,6 +135,8 @@ class _ModalEditTodoState extends State<ModalEditTodo> {
|
||||
onSelectionChanged: (p0) {
|
||||
if (p0.last == "Save") {
|
||||
context.read<TodoProvider>().updateTodo(widget.oldValue, tempValue, combineTime());
|
||||
} else if (p0.last == "Delete") {
|
||||
context.read<TodoProvider>().removeTodo(widget.oldValue);
|
||||
}
|
||||
Navigator.pop(context);
|
||||
},
|
||||
|
||||
@@ -5,6 +5,10 @@ import 'package:todoapp/modules/body.dart';
|
||||
import 'package:todoapp/modules/drawer.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:todoapp/providers/todoprovider.dart';
|
||||
import 'package:awesome_notifications/awesome_notifications.dart';
|
||||
import 'package:workmanager/workmanager.dart';
|
||||
import 'package:disable_battery_optimization/disable_battery_optimization.dart';
|
||||
|
||||
|
||||
class Home extends StatefulWidget {
|
||||
const Home({super.key});
|
||||
@@ -14,8 +18,28 @@ class Home extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _HomeState extends State<Home> {
|
||||
void getPermissions() async {
|
||||
await DisableBatteryOptimization.showEnableAutoStartSettings("Enable Auto Start", "Follow the steps and enable the auto start of this app");
|
||||
await DisableBatteryOptimization.showDisableBatteryOptimizationSettings();
|
||||
|
||||
AwesomeNotifications().isNotificationAllowed().then((isAllowed) {
|
||||
AwesomeNotifications().requestPermissionToSendNotifications();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
getPermissions();
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// AwesomeNotifications().createNotification(
|
||||
// content: NotificationContent(id: 10, channelKey: "reminder_channel", title: "test", body: "test"),
|
||||
// );
|
||||
|
||||
return FutureBuilder(
|
||||
future: context.read<TodoProvider>().readListsFromDisk(),
|
||||
builder: (context, snapshot) => const Scaffold(
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
# Generated by pub
|
||||
# See https://dart.dev/tools/pub/glossary#lockfile
|
||||
packages:
|
||||
android_intent_plus:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: android_intent_plus
|
||||
sha256: "007703c1b2cac7ca98add3336b98cffa4baa11d5133cc463293dba9daa39cdf6"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "5.1.0"
|
||||
async:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -9,6 +17,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.11.0"
|
||||
awesome_notifications:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: awesome_notifications
|
||||
sha256: d9e46ce7f5171ee1e9b1c5bc6dc40bd77528561f592842ce97ce3a0a9ae155ef
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.9.3+1"
|
||||
boolean_selector:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -49,6 +65,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.8"
|
||||
disable_battery_optimization:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: disable_battery_optimization
|
||||
sha256: "6b2ba802f984af141faf1b6b5fb956d5ef01f9cd555597c35b9cc335a03185ba"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.1"
|
||||
fake_async:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -83,6 +107,19 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_web_plugins:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
intl:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: intl
|
||||
sha256: d6f56758b7d3014a48af9701c085700aac781a92a87a62b1333b46d8879661cf
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.19.0"
|
||||
leak_tracker:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -296,6 +333,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "14.2.5"
|
||||
workmanager:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: workmanager
|
||||
sha256: ed13530cccd28c5c9959ad42d657cd0666274ca74c56dea0ca183ddd527d3a00
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.5.2"
|
||||
xdg_directories:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
+6
-1
@@ -41,6 +41,10 @@ dev_dependencies:
|
||||
sdk: flutter
|
||||
provider:
|
||||
path_provider:
|
||||
awesome_notifications:
|
||||
workmanager:
|
||||
android_intent_plus:
|
||||
disable_battery_optimization:
|
||||
|
||||
# The "flutter_lints" package below contains a set of recommended lints to
|
||||
# encourage good coding practices. The lint set provided by the package is
|
||||
@@ -54,7 +58,8 @@ dev_dependencies:
|
||||
|
||||
# The following section is specific to Flutter packages.
|
||||
flutter:
|
||||
|
||||
assets:
|
||||
- icons/ic_launcher.png
|
||||
# The following line ensures that the Material Icons font is
|
||||
# included with your application, so that you can use the icons in
|
||||
# the material Icons class.
|
||||
|
||||
Reference in New Issue
Block a user