onInit method
Called immediately after the widget is allocated in memory. You might use this to initialize something for the controller.
Implementation
@override
void onInit() {
super.onInit();
final stateId = Get.parameters['stateId'] ?? 'first-contact';
lang = Get.parameters['lang'] ?? Get.locale?.languageCode ?? 'en';
ref = Get.parameters['ref'];
state = StateCatalog.byId(stateId) ?? StateCatalog.firstContact;
currentColor.value = state.screenColor;
currentPulseFreq.value = state.pulseFrequency;
_audio = createPlatformAudio();
_room = StateRoomWrapper(state: state);
// Subscribe to room participant count for real-time social proof.
_presenceSub = _room.participantCountStream.listen((count) {
presenceCount.value = count;
});
// Parallelize all async work: Firestore reads + Hive + analytics writes.
unawaited(Future.wait([
_loadUsageCount(),
_loadPresenceCount(),
_checkSessionLimit(),
StateAnalyticsService.recordOpen(state.id),
if (ref != null && ref!.isNotEmpty)
StateAnalyticsService.recordRef(state.id, ref!),
]));
}