showNotificationWithActions method

  1. @override
Future<int> showNotificationWithActions({
  1. required String title,
  2. required String message,
  3. required List<Map<String, String>> actions,
  4. String? channelId,
  5. NotificationImportance? importance,
  6. bool? autoCancel,
  7. String? targetScreen,
  8. Map<String, dynamic>? extraData,
})
override

Show a notification with custom actions.

Implementation

@override
Future<int> showNotificationWithActions({
  required String title,
  required String message,
  required List<Map<String, String>> actions,
  String? channelId,
  NotificationImportance? importance,
  bool? autoCancel,
  String? targetScreen,
  Map<String, dynamic>? extraData,
}) async {
  try {
    // Check if the browser supports notifications
    if (!_isNotificationSupported()) {
      return -1;
    }

    if (web.Notification.permission == 'granted') {
      // Convert actions to NotificationAction objects if supported
      final options = web.NotificationOptions(
        body: message,
        // Note: actions are part of Service Worker notifications
        // For basic notifications, we'll just show the message
      );
      final notification = web.Notification(title, options);
      return 1; // Return a notification ID
    }
    return -1; // Failed to show notification
  } catch (e) {
    return -1; // Failed to show notification
  }
}