Skip to content

Overview

  • File: lib/views/home_page.dart

The HomePage is a Flutter widget that serves as the main landing page of the HVC Mobile application. It provides QR code functionality for headset login, with responsive design for both landscape and portrait orientations.

Class Structure

Class Definition

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

Controllers

dart
final AuthController authController = Get.find();

Dependencies

Required Packages

  • flutter/material.dart - Core Flutter UI components
  • get/get.dart - State management and routing

Internal Dependencies

  • auth_controller.dart - Authentication logic
  • hlk_helpers/hlk_utils.dart - Custom helper utilities
  • shared/common.dart - Shared utilities
  • shared/constants.dart - Application constants

UI Components

QR Code Display

dart
Image.memory(
  authController.byteArray!,
  height: s,
  width: s,
  fit: BoxFit.contain,
)

Placeholder QR Code

dart
Opacity(
  opacity: 0.2,
  child: GestureDetector(
    onTap: () async {
      if (!hasPermission(HvcPermissions.GenerateQRCode)) {
        HlkDialog.showErrorSnackBar('Not permitted to perform action');
        return;
      }
      await authController.getQrcode();
    },
    child: Image.asset(
      'assets/images/qrcode.png',
      height: s,
      width: s,
      fit: BoxFit.cover,
    ),
  ),
)

Instructional Text

dart
const Text(
  'QR Code for Headset Log In',
  style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
  textAlign: TextAlign.center,
)

Status Messages

dart
Text(
  'Center QR code in headset camera view to scan. The QR code will remain in focus for ${duration - authController.timeSpent.value.toInt()} seconds',
  textAlign: TextAlign.center,
)

State Management

Reactive State

dart
Obx(() => isLandscape ? Row(...) : Column(...))

Loading State

dart
if (authController.loading.value)
  const CircularProgressIndicator(color: kAppColorPurple)

Timer State

dart
if (authController.showTimer.value && authController.byteArray != null)
  // Show active QR code
else
  // Show placeholder QR code

QR Code Functionality

Permission Check

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

QR Code Generation

dart
await authController.getQrcode();

Timer Management

dart
final duration = getQrcodeDuration();
value: authController.timeSpent.value / duration

Responsive Design

Orientation Detection

dart
OrientationBuilder(
  builder: (context, orientation) {
    isLandscape = orientation == Orientation.landscape;
    return Center(...)
  }
)

Landscape Layout

dart
Row(
  children: [
    Expanded(
      child: // QR Code Section
    ),
    Expanded(
      child: Column(
        // Instructions Section
      ),
    )
  ],
)

Portrait Layout

dart
Column(
  mainAxisAlignment: MainAxisAlignment.center,
  crossAxisAlignment: CrossAxisAlignment.center,
  children: [
    // QR Code Section
    // Instructions Section
  ],
)

Progress Indicators

Loading Indicator

dart
if (authController.loading.value)
  const CircularProgressIndicator(color: kAppColorPurple)

Progress Bar

dart
LinearProgressIndicator(
  value: authController.timeSpent.value / duration,
  color: kAppColorPurple,
)

Released under the MIT License.