import 'package:cometchat_chat_uikit/cometchat_chat_uikit.dart';
import 'package:flutter/material.dart';
class HashTagTextFormatter extends CometChatTextFormatter {
HashTagTextFormatter() : super(
trackingCharacter: '#',
pattern: RegExp(r'\B#(\w+)\b'),
showLoadingIndicator: false,
);
@override
void init() {
// Initialization logic
}
@override
void handlePreMessageSend(BuildContext context, BaseMessage baseMessage) {
// Process hashtags before sending
}
@override
TextStyle getMessageInputTextStyle(BuildContext context) {
CometChatColorPalette colorPalette = CometChatThemeHelper.getColorPalette(context);
return TextStyle(
color: colorPalette.primary,
fontWeight: FontWeight.w500,
);
}
@override
TextStyle getMessageBubbleTextStyle(
BuildContext context,
BubbleAlignment? alignment,
{bool forConversation = false}
) {
CometChatColorPalette colorPalette = CometChatThemeHelper.getColorPalette(context);
return TextStyle(
color: alignment == BubbleAlignment.right
? colorPalette.white
: colorPalette.primary,
fontWeight: FontWeight.bold,
decoration: TextDecoration.underline,
);
}
@override
void onScrollToBottom(TextEditingController textEditingController) {
// Handle scroll to bottom
}
@override
void onChange(TextEditingController textEditingController, String previousText) {
// Handle text changes - detect new hashtags
String currentText = textEditingController.text;
if (currentText.contains('#')) {
// Process hashtag
}
}
@override
List<AttributedText> getAttributedText(
String text,
BuildContext context,
BubbleAlignment? alignment,
{List<AttributedText>? existingAttributes,
Function(String)? onTap,
bool forConversation = false}
) {
return super.getAttributedText(
text,
context,
alignment,
existingAttributes: existingAttributes,
onTap: onTap ?? (hashtag) {
// Handle hashtag tap - e.g., search for hashtag
print('Tapped hashtag: $hashtag');
},
forConversation: forConversation,
);
}
}