Users with Messages
Overview
CometChatUsersWithMessages
is a Composite Widget that seamlessly merges the functionalities of both the Users and Messages modules. It empowers users to effortlessly navigate to any individual's chat window by simply clicking on their respective list item in the user list.
Additionally, CometChatUsersWithMessages
inherits and encompasses all attributes available within the CometChatUsersWithMessages
module, ensuring a comprehensive user experience.
- Android
- iOS
Widget | Description |
---|---|
Users | Standalone screen displaying a searchable user list. Inherits from CometChatListBase and wraps CometChatUserList . |
Messages | Chat interface for users and groups. Displays message list for logged-in user's interactions. |
Usage
Integration
Since CometChatUsersWithMessages
is a widget, it can be launched either by a button click or through any event's trigger. It inherits all the customizable properties and methods of CometChatUsers.
You can launch CometChatUsersWithMessages
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 CometChatUsersWithMessages
- Dart
Navigator.push(context, MaterialPageRoute(builder: (context) => const CometChatUsersWithMessages()));
2. Embedding CometChatUsersWithMessages
as a Widget in the build Method
- Dart
import 'package:cometchat_chat_uikit/cometchat_chat_uikit.dart';
import 'package:flutter/material.dart';
class UsersWithMessages extends StatefulWidget {
const UsersWithMessages({super.key});
State<UsersWithMessages> createState() => _UsersWithMessagesState();
}
class _UsersWithMessagesState extends State<UsersWithMessages> {
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: CometChatUsersWithMessages()
)
);
}
}
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.
1. onItemTap
The onItemTap
method is used to override the onClick behavior in CometChatUsersWithMessages
.
This action does not come with any predefined behavior. However, you have the flexibility to override this event and tailor it to suit your needs using the following code snippet.
- Dart
CometChatUsersWithMessages(
usersConfiguration: UsersConfiguration(
onItemTap: (context, user) {
// TODO("Not yet implemented")
},
)
)
2. onItemLongPress
This method onItemLongPress
, empowers users to customize long-click actions within CometChatUsersWithMessages
, offering enhanced functionality and interaction possibilities.
- Dart
CometChatUsersWithMessages(
usersConfiguration: UsersConfiguration(
onItemLongPress: (context, user) {
// TODO("Not yet implemented")
},
)
)
3. onBack
This method allows users to override the onBack Pressed behavior in CometChatUsersWithMessages
by utilizing the onBack
, providing customization options for handling the back action.
By default, this action has a predefined behavior: it simply dismisses the current widget. However, the flexibility of CometChat UI Kit allows you to override this standard behavior according to your application's specific requirements. You can define a custom action that will be performed instead when the back button is pressed.
- Dart
CometChatUsersWithMessages(
usersConfiguration: UsersConfiguration(
onBack: () {
// TODO("Not yet implemented")
},
)
)
4. onError
This method onError
, allows users to override error handling within CometChatUsersWithMessages
, providing greater control over error responses and actions.
- Dart
CometChatUsersWithMessages(
usersConfiguration: UsersConfiguration(
onError: (e) {
// TODO("Not yet implemented")
},
)
)