showNotification method

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

Show a simple notification.

Implementation

@override
Future<int> showNotification({
  int? id,
  required String title,
  required String message,
  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') {
      final options = web.NotificationOptions(
        body: message,
        // Add more options as needed
      );
      final notification = web.Notification(title, options);
      return id ?? 1; // Return the provided ID or default to 1
    }
    return -1; // Failed to show notification
  } catch (e) {
    return -1; // Failed to show notification
  }
}