Appearance
Overview
- File:
lib/widgets/chat_window.dart
The chat_window.dart file implements a real-time chat interface for the HVC XR application. It provides a customizable chat window with message display, notification controls, and support for in-call chat options.
Class Structure
dart
class ChatWindow extends StatelessWidget {
final RxList<Message> messageList;
final double width, height;
final int userId;
final Function()? onCloseOrCancel;
final Function(String) sendMessage;
final bool showNotification;
final Function(bool) onNotificationChange;
final TextEditingController smsController;
final ScrollController scrollController;
final RxList<InCallChatOption>? options;
final Function(InCallChatOption?)? onInCallChatOptionChange;
}
class InCallChatOption {
final String name;
final int id;
}
class LabeledSwitch extends StatelessWidget {
final String label;
final bool value;
final ValueChanged<bool> onChanged;
}Dependencies
flutter/material.dart- Flutter UI componentsget/get_rx/src/rx_types/rx_types.dart- Reactive state managementget/get_state_manager/src/rx_flutter/rx_obx_widget.dart- Reactive widgetshvc_xr/main.dart- Application constantshvc_xr/widgets/message_item.dart- Message display component
Key Components
Properties
messageList- Reactive list of chat messageswidthandheight- Window dimensionsuserId- Current user identifiersmsController- Text input controllerscrollController- Message list scroll controlleroptions- In-call chat optionsshowNotification- Notification visibility state
UI Elements
- Message list view
- Notification toggle
- Close/Cancel button
- Chat header
- Message input field (commented out)
Core Functionality
Message Display
dart
Obx(() {
final uniqueMessages = messageList.toSet().toList();
WidgetsBinding.instance.addPostFrameCallback((_) {
if (scrollController.hasClients) {
scrollController.animateTo(
scrollController.position.maxScrollExtent,
duration: const Duration(milliseconds: 500),
curve: Curves.easeInOut,
);
}
});
return ListView.builder(
itemCount: uniqueMessages.length,
controller: scrollController,
shrinkWrap: true,
padding: const EdgeInsets.all(8),
itemBuilder: (BuildContext ctx, int index) {
final ct = uniqueMessages[index];
return MessageItem(
message: ct,
isMe: ct.fromId == userId,
);
},
);
})Notification Control
dart
LabeledSwitch(
label: 'HIDE NOTIFICATIONS',
value: showNotification,
onChanged: onNotificationChange,
)UI Components
Main Layout
- Header with title and close button
- Message list area
- Footer with notification toggle and cancel button
Dynamic Elements
- Reactive message list
- Auto-scrolling to latest messages
- Notification toggle switch
- Responsive layout
State Management
- Uses GetX for reactive state management
- Manages message list state
- Handles notification visibility
- Controls scroll position
Dependencies
get- State managementflutter/material.dart- UI componentshvc_xr- Application components
Styling
- Follow application theme
- Use consistent colors
- Implement responsive layouts
- Handle different window sizes
- Support orientation changes
Integration Points
- Connects with message system
- Integrates with notification system
- Uses application constants
- Integrates with message item widget
Future Improvements
- Implement message input field
- Add in-call chat options
- Enhance notification system
- Improve scroll behavior
- Add message grouping
- Implement message search
- Add message reactions
- Enhance UI responsiveness