sendNotification static method
dynamic
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,
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);
}