Skip to content

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 components
  • get/get_rx/src/rx_types/rx_types.dart - Reactive state management
  • get/get_state_manager/src/rx_flutter/rx_obx_widget.dart - Reactive widgets
  • hvc_xr/main.dart - Application constants
  • hvc_xr/widgets/message_item.dart - Message display component

Key Components

Properties

  • messageList - Reactive list of chat messages
  • width and height - Window dimensions
  • userId - Current user identifier
  • smsController - Text input controller
  • scrollController - Message list scroll controller
  • options - In-call chat options
  • showNotification - 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 management
  • flutter/material.dart - UI components
  • hvc_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

  1. Implement message input field
  2. Add in-call chat options
  3. Enhance notification system
  4. Improve scroll behavior
  5. Add message grouping
  6. Implement message search
  7. Add message reactions
  8. Enhance UI responsiveness

Released under the MIT License.