LocalNotification class
A class for creating and sending local notifications on iOS and Android.
This class provides a fluent builder API for configuring notifications, as well as static methods for common operations.
Example usage with builder pattern:
await LocalNotification(title: 'Hello', body: 'World')
.addPayload('custom-data')
.addId(123)
.send();
Example usage with static method:
await LocalNotification.sendNotification(
title: 'Hello',
body: 'World',
payload: 'custom-data',
);
Constructors
- LocalNotification({String title = '', String body = ''})
-
Creates a LocalNotification with the given
titleandbody.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addAttachment(
String url, String fileName, {bool? showThumbnail}) → LocalNotification - Adds an attachment to the notification.
-
addBadgeNumber(
int badgeNumber) → LocalNotification - Sets the badge number for the notification.
-
addId(
int id) → LocalNotification - Sets the notification ID.
-
addPayload(
String payload) → LocalNotification - Sets the payload data for the notification.
-
addSound(
String sound) → LocalNotification - Sets the sound for the notification.
-
addSubtitle(
String subtitle) → LocalNotification - Sets the subtitle for the notification.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
send(
{DateTime? at, AndroidScheduleMode? androidScheduleMode}) → Future< void> - Sends the notification.
-
setAndroidConfig(
AndroidNotificationConfig config) → LocalNotification - Sets the Android-specific configuration.
-
setIOSConfig(
IOSNotificationConfig config) → LocalNotification - Sets the iOS-specific configuration.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
cancelAllNotifications(
) → Future< void> - Cancels all notifications.
-
cancelNotification(
int id, {String? tag}) → Future< void> -
Cancels a notification with the given
id. -
clearBadgeCount(
) → Future< void> - Clears the badge count on iOS.
-
requestPermissions(
{bool alert = true, bool badge = true, bool sound = true, bool provisional = false, bool critical = false, bool vibrate = true, bool enableLights = true, String channelId = 'default_notification_channel_id', String channelName = 'Default Notification Channel', String? description, String? groupId, Importance? importance, List< int> ? vibratePattern, Color? ledColor, AudioAttributesUsage? audioAttributesUsage}) → Future<void> - Requests notification permissions from the user.
-
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}) → Future< void> - Sends a notification with the specified parameters.