I'm working in an app and I need to implement local notification based on user input. This means that the user will select when the app shows the notification. I found the method repeatInterval, but it only offers fixed time intervals such as
everyMinute → const RepeatInterval
hourly → const RepeatInterval
daily → const RepeatInterval
weekly → const RepeatInterval
I don't need these options, because they are fixed. I need to add a notification, and the interval on runtime.
I tried with,
NotificationDetails notificationDetails =
NotificationDetails(android: androidNotificationDetails);
await _flutterLocalNotificationsPlugin.zonedSchedule(
-1,
title,
body,
tz.TZDateTime.from(
DateTime.now().add(const Duration(hours: hours)),
tz.local
),
androidAllowWhileIdle: true,
notificationDetails,
uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime
);
With this method I was able to pass manually the first notification, but I need to repeat the notification X times until the user cancel the notification.
Any ideas?
The flutter_local_notifications
plugin does not provide this functionality by itself. You have the following options.
periodically_show
function. The android implementation and iOS implementation of periodically_show
internally support any time interval. It's just the API design of the plugin that choses to hide this functionality.flutter_local_notifications
with a background worker library WorkerManager
that allows your app to execute some functionality in the background. On each call you could schedule a notification.I think such functionality would make a great contribution to the flutter_local_notifications
library.