AI Agent Component Spec
AI Agent Component Spec
| Field | Value |
|---|---|
| Package | cometchat_chat_uikit |
| Key class | CometChatTextFormatter (abstract base class for custom formatters) |
| Required setup | CometChatUIKit.init(uiKitSettings: uiKitSettings) then CometChatUIKit.login("UID") |
| Purpose | Extend to create custom inline text patterns with regex, styling, and callbacks |
| Features | Text formatting, customizable styles, dynamic text replacement, input field integration |
| Sample app | GitHub |
| Related | ShortCut Formatter | Mentions Formatter | All Guides |
CometChatTextFormatter is an abstract class for formatting text in the message composer and message bubbles. Extend it to build custom formatters — hashtags, keywords, or any regex-based pattern.
| Capability | Description |
|---|---|
| Text formatting | Auto-format text based on regex patterns and styles |
| Custom styles | Set colors, fonts, and backgrounds for matched text |
| Dynamic replacement | Regex-based find-and-replace in user input |
| Input integration | Real-time monitoring of the composer input field |
| Attributed text | Build styled text spans for message bubbles |
Steps
1. Import the base class
2. Extend CometChatTextFormatter
3. Configure tracking character and regex
Set the character that triggers formatting and the regex to match.4. Implement required methods
5. Customize message bubble styling
Example
A hashtag formatter used with CometChatMessageList and CometChatMessageComposer.
- HashTagTextFormatter.dart
- Usage
Methods Reference
| Field | Description |
|---|---|
trackingCharacter | Character that starts tracking (e.g. # for hashtags) |
pattern | Regex pattern to match text for formatting |
showLoadingIndicator | Whether to show loading indicator during search |
messageBubbleTextStyle | Function to style message bubble text |
messageInputTextStyle | Function to style composer input text |
message | Current message being processed |
user | User context for the formatter |
group | Group context for the formatter |
Override Methods
- init
- handlePreMessageSend
- getMessageBubbleTextStyle
- getAttributedText
- onChange
Initialize the formatter. Called when the formatter is first used.
Built-in Formatters
Flutter UI Kit includes these pre-built formatters:| Formatter | Description |
|---|---|
CometChatMentionsFormatter | @mentions with user suggestions |
CometChatUrlFormatter | Auto-detect and style URLs |
CometChatEmailFormatter | Auto-detect and style email addresses |
CometChatPhoneNumberFormatter | Auto-detect and style phone numbers |
Next Steps
Mentions Formatter
Add @mentions with styled tokens.
Message Composer
Customize the message input component.
All Guides
Browse all feature and formatter guides.
Sample App
Full working sample application on GitHub.