getConversationSubtitle method

  1. @override
Widget getConversationSubtitle(
  1. Conversation conversation,
  2. BuildContext context,
  3. CometChatTheme theme,
  4. TextStyle? subtitleStyle, {
  5. AdditionalConfigurations? additionalConfigurations,
})
override

override this to change the widget shown for subtitle in conversations

Implementation

@override
Widget getConversationSubtitle(Conversation conversation,
    BuildContext context, CometChatTheme theme, TextStyle? subtitleStyle,
    {AdditionalConfigurations? additionalConfigurations}) {
  TextStyle subtitleStyle0 = subtitleStyle ??
      TextStyle(
          color: theme.palette.getAccent600(),
          fontSize: theme.typography.subtitle1.fontSize,
          fontWeight: theme.typography.subtitle1.fontWeight,
          fontFamily: theme.typography.subtitle1.fontFamily);

  BaseMessage? lastMessage = conversation.lastMessage;
  String? messageCategory = lastMessage?.category;

  if (messageCategory == null || lastMessage == null) {
    return Text(
      "",
      maxLines: 1,
      overflow: TextOverflow.ellipsis,
      style: subtitleStyle0,
    );
  } else if (lastMessage.deletedBy != null &&
      lastMessage.deletedBy!.trim() != '') {
    return Text(
      Translations.of(context).thisMessageDeleted,
      maxLines: 1,
      overflow: TextOverflow.ellipsis,
      style: subtitleStyle0,
    );
  } else {
    String? prefix;
    if (conversation.conversationWith is Group) {
      if (lastMessage.sender?.uid != CometChatUIKit.loggedInUser?.uid) {
        prefix = "${lastMessage.sender?.name}: ";
      } else {
        prefix = "${cc.Translations.of(context).you}: ";
      }
    }

    if (additionalConfigurations != null &&
        additionalConfigurations.textFormatters != null &&
        additionalConfigurations.textFormatters!.isNotEmpty &&
        lastMessage is TextMessage) {
      String text = (lastMessage).text;

      return RichText(
        maxLines: 1,
        overflow: TextOverflow.ellipsis,
        text: TextSpan(
          text: prefix,
          style: subtitleStyle0,
          children: FormatterUtils.buildTextSpan(
              text,
              additionalConfigurations.textFormatters,
              theme,
              BubbleAlignment.left,
              forConversation: true),
        ),
      );
    } else {
      String? text;

      text =
          "${prefix ?? ""}${CometChatUIKit.getDataSource().getLastConversationMessage(conversation, context)}";

      return Text(
        text,
        maxLines: 1,
        overflow: TextOverflow.ellipsis,
        style: subtitleStyle0,
      );
    }
  }
}