Skip to content

Overview ​

  • File: lib/main.dart

The main.dart file serves as the entry point for the HVC Mobile application. It initializes core services, sets up state management, and configures the application's lifecycle management.

Global Variables ​

dart
bool isProd = true;
late String deviceId;
late String deviceAgent;
RxBool isInChat = false.obs;
RxBool isInCall = false.obs;
DbManager? dbManager;
late PackageInfo appInfo;
Logger log = Logger('HVC_MOBILE_LOGGER');
  • isProd: Environment flag for production mode
  • deviceId: Unique identifier for the device
  • deviceAgent: Platform-specific user agent string
  • isInChat/isInCall: Reactive state variables for chat and call status
  • dbManager: Database manager instance
  • appInfo: Package information
  • log: Logger instance for application logging

Application Initialization ​

Main Function ​

The main() function is wrapped in runZonedGuarded for error handling and performs the following initializations:

  1. Flutter Binding

    dart
    WidgetsFlutterBinding.ensureInitialized();
  2. Logger Setup

    dart
    Logger.root.level = Level.ALL;
  3. Storage Initialization

    dart
    await GetStorage.init();
  4. Permission Requests The application requests the following permissions:

    • Camera
    • Microphone
    • Notifications
    • Bluetooth
    • Location
  5. Database Initialization

    dart
    dbManager = await DbManager.create();
  6. Device Information

    dart
    deviceId = await getDeviceId();
    deviceAgent = 'HvcMobile->${Platform.isIOS ? 'iOS' : 'Android'}';
  7. Push Notifications Setup

    dart
    OneSignal.initialize('5bc6d3bd-8862-48c9-b172-435f8b3c75b4');
    OneSignal.Notifications.requestPermission(true);

Main Application Widget ​

MyApp Class ​

The MyApp class extends StatefulWidget and manages the application's state and theme.

Controllers ​

The following controllers are initialized using GetX:

dart
final authController = Get.put(AuthController());
final contactsController = Get.put(ContactsController());
final schedulesController = Get.put(EventsController());
final mediaController = Get.put(MediaController());
final meetingsController = Get.put(MeetingsController());
final realTimeController = Get.put(RealTimeController());
final messagesController = Get.put(MessagesController());
final settingsController = Get.put(SettingsController());

Build Method ​

The build method configures:

  • Theme settings
  • Route management
  • Initial page selection based on authentication state
  • Controller callbacks and event handlers

Lifecycle Management ​

App Lifecycle States ​

The application handles the following lifecycle states:

  1. Inactive

    dart
    case AppLifecycleState.inactive:
      print('appLifeCycleState inactive');
      break;
  2. Resumed

    dart
    case AppLifecycleState.resumed:
      if (isLoggedIn()) {
        realTimeController.callHi('AppLifecycleState.resumed');
      }
      if (isFromBackground && _isBioActivated) {
        Get.offAllNamed(LoginPage.routeName);
        isFromBackground = false;
      }
      break;
  3. Paused

    dart
    case AppLifecycleState.paused:
      isFromBackground = true;
      break;
  4. Detached

    dart
    case AppLifecycleState.detached:
      dbManager?.store.close();
      break;

State Management ​

Authentication State ​

dart
var firstPage = (isBioTokenValid() || !isLoggedIn()) || !isRealUser
    ? LoginPage()
    : const MainPage();

Logout Handling ​

dart
authController.doOnLogout = () {
  try {
    contactsController.clearAll();
    schedulesController.events.clear();
    meetingsController.messages.clear();
    messagesController.messages.clear();
    messagesController.chatList.clear();
    realTimeController.disconnectSignalR();
    realTimeController.onClose();
    realTimeController.urlToUse = '';
    realTimeController.serverUrl = null;
    realTimeController.token = null;
    setState(() {});
  } catch (e) {
    logInfo(e);
  }
};

Security Features ​

Screen Protection ​

dart
ScreenProtector.preventScreenshotOff();

Biometric Authentication ​

dart
bool get _isBioActivated => isBioEnabled && isBioTokenValid();

Push Notifications ​

OneSignal Configuration ​

dart
OneSignal.Debug.setLogLevel(OSLogLevel.error);
OneSignal.initialize('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx');
OneSignal.Notifications.requestPermission(true);

Released under the MIT License.