How to schedule notification at specific time using awesome package in Flutter?

729

The same plugin provides a way to schedule notifications as per the need.

Checkout this link from it's description: https://pub.dev/packages/awesome_notifications#scheduling-a-notification

Bascially showing it at a specific time will look something like this:

 await AwesomeNotifications().createNotification(
  content: NotificationContent(
    id: id,
    channelKey: 'scheduled',
    title: 'Just in time!',
    body: 'This notification was schedule to shows at ' +
        (Utils.DateUtils.parseDateToString(scheduleTime.toLocal()) ?? '?') +
        ' $timeZoneIdentifier (' +
        (Utils.DateUtils.parseDateToString(scheduleTime.toUtc()) ?? '?') +
        ' utc)',
    notificationLayout: NotificationLayout.BigPicture,
    bigPicture: 'asset://assets/images/delivery.jpeg',
    payload: {'uuid': 'uuid-test'},
    autoCancel: false,
  ),
  schedule: NotificationCalendar.fromDate(date: scheduleTime));

Note: The code sample is from the plugin's Readme. I have not tested this yet.

Share:
729
Abdelrahman Bahig
Author by

Abdelrahman Bahig

Updated on December 01, 2022

Comments

  • Abdelrahman Bahig
    Abdelrahman Bahig over 1 year

    I am using an awesome Package and am trying to make a notification at a specific time using this package.

    Future<void> showNotificationWithIconsAndActionButtons(int id) async {
        AwesomeNotifications().initialize(
            '',
            [
              NotificationChannel(
                  channelKey: 'basic_channel',
                  channelName: 'Basic notifications',
                  channelDescription: 'Notification channel for basic tests',
                  defaultColor: Color(0xFF9D50DD),
                  ledColor: Colors.white,
                playSound: true,
    
                importance: NotificationImportance.Max,
                defaultRingtoneType: DefaultRingtoneType.Notification,
    
              )
            ]
        );
     
        await AwesomeNotifications().createNotification(
    
            content: NotificationContent(
                id: id,
                channelKey: 'basic_channel',
                title: 'Anonymous says:',
                body: 'Hi there!',
                payload: {'uuid': 'user-profile-uuid'},
              displayOnBackground: true,
              displayOnForeground: true,
    
                ),
            
         
    

    i need to make notification in particular time.

  • Abdelrahman Bahig
    Abdelrahman Bahig almost 3 years
    how to add action buttons to this function. i tried this and it give me error
  • Abdelrahman Bahig
    Abdelrahman Bahig almost 3 years
    i need both schedule at specific time and action buttons
  • Tushar Patel
    Tushar Patel over 2 years
    how to pass a valid schedule date? I pass DateTime.no() and it gave me a run time error like a date is not more valid.
  • Harshvardhan Joshi
    Harshvardhan Joshi over 2 years
    @TusharPatel I think DateTime.now() is not valid because when the Notification must have been scheduled the time has passed to show it. You should pass the Date & Time value when you want to show it not the current date time. Add a few minutes to check if it works or not.
  • Tushar Patel
    Tushar Patel over 2 years
    okay, I'll look for it. Thank you.
  • MNBWorld
    MNBWorld about 2 years
    I have same problem here. Please reply here to help me: stackoverflow.com/q/71299531/17411652