show method

Future<int> show({
  1. required String title,
  2. required String body,
  3. String? payload,
  4. String? channelId,
  5. String channelName = 'General',
  6. NotificationImportance importance = NotificationImportance.high,
  7. int? id,
})

Displays a local notification with title, body, and optional payload.

Returns the integer ID assigned to the notification.

Example:

final id = await notifications.show(
  title: 'Build Complete',
  body: 'Your artifact is ready for download.',
  channelId: 'builds',
);

Implementation

Future<int> show({
  required String title,
  required String body,
  String? payload,
  String? channelId,
  String channelName = 'General',
  NotificationImportance importance = NotificationImportance.high,
  int? id,
}) async {
  final notificationId = id ?? _idCounter++;

  final notificationDetails = NotificationDetails(
    android: AndroidNotificationDetails(
      channelId ?? 'default_channel',
      channelName,
      importance: importance.importance,
      priority: importance.priority,
    ),
    iOS: const DarwinNotificationDetails(
      presentAlert: true,
      presentBadge: true,
      presentSound: true,
    ),
  );

  logger.info('BloomNotifications: Displaying notification [$notificationId] "$title"');
  try {
    await _plugin.show(
      notificationId,
      title,
      body,
      notificationDetails,
      payload: payload,
    );
  } catch (e) {
    logger.warn('BloomNotifications: Notification display note: $e');
  }
  return notificationId;
}