Skip to main content
This guide walks you through creating a custom mentions formatter that extends CometChatMentionsFormatter to control the @mention suggestion behavior inside the message composer — letting you filter who appears in the suggestion list, customize mention styling, and handle tap interactions. This works with both CometChatMessageComposer and CometChatCompactMessageComposer.
This guide requires cometchat_chat_uikit version 5.2.13 or above. Earlier versions do not expose the APIs needed to subclass CometChatMentionsFormatter in this way.

Setup

Before implementing a custom mentions formatter, integrate the CometChat Flutter UI Kit into your application. Follow the official Flutter UI Kit integration guide to:
  • Create a CometChat account and obtain your App ID, Region, and Auth Key
  • Add the cometchat_chat_uikit dependency to your pubspec.yaml
  • Initialize the SDK with CometChatUIKit.init() and log in a user with CometChatUIKit.login()

Use Case

Filter the logged-in user out of the @mention suggestion list so users don’t see themselves when typing @. The same pattern applies to any custom filtering, styling, or tap-handling logic you need.

How It Works

The key idea: wrap the suggestionListEventSink with a filtering proxy so every suggestion list emitted by the base class is automatically transformed before reaching the UI.

Steps

1. Create the Formatter Class

Create a new file lib/utils/custom_mentions_formatter.dart. Your class extends CometChatMentionsFormatter and wraps the suggestion sink before the parent starts using it.

2. Create the Filtering Sink

In the same file, add a private StreamSink wrapper. This is the piece that actually filters the suggestions — in this example it removes the logged-in user.

3. Use It in the Composer Widgets

Your custom formatter works with both composer widgets via the textFormatters parameter.
When the UI Kit detects a custom subclass of CometChatMentionsFormatter in textFormatters, it automatically removes the default one so they don’t conflict. You don’t need to manually disable the built-in formatter.

Key Concepts


Common Customization Ideas

Filter by Role

You can filter based on the data map attached to each SuggestionListItem. For example, if user metadata includes a role:

Limit Suggestion Count

Custom Mention Styling


Troubleshooting


Next Steps

Mentions Formatter

Configure the built-in mentions formatter.

Custom Text Formatter

Build custom inline text patterns with regex.

Message Composer

Customize the standard message input component.

Compact Message Composer

Customize the compact message input component.