sendNotification static method

dynamic 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. String? channelId,
  10. String? channelName,
  11. String? channelDescription,
  12. Importance? importance,
  13. Priority? priority,
  14. String? ticker,
  15. String? icon,
  16. bool? playSound,
  17. bool? enableVibration,
  18. List<int>? vibrationPattern,
  19. String? groupKey,
  20. bool? setAsGroupSummary,
  21. GroupAlertBehavior? groupAlertBehavior,
  22. bool? autoCancel,
  23. bool? ongoing,
  24. bool? silent,
  25. Color? color,
  26. String? largeIcon,
  27. bool? onlyAlertOnce,
  28. bool? showWhen,
  29. int? when,
  30. bool? usesChronometer,
  31. bool? chronometerCountDown,
  32. bool? channelShowBadge,
  33. bool? showProgress,
  34. int? maxProgress,
  35. int? progress,
  36. bool? indeterminate,
  37. AndroidNotificationChannelAction? channelAction,
  38. bool? enableLights,
  39. Color? ledColor,
  40. int? ledOnMs,
  41. int? ledOffMs,
  42. NotificationVisibility? visibility,
  43. int? timeoutAfter,
  44. bool? fullScreenIntent,
  45. String? shortcutId,
  46. List<int>? additionalFlags,
  47. String? tag,
  48. List<AndroidNotificationAction>? actions,
  49. bool? colorized,
  50. AudioAttributesUsage? audioAttributesUsage,
  51. bool? presentList,
  52. bool? presentAlert,
  53. bool? presentBadge,
  54. bool? presentSound,
  55. bool? presentBanner,
  56. String? threadIdentifier,
  57. String? categoryIdentifier,
  58. InterruptionLevel? interruptionLevel,
})

Send a notification Example:

PushNotification.sendNotification(
 title: "Hello",
 body: "World",
 );

This will send a notification with the title "Hello" and the body "World"

Implementation

