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.
I created an example for Daily Notification at 11:59:10 PM
(Exclude "repeats : true" if you don't want to repeat daily)
And Even You can specify these: [millisecond, weekday , weekofmonth , weekofyear ]
schedule: NotificationCalendar(
hour: 23,
minute: 59,
second: 10,
repeats: true
)
I checked its working fine :)
Complete Code :
AwesomeNotifications().createNotification(
content: NotificationContent(
id: 13,
channelKey: 'channelKey',
title: 'title',
body: 'this is body'),
schedule: NotificationCalendar(
hour: 23,
minute: 59,
second: 10,
repeats: true
)
);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With