getConversationSubtitle method
Widget
getConversationSubtitle(
- Conversation conversation,
- BuildContext context,
- CometChatTheme theme,
- TextStyle? subtitleStyle, {
- 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;
Icon? messageIcon;
Text? messageText;
RichText? messageRichText;
// Set the correct icon for the last message type
switch (lastMessage?.type) {
case MessageTypeConstants.text:
messageIcon = const Icon(Icons.chat_bubble_outline, color: AppTheme.light, size: 17.0);
break;
case MessageTypeConstants.groupActions:
messageIcon = const Icon(Icons.group_outlined, color: AppTheme.light, size: 17.0);
break;
case MessageTypeConstants.image:
messageIcon = const Icon(Icons.image_outlined, color: AppTheme.light, size: 17.0);
break;
case MessageTypeConstants.video:
messageIcon = const Icon(Icons.video_file_outlined, color: AppTheme.light, size: 17.0);
break;
case MessageTypeConstants.file:
messageIcon = const Icon(Icons.insert_drive_file_outlined, color: AppTheme.light, size: 17.0);
break;
case MessageTypeConstants.audio:
messageIcon = const Icon(Icons.audio_file_outlined, color: AppTheme.light, size: 17.0);
break;
case 'extension_poll':
messageIcon = const Icon(Icons.poll_outlined, color: AppTheme.light, size: 15.0);
break;
case 'extension_sticker':
messageIcon = const Icon(Icons.poll_outlined, color: AppTheme.light, size: 15.0);
break;
case 'extension_document':
messageIcon = const Icon(Icons.file_present, color: AppTheme.light, size: 15.0);
break;
case 'extension_whiteboard':
messageIcon = const Icon(Icons.article, color: AppTheme.light, size: 15.0);
break;
default:
messageIcon = null;
}
// Retrieve the conversation text
String conversationText = getConversationSubtitleText(conversation, context, additionalConfigurations: additionalConfigurations) ?? '';
// Construct the message widget
if (additionalConfigurations != null &&
additionalConfigurations.textFormatters != null &&
additionalConfigurations.textFormatters!.isNotEmpty &&
lastMessage is TextMessage) {
messageRichText = RichText(
maxLines: 1,
overflow: TextOverflow.ellipsis,
text: TextSpan(
text: "",
style: subtitleStyle0,
children: FormatterUtils.buildTextSpan(
conversationText,
additionalConfigurations.textFormatters,
theme,
BubbleAlignment.left,
forConversation: true,
),
),
);
} else {
messageText = Text(
conversationText,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: subtitleStyle0,
);
}
return Row(
mainAxisSize: MainAxisSize.max,
children: [
if (messageIcon != null) messageIcon,
const SizedBox(width: 4),
(messageText ?? messageRichText)!,
],
);
}