scheduleNotification method
Schedule a notification for a task
at the UserTask.triggerTime.
Implementation
@override
Future<void> scheduleNotification(UserTask task) async {
// early out if not to be scheduled
if (!task.notification) return;
// early out if has already been scheduled
// this is relevant for AwesomeNotification since it makes notifications
// persistent across app re-start
if (task.hasNotificationBeenCreated) {
debug('$runtimeType - task has already been scheduled - task: $task');
return;
}
if (task.triggerTime.isAfter(DateTime.now())) {
final time = tz.TZDateTime.from(
task.triggerTime, tz.getLocation(Settings().timezone));
await AwesomeNotifications().createNotification(
content: NotificationContent(
id: task.id.hashCode,
channelKey: 'scheduled_channel',
title: task.title,
body: task.description,
notificationLayout: NotificationLayout.Default),
schedule: NotificationCalendar.fromDate(
date: task.triggerTime, allowWhileIdle: true));
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}.');
}
}