scheduleTaskNotification method
Schedule a notification for a task at the task.triggerTime.
Implementation
@override
Future<void> scheduleTaskNotification(UserTask task) async {
// early out if not to be scheduled
if (!task.notification) return;
if (task.triggerTime.isAfter(DateTime.now())) {
final time = tz.TZDateTime.from(
task.triggerTime,
tz.getLocation(Settings().timezoneLocation),
);
await FlutterLocalNotificationsPlugin().zonedSchedule(
id: task.id.hashCode,
title: task.title,
body: task.description,
scheduledDate: time,
notificationDetails: _platformChannelSpecifics,
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
payload: task.id,
);
task.hasNotificationBeenCreated = true;
debug('$runtimeType - Notification scheduled for $task at $time');
} else {
warning(
'$runtimeType - Can only schedule a notification in the future. '
'task trigger time: ${task.triggerTime}.',
);
}
}