Appearance
Overview
- File:
lib/views/messages_page.dart
The MessagesPage is a Flutter widget that manages the chat list in the HVC Mobile application. It provides functionality for viewing, searching, and interacting with chat conversations, including navigation to chat details and chat selection.
Class Structure
Class Definition
dart
class MessagesPage extends StatefulWidget {
static const String routeName = '/MessagesPage';
MessagesPage({Key? key}) : super(key: key);
@override
_MessagesPageState createState() => _MessagesPageState();
}Controllers
dart
RealTimeController realTimeController = Get.find();
final MessagesController messagesController = Get.find();State Variables
dart
final TextEditingController searchCtrl = TextEditingController();Dependencies
Required Packages
flutter/material.dart- Core Flutter UI componentsget/get.dart- State management and routinginfinite_scroll_pagination- Infinite scrolling functionality
Internal Dependencies
messages_controller.dart- Chat management logicreal_time_controller.dart- Real-time communicationhlk_helpers/- Custom helper utilitiesmodels/- Data modelsshared/- Shared constants and configurationswidgets/- Custom widgets
State Management
Initialization
dart
@override
void initState() {
super.initState();
messagesController.getChatListOnline();
}Reactive State
dart
Obx(() => messagesController.loadingChat.isTrue &&
messagesController.chatList.isEmpty
? const Center(child: CircularProgressIndicator())
: Column(...))Chat Management
Chat Selection
dart
onSelected: (bool? value) {
setState(() {
chat.isSelected = value!;
if (value) {
messagesController.selectedChat.add(chat);
} else {
messagesController.selectedChat.remove(chat);
}
});
}Chat Navigation
dart
onTapHandler: () async {
if (!hasPermission(HvcPermissions.Chat)) {
HlkDialog.showErrorSnackBar('Not permitted to perform action');
return;
}
messagesController.selectedGroupId.value = chat.id;
await messagesController.reloadMessages();
Get.to(ContactMessageDetailsPage(
contact: chat.getContact(),
isForMessage: true,
));
Future.delayed(
const Duration(seconds: 2),
() => messagesController.getMessagesOnline()
);
}UI Components
Search Box
dart
if (messagesController.showSearchBox.value)
Padding(
padding: const EdgeInsets.only(left: 24, right: 12, top: 10),
child: Row(
children: [
Expanded(
child: TextFormField(
controller: searchCtrl,
validator: requiredValidator,
decoration: getInputDecoration('Search Chat', false),
),
),
IconButton(
onPressed: () async {
setState(() {
messagesController.showSearchBox.value = false;
messagesController.name.value = searchCtrl.text;
});
await messagesController.reloadChats();
searchCtrl.clear();
},
icon: const Icon(Icons.search),
),
],
),
)Chat List
dart
PagedListView<int, ChatModel>(
pagingController: messagesController.chatPagingController,
builderDelegate: PagedChildBuilderDelegate<ChatModel>(
itemBuilder: (context, chat, index) => ChatItem(...),
noItemsFoundIndicatorBuilder: (context) => NoItemLoader(...),
),
)Chat Item
dart
ChatItem(
chatModel: chat,
onTapHandler: () async { ... },
onSelected: (bool? value) { ... },
showSelector: messagesController.showSelector,
)Search Functionality
Search Implementation
dart
onPressed: () async {
setState(() {
messagesController.showSearchBox.value = false;
messagesController.name.value = searchCtrl.text;
});
await messagesController.reloadChats();
searchCtrl.clear();
}Search Box Toggle
dart
if (messagesController.showSearchBox.value)
// Show search box
else
// Hide search boxPermission Handling
Permission Checks
dart
if (!hasPermission(HvcPermissions.Chat)) {
HlkDialog.showErrorSnackBar('Not permitted to perform action');
return;
}Permission-Protected Actions
- Chat Navigation
- Chat List Refresh
- Chat List Loading