Reputation: 31
I want the notification to repeat. It works as expected in the foreground, but in the background, the notification only appears once and disappears. Since it’s an alarm app, I need the notification to keep repeating until the user clicks on it, even in the background. Below is the code I have written.
static void initializeNotificationListeners() {
print('Initializing notification listeners');
AwesomeNotifications().setListeners(
onActionReceivedMethod: onActionReceivedMethod,
onNotificationDisplayedMethod: onNotificationDisplayedMethod,
);
print('Notification listeners set');
}
static Future<void> onNotificationDisplayedMethod(ReceivedNotification receivedNotification) async {
_notificationTimer?.cancel();
_notificationTimer = Timer.periodic(Duration(seconds: 7), (timer) async {
int? subId = int.tryParse(receivedNotification.payload?['subId'] ?? '');
await AwesomeNotifications().createNotification(
content: NotificationContent(
criticalAlert: true,
displayOnBackground: true,
displayOnForeground: true,
fullScreenIntent: true,
id: subId!,
channelKey: "alarm_Category",
title: 'Alarm Reminder',
body: 'Your alarm is still active!',
autoDismissible: false,
payload: receivedNotification.payload,
),
);
});
}
Upvotes: 0
Views: 21