Skip to content

Overview

  • File: lib/views/home_page.dart

The home_page.dart file implements the main navigation screen of the HVC XR application. It provides a grid-based layout of action buttons for accessing different features of the application, including contacts, camera, QR code scanning, events, and sign out functionality. The page is designed to work with RealWear devices and includes voice command support.

Class Structure

dart
class HomePage extends StatefulWidget {
  static const String routeName = '/';
  HomePage({Key? key}) : super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  // Implementation
}

Dependencies

dart
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:hvc_xr/hlk_helpers/hlk_widgets.dart';
import 'package:hvc_xr/models/core_models.dart';
import 'package:hvc_xr/shared/common.dart';
import 'package:hvc_xr/shared/config.dart';
import 'package:hvc_xr/views/events_page.dart';
import 'package:hvc_xr/views/scanner_page.dart';
import 'package:hvc_xr/views/secure_camera.dart';
import 'package:hvc_xr/widgets/hvc_button.dart';
import 'package:onesignal_flutter/onesignal_flutter.dart';
import 'package:permission_handler/permission_handler.dart';

Key Components

Controllers

The page uses several GetX controllers:

dart
final AuthController authController = Get.find();
final DigilensController digilensController = Get.find();

State Management

  • Uses GetX for state management
  • Implements voice command mapping
  • Manages user data

Voice Commands

The page implements voice command functionality through a map of command handlers:

dart
@override
void initState() {
  super.initState();
  voiceCommandMap['contacts'] = () => hvcDebounce(handleContacts, 'contacts');
  voiceCommandMap['camera'] = () => hvcDebounce(handleCamera, 'camera');
  voiceCommandMap['events'] = () => hvcDebounce(handleEvent, 'events');
  voiceCommandMap['signOut'] = () => hvcDebounce(handleSignOut, 'signOut');
  digilensController.currentPage.value = HomePage.routeName;
  digilensController.loadPageCommands(HomePage.routeName);
}

Feature Handlers

Contacts Handler

dart
void handleContacts() {
  if (!hasPermission(HvcPermissions.ViewContacts)) {
    HlkDialog.showErrorSnackBar(
      'Not permitted to perform action',
    );
    return;
  }
  Get.toNamed(ContactsPage.routeName);
}

Camera Handler

dart
void handleCamera() async {
  if (!hasPermission(HvcPermissions.CanUseSecureCamera)) {
    HlkDialog.showErrorSnackBar(
      'Not permitted to perform action',
    );
    return;
  }
  await validatePermission(
      Permission.camera,
      () async => await validatePermission(
          Permission.microphone,
          () async => await validatePermission(
              Permission.storage,
              () => Get.to(const SecureCamera(source: HomePage.routeName)))));
}

Events Handler

dart
void handleEvent() {
  if (!hasPermission(HvcPermissions.ManageEvents)) {
    HlkDialog.showErrorSnackBar(
      'Not permitted to perform action',
    );
    return;
  }
  Get.toNamed(EventsPage.routeName);
}

Sign Out Handler

dart
void handleSignOut() {
  HlkDialog.showVerticalDialog(
    qMessage: 'Are you sure you want to log out ?',
    positiveAction: () async => await authController.logout(),
  );
  digilensController.loadPageCommands('HlkDialog');
}

UI Layout

Background

dart
PageWithBackground(
  assetImagePath: 'assets/images/hvc_xr_bg.jpeg',
  child: Scaffold(
    backgroundColor: Colors.transparent,
    // ...
  ),
)

Button Grid

The page implements a grid layout using positioned buttons:

dart
Positioned(
  top: top1,
  left: start,
  child: HvcButton(
    text: 'contacts',
    bgColor: kAppColorPink,
    iconData: Icons.contacts,
    size: bigSize,
    onPressed: handleContacts,
  ),
),

Layout Calculations

dart
final bigSize = getWidth(0.16);
final smallSize = getWidth(0.12);
final start = getWidth(0.5) - getWidth(0.16) * 1.5;
final top1 = getWidth(0.08) + 12;
final top2 = getWidth(0.04) + 12;

Permission Handling

The page implements permission checks for various features:

dart
if (!hasPermission(HvcPermissions.ViewContacts)) {
  HlkDialog.showErrorSnackBar(
    'Not permitted to perform action',
  );
  return;
}

Device Orientation

The page manages device orientation in the dispose method:

dart
@override
dispose() {
  SystemChrome.setPreferredOrientations([
    DeviceOrientation.landscapeRight,
    DeviceOrientation.landscapeLeft,
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown,
  ]);
  super.dispose();
}

Push Notifications

The page initializes push notifications for logged-in users:

dart
if (isLoggedIn()) {
  OneSignal.login(user.userId);
}

Dependencies

  • get: State management
  • onesignal_flutter: Push notifications
  • permission_handler: Permission management
  • flutter/services: System services

Styling

  • Uses predefined color constants (kAppColorPink, kAppColorOrange, etc.)
  • Implements consistent button styling with HvcButton
  • Uses bigTextStyle and whiteTextStyle for text styling
  • Maintains responsive design with getWidth and getHeight

Released under the MIT License.