Reputation: 124
I want to trigger a local Notification daily on a specific time(Chosen by user). Similar to alarm type. With the help of date picker. User must select the days and time, it should push a local Notification on that time daily.
Upvotes: 2
Views: 1278
Reputation: 8246
Assuming you have already preset flutter_local_notification
you can go ahead and do it as follows
DateTime scheduledTime
handles date time allocation
import 'package:flutter_local_notifications/flutter_local_notifications.dart'as notifs;
Future<void> scheduleNotification(
{notifs.FlutterLocalNotificationsPlugin notifsPlugin,
String id,
String title,
String body,
DateTime scheduledTime}) async {
var androidSpecifics = notifs.AndroidNotificationDetails(
id, // This specifies the ID of the Notification
'Scheduled notification', // This specifies the name of the notification channel
'A scheduled notification', //This specifies the description of the channel
icon: 'icon',
);
var iOSSpecifics = notifs.IOSNotificationDetails();
var platformChannelSpecifics = notifs.NotificationDetails(
androidSpecifics, iOSSpecifics);
await notifsPlugin.schedule(0, title, "Scheduled notification",
scheduledTime, platformChannelSpecifics); // This literally schedules the notification
}
How will user choose the date(for how many days local notification should be triggered daily on a specific time
you can use datetime picker to select date if its a one occurrence notification
if it has to occur on different days same time , you can use a workmanager and run every 24 hrs and end the services after no of frequencies are over
check this blog post
Upvotes: 2