Appearance
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 modedeviceId: Unique identifier for the devicedeviceAgent: Platform-specific user agent stringisInChat/isInCall: Reactive state variables for chat and call statusdbManager: Database manager instanceappInfo: Package informationlog: Logger instance for application logging
Application Initialization
Main Function
The main() function is wrapped in runZonedGuarded for error handling and performs the following initializations:
Flutter Binding
dartWidgetsFlutterBinding.ensureInitialized();Logger Setup
dartLogger.root.level = Level.ALL;Storage Initialization
dartawait GetStorage.init();Permission Requests The application requests the following permissions:
- Camera
- Microphone
- Notifications
- Bluetooth
- Location
Database Initialization
dartdbManager = await DbManager.create();Device Information
dartdeviceId = await getDeviceId(); deviceAgent = 'HvcMobile->${Platform.isIOS ? 'iOS' : 'Android'}';Push Notifications Setup
dartOneSignal.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:
Inactive
dartcase AppLifecycleState.inactive: print('appLifeCycleState inactive'); break;Resumed
dartcase AppLifecycleState.resumed: if (isLoggedIn()) { realTimeController.callHi('AppLifecycleState.resumed'); } if (isFromBackground && _isBioActivated) { Get.offAllNamed(LoginPage.routeName); isFromBackground = false; } break;Paused
dartcase AppLifecycleState.paused: isFromBackground = true; break;Detached
dartcase 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);