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. 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,
  59. AndroidScheduleMode? androidScheduleMode,
})

Send a notification Example:

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

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

Implementation

static Future<void> 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,
  AndroidScheduleMode? androidScheduleMode,
}) async {
  JetNotifications jetNotification = JetNotifications(
    title: title,
    body: body,
  );

  if (kIsWeb) {
    throw Exception("Push notifications are not supported on the web");
  }

  if (Platform.isAndroid) {
    if (channelId == null) {
      jetNotification.addChannelId("default_channel");
    }
    if (channelName == null) {
      jetNotification.addChannelName("Default Channel");
    }
    if (channelDescription == null) {
      jetNotification.addChannelDescription("Default Channel");
    }
    if (importance == null) {
      jetNotification.addImportance(Importance.max);
    }
    if (priority == null) {
      jetNotification.addPriority(Priority.high);
    }
    if (ticker == null) {
      jetNotification.addTicker("ticker");
    }
    if (icon == null) {
      jetNotification.addIcon("@mipmap/ic_launcher");
    }
    if (playSound == null) {
      jetNotification.addPlaySound(true);
    }
    if (enableVibration == null) {
      jetNotification.addEnableVibration(true);
    }
    if (groupAlertBehavior == null) {
      jetNotification.addGroupAlertBehavior(GroupAlertBehavior.all);
    }
    if (autoCancel == null) {
      jetNotification.addAutoCancel(true);
    }
    if (showWhen == null) {
      jetNotification.addShowWhen(true);
    }
    if (channelShowBadge == null) {
      jetNotification.addChannelShowBadge(true);
    }
  }

  if (payload != null) {
    jetNotification.addPayload(payload);
  }
  if (id != null) {
    jetNotification.addId(id);
  }
  if (subtitle != null) {
    jetNotification.addSubtitle(subtitle);
  }
  if (badgeNumber != null) {
    jetNotification.addBadgeNumber(badgeNumber);
  }
  if (sound != null) {
    jetNotification.addSound(sound);
  }
  if (channelId != null) {
    jetNotification.addChannelId(channelId);
  }
  if (channelName != null) {
    jetNotification.addChannelName(channelName);
  }
  if (channelDescription != null) {
    jetNotification.addChannelDescription(channelDescription);
  }
  if (importance != null) {
    jetNotification.addImportance(importance);
  }
  if (priority != null) {
    jetNotification.addPriority(priority);
  }
  if (ticker != null) {
    jetNotification.addTicker(ticker);
  }
  if (icon != null) {
    jetNotification.addIcon(icon);
  }
  if (playSound != null) {
    jetNotification.addPlaySound(playSound);
  }
  if (enableVibration != null) {
    jetNotification.addEnableVibration(enableVibration);
  }
  if (vibrationPattern != null) {
    jetNotification.addVibrationPattern(vibrationPattern);
  }
  if (groupKey != null) {
    jetNotification.addGroupKey(groupKey);
  }
  if (setAsGroupSummary != null) {
    jetNotification.addSetAsGroupSummary(setAsGroupSummary);
  }
  if (groupAlertBehavior != null) {
    jetNotification.addGroupAlertBehavior(groupAlertBehavior);
  }
  if (autoCancel != null) {
    jetNotification.addAutoCancel(autoCancel);
  }
  if (ongoing != null) {
    jetNotification.addOngoing(ongoing);
  }
  if (silent != null) {
    jetNotification.addSilent(silent);
  }
  if (color != null) {
    jetNotification.addColor(color);
  }
  if (largeIcon != null) {
    jetNotification.addLargeIcon(largeIcon);
  }
  if (onlyAlertOnce != null) {
    jetNotification.addOnlyAlertOnce(onlyAlertOnce);
  }
  if (showWhen != null) {
    jetNotification.addShowWhen(showWhen);
  }
  if (when != null) {
    jetNotification.addWhen(when);
  }
  if (usesChronometer != null) {
    jetNotification.addUsesChronometer(usesChronometer);
  }
  if (chronometerCountDown != null) {
    jetNotification.addChronometerCountDown(chronometerCountDown);
  }
  if (channelShowBadge != null) {
    jetNotification.addChannelShowBadge(channelShowBadge);
  }
  if (showProgress != null) {
    jetNotification.addShowProgress(showProgress);
  }
  if (maxProgress != null) {
    jetNotification.addMaxProgress(maxProgress);
  }
  if (progress != null) {
    jetNotification.addProgress(progress);
  }
  if (indeterminate != null) {
    jetNotification.addIndeterminate(indeterminate);
  }
  if (channelAction != null) {
    jetNotification.addChannelAction(channelAction);
  }
  if (enableLights != null) {
    jetNotification.addEnableLights(enableLights);
  }
  if (ledColor != null) {
    jetNotification.addLedColor(ledColor);
  }
  if (ledOnMs != null) {
    jetNotification.addLedOnMs(ledOnMs);
  }
  if (ledOffMs != null) {
    jetNotification.addLedOffMs(ledOffMs);
  }
  if (visibility != null) {
    jetNotification.addVisibility(visibility);
  }
  if (timeoutAfter != null) {
    jetNotification.addTimeoutAfter(timeoutAfter);
  }
  if (fullScreenIntent != null) {
    jetNotification.addFullScreenIntent(fullScreenIntent);
  }
  if (shortcutId != null) {
    jetNotification.addShortcutId(shortcutId);
  }
  if (additionalFlags != null) {
    jetNotification.addAdditionalFlags(additionalFlags);
  }
  if (tag != null) {
    jetNotification.addTag(tag);
  }
  if (actions != null) {
    jetNotification.addActions(actions);
  }
  if (colorized != null) {
    jetNotification.addColorized(colorized);
  }
  if (audioAttributesUsage != null) {
    jetNotification.addAudioAttributesUsage(audioAttributesUsage);
  }
  if (presentList != null) {
    jetNotification.addPresentList(presentList);
  }
  if (presentAlert != null) {
    jetNotification.addPresentAlert(presentAlert);
  }
  if (presentBadge != null) {
    jetNotification.addPresentBadge(presentBadge);
  }
  if (presentSound != null) {
    jetNotification.addPresentSound(presentSound);
  }
  if (presentBanner != null) {
    jetNotification.addPresentBanner(presentBanner);
  }
  if (threadIdentifier != null) {
    jetNotification.addThreadIdentifier(threadIdentifier);
  }
  if (categoryIdentifier != null) {
    jetNotification.addCategoryIdentifier(categoryIdentifier);
  }
  if (interruptionLevel != null) {
    jetNotification.addInterruptionLevel(interruptionLevel);
  }

  await jetNotification.send(
    at: at,
    androidScheduleMode: androidScheduleMode,
  );
}