{
"component" : "CometChatAIAssistantChatHistory" ,
"package" : "cometchat_chat_uikit" ,
"import" : "import 'package:cometchat_chat_uikit/cometchat_chat_uikit.dart';" ,
"description" : "A widget that displays the conversation history between users and an AI assistant with date separators and new chat functionality" ,
"primaryOutput" : {
"prop" : "onMessageClicked" ,
"type" : "void Function(BaseMessage? message)?"
},
"props" : {
"data" : {
"user" : {
"type" : "User?" ,
"default" : "null" ,
"note" : "User object for user message list (one of user/group required)"
},
"group" : {
"type" : "Group?" ,
"default" : "null" ,
"note" : "Group object for group message list (one of user/group required)"
},
"messagesRequestBuilder" : {
"type" : "MessagesRequestBuilder?" ,
"default" : "null" ,
"note" : "Custom request builder passed to CometChat's SDK"
}
},
"callbacks" : {
"onMessageClicked" : "void Function(BaseMessage? message)?" ,
"onNewChatButtonClicked" : "VoidCallback?" ,
"onError" : "OnError?" ,
"onLoad" : "OnLoad<BaseMessage>?" ,
"onEmpty" : "OnEmpty?" ,
"onClose" : "VoidCallback?"
},
"visibility" : {
"hideStickyDate" : {
"type" : "bool?" ,
"default" : "null"
},
"hideDateSeparator" : {
"type" : "bool?" ,
"default" : "null"
}
},
"viewSlots" : {
"loadingStateView" : "WidgetBuilder?" ,
"emptyStateView" : "WidgetBuilder?" ,
"errorStateView" : "WidgetBuilder?" ,
"backButton" : "Widget?"
},
"formatting" : {
"dateSeparatorPattern" : {
"type" : "String Function(DateTime)?" ,
"default" : "null"
},
"dateTimeFormatterCallback" : {
"type" : "DateTimeFormatterCallback?" ,
"default" : "null"
}
}
},
"events" : [],
"sdkListeners" : [],
"compositionExample" : {
"description" : "CometChatAIAssistantChatHistory is typically used within AI assistant features to show past conversations" ,
"components" : [ "CometChatMessageList" , "CometChatMessageComposer" ],
"flow" : "User opens chat history → Past messages displayed → User clicks message or starts new chat"
},
"types" : {}
}
Where It Fits
CometChatAIAssistantChatHistory 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.
Minimal Render
The simplest way to render CometChatAIAssistantChatHistory:
import 'package:cometchat_chat_uikit/cometchat_chat_uikit.dart' ;
CometChatAIAssistantChatHistory (
user : user, // Required: User or Group object
)
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.
You can also launch it using Navigator:
Navigator . push (
context,
MaterialPageRoute (
builder : (context) => CometChatAIAssistantChatHistory (
user : user, // A user or group object is required
),
),
);
Or embed it as a widget:
import 'package:cometchat_chat_uikit/cometchat_chat_uikit.dart' ;
import 'package:flutter/material.dart' ;
class ChatHistory extends StatefulWidget {
const ChatHistory ({ super .key});
@override
State < ChatHistory > createState () => _ChatHistoryState ();
}
class _ChatHistoryState extends State < ChatHistory > {
@override
Widget build ( BuildContext context) {
return Scaffold (
body : SafeArea (
child : CometChatAIAssistantChatHistory (
user : user, // A user or group object is required
),
),
);
}
}
Filtering
You can adjust the MessagesRequestBuilder to customize the message list. Numerous options are available to alter the builder to meet your specific needs.
CometChatAIAssistantChatHistory (
user : user,
messagesRequestBuilder : MessagesRequestBuilder ()
..uid = user.uid,
)
The following parameters in messageRequestBuilder will always be altered inside the list:
UID
GUID
types
categories
For additional details on MessagesRequestBuilder, please visit MessagesRequestBuilder .
Actions and Events
Callback Props
Component-level callbacks that fire on specific user interactions:
Callback Signature Fires When onMessageClickedvoid Function(BaseMessage? message)?User clicks a message onNewChatButtonClickedVoidCallback?User clicks the new chat button onErrorOnError?An error occurs while fetching messages onLoadOnLoad<BaseMessage>?List is successfully loaded onEmptyOnEmpty?List is empty onCloseVoidCallback?User clicks the back/close button
CometChatAIAssistantChatHistory (
user : user,
onNewChatButtonClicked : () {
// Start a new chat session
print ( 'New chat initiated' );
},
onMessageClicked : (message) {
// Navigate to the message context
print ( 'Message clicked: ${ message ?. id } ' );
},
onError : (e) {
print ( 'Error: $ e ' );
},
onLoad : (list) {
print ( 'Messages loaded: ${ list . length } ' );
},
onEmpty : () {
print ( 'No messages found' );
},
onClose : () {
Navigator . pop (context);
},
)
Global UI Events
The CometChatAIAssistantChatHistory component does not produce any global UI events.
Custom View Slots
Customize the appearance of CometChatAIAssistantChatHistory by replacing default views with your own widgets.
Slot Signature Replaces loadingStateViewWidgetBuilder?Loading spinner emptyStateViewWidgetBuilder?Empty state display errorStateViewWidgetBuilder?Error state display backButtonWidget?Back/close button
CometChatAIAssistantChatHistory (
user : user,
backButton : IconButton (
icon : const Icon (
Icons .arrow_back,
color : Colors .red,
),
onPressed : () {
Navigator . pop (context);
},
),
)
Example: Custom Loading State
CometChatAIAssistantChatHistory (
user : user,
loadingStateView : (context) {
return Center (
child : Column (
mainAxisAlignment : MainAxisAlignment .center,
children : [
CircularProgressIndicator (),
SizedBox (height : 16 ),
Text ( 'Fetching history...' ),
],
),
);
},
)
Example: Custom Empty State
CometChatAIAssistantChatHistory (
user : user,
emptyStateView : (context) {
return Center (
child : Text ( 'No history yet. Start a new conversation!' ),
);
},
)
Date Separator Pattern
You can modify the date pattern of the chat history date separator using dateSeparatorPattern:
CometChatAIAssistantChatHistory (
user : user,
dateSeparatorPattern : ( DateTime dateTime) {
return DateFormat ( "dd/MM/yyyy" ). format (dateTime);
},
)
Styling
Customize the appearance of CometChatAIAssistantChatHistory using CometChatAIAssistantChatHistoryStyle.
final ccColor = CometChatThemeHelper . getColorPalette (context);
CometChatAIAssistantChatHistory (
user : user,
style : CometChatAIAssistantChatHistoryStyle (
backgroundColor : const Color ( 0xFFFFFAF6 ),
headerBackgroundColor : const Color ( 0xFFFFFAF6 ),
headerTitleTextColor : ccColor.textPrimary,
headerTitleTextStyle : const TextStyle (
fontFamily : 'TimesNewRoman' ,
),
newChatIconColor : ccColor.iconSecondary,
newChatTextColor : ccColor.textPrimary,
newChaTitleStyle : const TextStyle (
fontFamily : 'TimesNewRoman' ,
),
dateSeparatorStyle : CometChatDateStyle (
textStyle : const TextStyle (
fontFamily : 'TimesNewRoman' ,
),
textColor : ccColor.textTertiary,
backgroundColor : const Color ( 0xFFFFFAF6 ),
),
itemTextStyle : const TextStyle (
fontFamily : 'TimesNewRoman' ,
),
itemTextColor : ccColor.textPrimary,
),
)
Style Properties
Property Type Description backgroundColorColor?Background color of the message list borderBoxBorder?Border of the message list borderRadiusBorderRadiusGeometry?Border radius of the message list emptyStateTextStyleTextStyle?Style of empty state text emptyStateTextColorColor?Color of empty state text emptyStateSubtitleStyleTextStyle?Style of empty state subtitle emptyStateSubtitleColorColor?Color of empty state subtitle errorStateTextStyleTextStyle?Style of error state text errorStateTextColorColor?Color of error state text errorStateSubtitleStyleTextStyle?Style of error state subtitle errorStateSubtitleColorColor?Color of error state subtitle dateSeparatorStyleCometChatDateStyle?Style for date separator newChatIconColorColor?Color of new chat icon newChaTitleStyleTextStyle?Style of new chat title newChatTextColorColor?Color of new chat text itemTextStyleTextStyle?Style of item text itemTextColorColor?Color of item text headerBackgroundColorColor?Background color of header headerTitleTextStyleTextStyle?Style of header title text headerTitleTextColorColor?Color of header title text closeIconColorColor?Color of close icon separatorHeightdouble?Height of separator separatorColorColor?Color of separator deleteChatHistoryDialogStyleCometChatConfirmDialogStyle?Style for delete dialog
Props Reference
Prop Type Default Description userUser?nullUser object for user message list groupGroup?nullGroup object for group message list messagesRequestBuilderMessagesRequestBuilder?nullCustom request builder loadingStateViewWidgetBuilder?nullCustom loading view emptyStateViewWidgetBuilder?nullCustom empty view errorStateViewWidgetBuilder?nullCustom error view onMessageClickedvoid Function(BaseMessage?)?nullMessage click callback onErrorOnError?nullError callback onLoadOnLoad<BaseMessage>?nullLoad callback onEmptyOnEmpty?nullEmpty callback onNewChatButtonClickedVoidCallback?nullNew chat button callback styleCometChatAIAssistantChatHistoryStyle?nullStyle configuration dateSeparatorPatternString Function(DateTime)?nullDate separator pattern dateTimeFormatterCallbackDateTimeFormatterCallback?nullDate/time formatter emptyStateTextString?nullEmpty state text emptyStateSubtitleTextString?nullEmpty state subtitle errorStateTextString?nullError state text errorStateSubtitleTextString?nullError state subtitle onCloseVoidCallback?nullClose callback backButtonWidget?nullCustom back button widthdouble?nullWidget width heightdouble?nullWidget height hideStickyDatebool?nullHide sticky date separator hideDateSeparatorbool?nullHide date separator