createNotification method

  1. @override
Future<bool> createNotification({
  1. required NotificationContent content,
  2. List<NotificationActionButton>? actionButtons,
  3. List<NotificationExtension>? extensions,
})
override

LOCAL NOTIFICATION METHODS ********************************************* Creates a new notification with the specified content.

The content parameter is a NotificationContent object that represents the content of the notification, including the title, body, icon, and other details.

The optional actionButtons parameter is a list of NotificationActionButton objects that represent the action buttons to be displayed on the notification.

This method returns a Future that resolves to true if the notification was successfully created, or false if an error occurred.

If the notification has no body or title, it will be created but not displayed (i.e. it will be a "background" notification).

This method is typically used to create a new notification with the specified content. If an action button or buttons are provided, they will be displayed on the notification to allow the user to take specific actions in response to the notification.

The optional extensions let opt-in add-on packages attach extra data to the notification — for example scheduling via the awesome_notifications_schedules package (NotificationCalendar / NotificationInterval), or per-language translations via the awesome_notifications_localizations package (NotificationLocalizations).

Implementation

@override
Future<bool> createNotification({
  required NotificationContent content,
  List<NotificationActionButton>? actionButtons,
  List<NotificationExtension>? extensions,
}) async {
  validateId(content.id!);

  final Map<String, dynamic> data = NotificationModel(
    content: content,
    actionButtons: actionButtons,
  ).toMap();

  // Merge whatever add-on extensions contribute (e.g. scheduling,
  // localizations). The core doesn't know what these are — it just forwards
  // the extra map entries as siblings of content/actionButtons.
  for (final extension in extensions ?? const <NotificationExtension>[]) {
    data.addAll(extension.toMap());
  }

  final bool wasCreated = await methodChannel.invokeMethod(
      CHANNEL_METHOD_CREATE_NOTIFICATION, data);

  return wasCreated;
}