Overview
TheAI Assistant Chat History
widget is a pre-built user interface widget designed to display the conversation history between users and an AI assistant within a chat application. It provides a structured and visually appealing way to present past interactions, making it easy for users to review previous messages and context.

Usage
Integration
You can launchCometChatAIAssistantChatHistory
directly using Navigator.push
, or you can define it as a widget within the build
method of your State
class.
1. Using Navigator to Launch CometChatAIAssistantChatHistory
- Dart
Simply adding the
CometChatAIAssistantChatHistory
component to the layout will only display the loading indicator. To fetch messages for a specific entity, you need to supplement it with User
or Group
Object.2. Embedding ChatHistory
as a Widget in the build Method
- Dart
Actions
Actions dictate how a widget functions. They are divided into two types: Predefined and User-defined. You can override either type, allowing you to tailor the behavior of the widget to fit your specific needs.onNewChatButtonClicked
onNewChatButtonClicked
is triggered when you click on the new chat button. The onNewChatButtonClicked
action doesn’t have a predefined behavior. You can override this action using the following code snippet.
- Dart
onMessageClicked
You can customize this behavior by using the provided code snippet to override theonMessageClicked
.
- Dart
onError
You can customize this behavior by using the provided code snippet to override theonError
and improve error handling.
- Dart
onLoad
Invoked when the list is successfully fetched and loaded, helping track component readiness.- Dart
onEmpty
Called when the list is empty, enabling custom handling such as showing a placeholder message.- Dart
Filters
You can adjust theMessagesRequestBuilder
in the CometChatAIAssistantChatHistory Widget to customize your list. Numerous options are available to alter the builder to meet your specific needs. For additional details on MessagesRequestBuilder
, please visit MessagesRequestBuilder.
In the example below, we are applying a filter to the messages based on a search substring and for a specific user. This means that only messages that contain the search term and are associated with the specified user will be displayed
- Dart
The following parameters in messageRequestBuilder will always be altered inside the list
- UID
- GUID
- types
- categories
Events
Events are emitted by aWidget
. By using event you can extend existing functionality. Being global events, they can be applied in Multiple Locations and are capable of being Added or Removed.
The CometChatAIAssistantChatHistory Widget does not emit any events of its own.
Customization
To fit your app’s design requirements, you can customize the appearance of the conversation widget. We provide exposed methods that allow you to modify the experience and behavior according to your specific needs.Style
Using Style you can customize the look and feel of the widget in your app, These parameters typically control elements such as the color, size, shape, and fonts used within the widget.1. CometChatAIAssistantChatHistoryStyle
You can set thestyle
to the CometChatAIAssistantChatHistory
Widget to customize the styling.
- Dart

Functionality
These are a set of small functional customizations that allow you to fine-tune the overall experience of the widget. With these, you can change text, set custom icons, and toggle the visibility of UI elements.- Dart
CometChatMessageList Properties
Below is a list of customizations along with corresponding code snippets:Property | Data Type | Description |
---|---|---|
user | User? | User object for the user message list. |
group | Group? | Group object for the group message list. |
messagesRequestBuilder | MessagesRequestBuilder? | Custom request builder passed to CometChat’s SDK. |
loadingStateView | WidgetBuilder? | View for the loading state. |
emptyStateView | WidgetBuilder? | View for the empty state. |
errorStateView | WidgetBuilder? | View for the error state behind the dialog. |
onMessageClicked | void Function(BaseMessage? message)? | Callback triggered when a message is clicked. |
onError | OnError? | Callback triggered when an error occurs while fetching users. |
onLoad | OnLoad<BaseMessage>? | Callback triggered when the list is loaded. |
onEmpty | OnEmpty? | Callback triggered when the list is empty. |
onNewChatButtonClicked | VoidCallback? | Callback triggered when the new chat button is clicked. |
style | CometChatAIAssistantChatHistoryStyle? | Sets the style for the AI Assistant chat history. |
dateSeparatorPattern | String Function(DateTime dateTime)? | Custom pattern for the date separator. |
dateTimeFormatterCallback | DateTimeFormatterCallback? | Callback to format the date and time. |
emptyStateText | String? | Text to display when the list is empty. |
emptyStateSubtitleText | String? | Subtitle text to display when the list is empty. |
errorStateText | String? | Text to display when an error occurs. |
errorStateSubtitleText | String? | Subtitle text to display when an error occurs. |
onClose | VoidCallback? | Callback triggered when the back button is pressed. |
backButton | Widget? | Custom widget for the back button. |
width | double? | Sets the width of the list. |
height | double? | Sets the height of the list. |
hideStickyDate | bool? | Hide the sticky date separator. |
hideDateSeparator | bool? | Hide the date separator. |
Advance
For advanced-level customization, you can set custom views to the widget. This lets you tailor each aspect of the widget to fit your exact needs and application aesthetics. You can create and define your own widget and then incorporate those into the widget.DateSeparatorPattern
You can modify the date pattern of the chat history date separator to your requirement usingdateSeparatorPattern
. This method accepts a function with a return type String. Inside the function, you can create your own pattern and return it as a String.
Example
Here is the complete example for reference:
- Dart
loadingStateView
Customizes the loading indicator when messages are being fetched. Use Cases:- Show a spinner or skeleton loader for smooth UX.
- Display a “Fetching history…” text.
- Dart
emptyStateView
Defines a custom view to be displayed when no messages are available. Use Cases:- Show a friendly message like “No history yet.”.
- Dart
errorStateView
Custom error state view displayed when fetching history fails. Use Cases:- Show a retry button when an error occurs.
- Display a friendly message like “Couldn’t load history. Check your connection.”.
- Dart