Local Schedule Notification in Flutter

324

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

Share:
324
Hadi Khan
Author by

Hadi Khan

Updated on December 31, 2022

Comments

  • Hadi Khan
    Hadi Khan over 1 year

    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.

  • griffins
    griffins over 2 years
    you can read more here medium.com/@fuzzymemory/…
  • Hadi Khan
    Hadi Khan over 2 years
    How will user choose the date(for how many days local notification should be triggered daily on a specific time)? I don't want it hardcoded. User must select the days with datepicker or something.