Notice: You're viewing an old version of the Nylo Website documentation. Consider upgrading your project to Nylo Website 7.x.
Advanced
Push Notifications
Introduction
The Push Notification system in Nylo provides a powerful way to send local notifications to users. This feature allows you to send immediate or scheduled notifications with rich content and customizable behaviors for both iOS and Android platforms.
Basic Usage
Here's how to send a basic push notification:
// Simple notification
await PushNotification(
title: "Hello",
body: "This is a basic notification"
).send();
// Using the helper function
await pushNotification("Hello", "This is a basic notification").send();
// Using the static method
await PushNotification.sendNotification(
title: "Hello",
body: "This is a basic notification"
);
Scheduled Notifications
You can schedule notifications to be delivered at a specific time:
// Schedule a notification for tomorrow
final tomorrow = DateTime.now().add(Duration(days: 1));
await PushNotification(
title: "Reminder",
body: "Don't forget your appointment!"
).send(at: tomorrow);
// Using the static method
await PushNotification.sendNotification(
title: "Reminder",
body: "Don't forget your appointment!",
at: tomorrow
);
Customizing Notifications
Adding Attachments
await PushNotification(
title: "New Photo",
body: "Check out this image!"
)
.addAttachment(
"https://example.com/image.jpg",
"photo.jpg"
)
.send();
final actions = [
AndroidNotificationAction(
'accept',
'Accept',
showsUserInterface: true,
),
AndroidNotificationAction(
'decline',
'Decline',
showsUserInterface: true,
),
];
await PushNotification(
title: "Meeting Request",
body: "Would you like to attend?"
)
.addActions(actions)
.send();
## Platform Specific Features
iOS Specific Features
await PushNotification(
title: "iOS Notification",
body: "This is an iOS specific notification"
)
.addBadgeNumber(1)
.addSound("custom_sound.wav")
.addThreadIdentifier("thread_1")
.addInterruptionLevel(InterruptionLevel.active)
.send();
Android Specific Features
await PushNotification(
title: "Android Notification",
body: "This is an Android specific notification"
)
.addChannelId("custom_channel")
.addChannelName("Custom Channel")
.addChannelDescription("Notifications from custom channel")
.addVibrationPattern([0, 1000, 500, 1000])
.addLedColor(Color(0xFF00FF00))
.send();
Managing Notifications
You can cancel specific notifications or all notifications, as well as request permissions for notifications.
Canceling Notifications
// Cancel a specific notification
await PushNotification.cancelNotification(1);
// Cancel all notifications
await PushNotification.cancelAllNotifications();