To integrate ChatList into your application, follow these three steps:
1. Create a ChatListController
Initialize the controller with your initial data and a ScrollController.
2. Define your Chat List
Create a list of ChatListItem objects containing user info, unread counts, and last messages.
3. Add the ChatList Widget
Pass the controller and configuration to the ChatList widget. You can use menuConfig to handle actions like deleting, muting, or pinning chats via callbacks.
// 1. Create Controller
ChatListController chatListController = ChatListController(
initialChatList: chatList,
scrollController: ScrollController(),
);
// 2. Define Data
List<ChatListItem> chatList = [
ChatListItem(
id: '2',
name: 'Simform',
unreadCount: 2,
lastMessage: Message(
id: '12',
sentBy: '2',
message: "🤩🤩",
createdAt: DateTime.now(),
status: MessageStatus.delivered,
),
settings: ChatSettings(
pinTime: DateTime.now(),
pinStatus: PinStatus.pinned,
),
),
];
// 3. Add Widget
ChatList(
controller: chatListController,
appbar: const ChatListAppBar(title: 'ChatList Demo'),
menuConfig: ChatMenuConfig(
deleteCallback: (chat) => chatListController.removeChat(chat.id),
muteStatusCallback: (result) => chatListController.updateChat(
result.chat.id,
(previousChat) => previousChat.copyWith(
settings: previousChat.settings.copyWith(
muteStatus: result.status,
),
),
),
pinStatusCallback: (result) => chatListController.updateChat(
result.chat.id,
(previousChat) => previousChat.copyWith(
settings: previousChat.settings.copyWith(
pinStatus: result.status,
),
),
),
),
tileConfig: ListTileConfig(onTap: (chat) {}),
)