showLocalNotification method

Future<void> showLocalNotification(
  1. Message message, {
  2. String? title,
  3. String? body,
})

Shows a local notification for message when filters allow it.

Implementation

Future<void> showLocalNotification(
  Message message, {
  String? title,
  String? body,
}) async {
  if (!_enableLocalNotification || !_localNotificationReady) {
    return;
  }
  final plugin = _localNotifications;
  if (plugin == null) {
    return;
  }
  const details = NotificationDetails(
    android: AndroidNotificationDetails(
      'nexconn_chat_messages',
      'Messages',
      channelDescription: 'Nexconn Chat message notifications',
      importance: Importance.max,
      priority: Priority.high,
    ),
    iOS: DarwinNotificationDetails(),
    macOS: DarwinNotificationDetails(),
  );
  try {
    await plugin.show(
      (_messageIdOf(message) ??
              _clientIdOf(message)?.toString() ??
              message.hashCode.toString())
          .hashCode,
      title ?? _senderUserIdOf(message) ?? 'Nexconn Chat',
      body ?? messageSummary(message),
      details,
    );
  } catch (_) {
    // Local notification delivery is best effort across host app setups.
  }
}