static sendNotification({
  required String title,
  required String body,
  String? payload,
  DateTime? at,
  int? id,
  String? subtitle,
  int? badgeNumber,
  String? sound,
  String? channelId,
  String? channelName,
  String? channelDescription,
  Importance? importance,
  Priority? priority,
  String? ticker,
  String? icon,
  bool? playSound,
  bool? enableVibration,
  List<int>? vibrationPattern,
  String? groupKey,
  bool? setAsGroupSummary,
  GroupAlertBehavior? groupAlertBehavior,
  bool? autoCancel,
  bool? ongoing,
  bool? silent,
  Color? color,
  String? largeIcon,
  bool? onlyAlertOnce,
  bool? showWhen,
  int? when,
  bool? usesChronometer,
  bool? chronometerCountDown,
  bool? channelShowBadge,
  bool? showProgress,
  int? maxProgress,
  int? progress,
  bool? indeterminate,
  AndroidNotificationChannelAction? channelAction,
  bool? enableLights,
  Color? ledColor,
  int? ledOnMs,
  int? ledOffMs,
  NotificationVisibility? visibility,
  int? timeoutAfter,
  bool? fullScreenIntent,
  String? shortcutId,
  List<int>? additionalFlags,
  String? tag,
  List<AndroidNotificationAction>? actions,
  bool? colorized,
  AudioAttributesUsage? audioAttributesUsage,
  bool? presentList,
  bool? presentAlert,
  bool? presentBadge,
  bool? presentSound,
  bool? presentBanner,
  String? threadIdentifier,
  String? categoryIdentifier,
  InterruptionLevel? interruptionLevel,
}) async {
  PushNotification pushNotification = PushNotification(
    title: title,
    body: body,
  );
  if (Platform.isAndroid) {
    if (channelId == null) {
      pushNotification.addChannelId("default_channel");
    }
    if (channelName == null) {
      pushNotification.addChannelName("Default Channel");
    }
    if (channelDescription == null) {
      pushNotification.addChannelDescription("Default Channel");
    }
    if (importance == null) {
      pushNotification.addImportance(Importance.max);
    }
    if (priority == null) {
      pushNotification.addPriority(Priority.high);
    }
    if (ticker == null) {
      pushNotification.addTicker("ticker");
    }
    if (icon == null) {
      pushNotification.addIcon("app_icon");
    }
    if (playSound == null) {
      pushNotification.addPlaySound(true);
    }
    if (enableVibration == null) {
      pushNotification.addEnableVibration(true);
    }
    if (groupAlertBehavior == null) {
      pushNotification.addGroupAlertBehavior(GroupAlertBehavior.all);
    }
    if (autoCancel == null) {
      pushNotification.addAutoCancel(true);
    }
    if (showWhen == null) {
      pushNotification.addShowWhen(true);
    }
    if (channelShowBadge == null) {
      pushNotification.addChannelShowBadge(true);
    }
  }
  if (payload != null) {
    pushNotification.addPayload(payload);
  }
  if (at != null) {
    pushNotification.send(at: at);
  }
  if (id != null) {
    pushNotification.addId(id);
  }
  if (subtitle != null) {
    pushNotification.addSubtitle(subtitle);
  }
  if (badgeNumber != null) {
    pushNotification.addBadgeNumber(badgeNumber);
  }
  if (sound != null) {
    pushNotification.addSound(sound);
  }
  if (channelId != null) {
    pushNotification.addChannelId(channelId);
  }
  if (channelName != null) {
    pushNotification.addChannelName(channelName);
  }
  if (channelDescription != null) {
    pushNotification.addChannelDescription(channelDescription);
  }
  if (importance != null) {
    pushNotification.addImportance(importance);
  }
  if (priority != null) {
    pushNotification.addPriority(priority);
  }
  if (ticker != null) {
    pushNotification.addTicker(ticker);
  }
  if (icon != null) {
    pushNotification.addIcon(icon);
  }
  if (playSound != null) {
    pushNotification.addPlaySound(playSound);
  }
  if (enableVibration != null) {
    pushNotification.addEnableVibration(enableVibration);
  }
  if (vibrationPattern != null) {
    pushNotification.addVibrationPattern(vibrationPattern);
  }
  if (groupKey != null) {
    pushNotification.addGroupKey(groupKey);
  }
  if (setAsGroupSummary != null) {
    pushNotification.addSetAsGroupSummary(setAsGroupSummary);
  }
  if (groupAlertBehavior != null) {
    pushNotification.addGroupAlertBehavior(groupAlertBehavior);
  }
  if (autoCancel != null) {
    pushNotification.addAutoCancel(autoCancel);
  }
  if (ongoing != null) {
    pushNotification.addOngoing(ongoing);
  }
  if (silent != null) {
    pushNotification.addSilent(silent);
  }
  if (color != null) {
    pushNotification.addColor(color);
  }
  if (largeIcon != null) {
    pushNotification.addLargeIcon(largeIcon);
  }
  if (onlyAlertOnce != null) {
    pushNotification.addOnlyAlertOnce(onlyAlertOnce);
  }
  if (showWhen != null) {
    pushNotification.addShowWhen(showWhen);
  }
  if (when != null) {
    pushNotification.addWhen(when);
  }
  if (usesChronometer != null) {
    pushNotification.addUsesChronometer(usesChronometer);
  }
  if (chronometerCountDown != null) {
    pushNotification.addChronometerCountDown(chronometerCountDown);
  }
  if (channelShowBadge != null) {
    pushNotification.addChannelShowBadge(channelShowBadge);
  }
  if (showProgress != null) {
    pushNotification.addShowProgress(showProgress);
  }
  if (maxProgress != null) {
    pushNotification.addMaxProgress(maxProgress);
  }
  if (progress != null) {
    pushNotification.addProgress(progress);
  }
  if (indeterminate != null) {
    pushNotification.addIndeterminate(indeterminate);
  }
  if (channelAction != null) {
    pushNotification.addChannelAction(channelAction);
  }
  if (enableLights != null) {
    pushNotification.addEnableLights(enableLights);
  }
  if (ledColor != null) {
    pushNotification.addLedColor(ledColor);
  }
  if (ledOnMs != null) {
    pushNotification.addLedOnMs(ledOnMs);
  }
  if (ledOffMs != null) {
    pushNotification.addLedOffMs(ledOffMs);
  }
  if (visibility != null) {
    pushNotification.addVisibility(visibility);
  }
  if (timeoutAfter != null) {
    pushNotification.addTimeoutAfter(timeoutAfter);
  }
  if (fullScreenIntent != null) {
    pushNotification.addFullScreenIntent(fullScreenIntent);
  }
  if (shortcutId != null) {
    pushNotification.addShortcutId(shortcutId);
  }
  if (additionalFlags != null) {
    pushNotification.addAdditionalFlags(additionalFlags);
  }
  if (tag != null) {
    pushNotification.addTag(tag);
  }
  if (actions != null) {
    pushNotification.addActions(actions);
  }
  if (colorized != null) {
    pushNotification.addColorized(colorized);
  }
  if (audioAttributesUsage != null) {
    pushNotification.addAudioAttributesUsage(audioAttributesUsage);
  }
  if (presentList != null) {
    pushNotification.addPresentList(presentList);
  }
  if (presentAlert != null) {
    pushNotification.addPresentAlert(presentAlert);
  }
  if (presentBadge != null) {
    pushNotification.addPresentBadge(presentBadge);
  }
  if (presentSound != null) {
    pushNotification.addPresentSound(presentSound);
  }
  if (presentBanner != null) {
    pushNotification.addPresentBanner(presentBanner);
  }
  if (threadIdentifier != null) {
    pushNotification.addThreadIdentifier(threadIdentifier);
  }
  if (categoryIdentifier != null) {
    pushNotification.addCategoryIdentifier(categoryIdentifier);
  }
  if (interruptionLevel != null) {
    pushNotification.addInterruptionLevel(interruptionLevel);
  }
  await pushNotification.send(at: at);
}