sendNotification static method

Future<void> sendNotification({
  1. required String title,
  2. required String body,
  3. String? payload,
  4. DateTime? at,
  5. int? id,
  6. String? subtitle,
  7. int? badgeNumber,
  8. String? sound,
  9. AndroidNotificationConfig? androidConfig,
  10. IOSNotificationConfig? iosConfig,
  11. 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);
}