Skip to content

Commit 666969e

Browse files
committed
Notification deleted on task deletion or completion
1 parent dd5a984 commit 666969e

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

lib/widgets/buildTasks.dart

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import 'package:flutter/foundation.dart';
44
import 'package:flutter/material.dart';
55

6-
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
76
import 'package:flutter_slidable/flutter_slidable.dart';
87
import 'package:google_fonts/google_fonts.dart';
98

@@ -15,6 +14,7 @@ import 'package:taskwarrior/model/storage/storage_widget.dart';
1514
import 'package:taskwarrior/services/task_details.dart';
1615
import 'package:taskwarrior/services/task_list_tem.dart';
1716
import 'package:taskwarrior/widgets/taskfunctions/modify.dart';
17+
import '../services/notification_services.dart';
1818
import 'pallete.dart';
1919

2020
class TasksBuilder extends StatefulWidget {
@@ -191,13 +191,15 @@ class _TasksBuilderState extends State<TasksBuilder> {
191191
DateTime? dtb = task.due;
192192
dtb =
193193
dtb!.add(const Duration(minutes: 1));
194-
final FlutterLocalNotificationsPlugin
195-
flutterLocalNotificationsPlugin =
196-
FlutterLocalNotificationsPlugin();
197-
flutterLocalNotificationsPlugin.cancel(
198-
dtb.day * 100 +
199-
dtb.hour * 10 +
200-
dtb.minute);
194+
NotificationService notificationService =
195+
NotificationService();
196+
//Task ID is set to null when creating the notification id.
197+
int notificationId = notificationService
198+
.calculateNotificationId(task.due!,
199+
task.description, null);
200+
notificationService
201+
.cancelNotification(notificationId);
202+
201203
if (kDebugMode) {
202204
print("Task due is $dtb");
203205
print(dtb.day * 100 +
@@ -217,20 +219,24 @@ class _TasksBuilderState extends State<TasksBuilder> {
217219
motion: const DrawerMotion(),
218220
children: [
219221
SlidableAction(
220-
onPressed: (context) {
222+
onPressed: (context) async {
221223
// Delete task without confirmation
222224
setStatus('deleted', task.uuid);
223225
if (task.due != null) {
224226
DateTime? dtb = task.due;
225227
dtb =
226228
dtb!.add(const Duration(minutes: 1));
227-
final FlutterLocalNotificationsPlugin
228-
flutterLocalNotificationsPlugin =
229-
FlutterLocalNotificationsPlugin();
230-
flutterLocalNotificationsPlugin.cancel(
231-
dtb.day * 100 +
232-
dtb.hour * 10 +
233-
dtb.minute);
229+
230+
//Task ID is set to null when creating the notification id.
231+
NotificationService notificationService =
232+
NotificationService();
233+
234+
int notificationId = notificationService
235+
.calculateNotificationId(task.due!,
236+
task.description, null);
237+
notificationService
238+
.cancelNotification(notificationId);
239+
234240
if (kDebugMode) {
235241
print("Task due is $dtb");
236242
print(dtb.day * 100 +

0 commit comments

Comments
 (0)