showNotification method

  1. @override
Future<int?> showNotification(
  1. RemoteMessage message
)
override

Implementation

@override
Future<int?> showNotification(RemoteMessage message) async {
  await _ensureChannelsInitialized();
  final config = _config ??= NotificationConfig.defaultConfig();
  final id = _stableId(message.messageId);
  final title =
      message.notification?.title ?? message.data['title'] ?? 'New Message';
  final body = message.notification?.body ??
      message.data['body'] ??
      'You have a new message.';
  try {
    await _awesome.createNotification(
      content: NotificationContent(
        id: id,
        channelKey: config.channelKey,
        title: title,
        body: body,
        payload: _convertPayload(message.data),
        color: config.defaultColor,
        icon: config.androidNotificationIcon,
        wakeUpScreen: config.wakeUpScreen,
        category: config.category,
      ),
    );
    _logger.d('Local notification created for FCM: ${message.messageId}');
    return id;
  } catch (e, st) {
    _logger.e('Error showing notification from FCM: $e');
    onError?.call(e, st);
    return null;
  }
}