import 'dart:async'; import 'package:fikoyt_ui/fikoyt_ui.dart'; class Screen1Controller extends GetxController { // Singleton instance // static Screen1Controller? _instance; // // Private constructor // Screen1Controller._internal(); // // Factory constructor to return the same instance // factory Screen1Controller() { // _instance ??= Screen1Controller._internal(); // return _instance!; // } final Rx cardId = FikoYTEvent('FikoYT.uyar.cardId.value').$value; final RxList cardReaderList = RxList.empty(); final Rx cardReaderInfo = Rx(null); final Rx deviceSettings = Rx(null); final Rx deviceInfo = Rx(null); final Rx nfcKullanici = FikoYTEvent('FikoYT.uyar.nfc.kullanici').$value; StreamSubscription? listenerCardId; @override void onInit() async { await initCardReader(); super.onInit(); } @override void onClose() { FikoYTCoreService.socket.off("FikoYT.uyar.devices.card.update"); FikoYTCoreService.socket.off("FikoYT.uyar.devices.device.updated"); listenerCardId?.cancel(); super.onClose(); } Future initCardReader() async { listenerCardId = cardId.listen( (val) { if (val != "" && val != null) { FikoYTCoreService.socket.auth = {"selam": DateTime.now().toIso8601String()}; FikoYTCoreService.socket.emitWithAck("FikoYT.uyar.nfc.kullanici", {"nfc": val}, ack: (data) async { nfcKullanici.value = data; if (data != null) { FikoYTCoreService.navigatorKey.currentContext?.vRouter.to("/screen-1/person-dash"); } else { FikoYTCoreService.navigatorKey.currentContext?.vRouter.to("/screen-1/unknown-dash"); } }); } else { FikoYTCoreService.navigatorKey.currentContext?.vRouter.to("/screen-1/intro"); nfcKullanici.value = null; } }, ); FikoYTCoreService.socket.emitWithAck("FikoYT.uyar.devices.list", "FikoYT Kart Okuyucu", ack: (data) async { cardReaderList.value = data ?? []; }); /** */ FikoYTCoreService.socket.emitWithAck("FikoYT.uyar.devices.info", await FikoYTCoreService.getDeviceID(), ack: (data) async { deviceSettings.value = data?["info"]?["settings"]; deviceInfo.value = data; if (deviceSettings.value != null) { FikoYTCoreService.socket.emitWithAck("FikoYT.uyar.devices.info", deviceSettings.value?["cardReaderUuid"], ack: (data) async { cardId.value = data?["data"]?["cardId"]; cardReaderInfo.value = data; }); } }); /** */ FikoYTCoreService.socket.on( "FikoYT.uyar.devices.card.update", (data) async { cardId.value = data["cardUuid"]; // print(data); }, ); /** */ FikoYTCoreService.socket.on( "FikoYT.uyar.devices.device.updated", (data) async { if (data?["_id"] == cardReaderInfo.value?["_id"]) { cardId.value = data?["data"]?["cardId"]; cardReaderInfo.value = data; } }, ); } }