sendNotification static method
Future<void>
sendNotification({
- required String title,
- required String body,
- String? payload,
- DateTime? at,
- int? id,
- String? subtitle,
- int? badgeNumber,
- String? sound,
- AndroidNotificationConfig? androidConfig,
- IOSNotificationConfig? iosConfig,
- AndroidScheduleMode? androidScheduleMode,
Sends a notification with the specified parameters.
This is a convenience method that creates a LocalNotification, configures it with the provided parameters, and sends it.
Example:
await LocalNotification.sendNotification(
title: 'Hello',
body: 'World',
payload: 'custom-data',
);
Implementation
static Future<void> sendNotification({
required String title,
required String body,
String? payload,
DateTime? at,
int? id,
String? subtitle,
int? badgeNumber,
String? sound,
AndroidNotificationConfig? androidConfig,
IOSNotificationConfig? iosConfig,
AndroidScheduleMode? androidScheduleMode,
}) async {
_assertNotWeb();
final notification = LocalNotification(title: title, body: body);
_applyIfNotNull(payload, notification.addPayload);
_applyIfNotNull(id, notification.addId);
_applyIfNotNull(subtitle, notification.addSubtitle);
_applyIfNotNull(badgeNumber, notification.addBadgeNumber);
_applyIfNotNull(sound, notification.addSound);
if (androidConfig != null) {
notification.setAndroidConfig(androidConfig);
}
if (iosConfig != null) {
notification.setIOSConfig(iosConfig);
}
await notification.send(at: at, androidScheduleMode: androidScheduleMode);
}