import 'dart:async'; import '../../../blue/io_tool/manager_event_bus.dart'; import '../../../network/api_repository.dart'; import '../../../tools/baseGetXController.dart'; import 'lockMain_state.dart'; class LockMainLogic extends BaseGetXController { final LockMainState state = LockMainState(); void getLockInfo() async{ var entity = await ApiRepository.to.getLockInfo( lastUpdateDate:DateTime.now().millisecondsSinceEpoch.toString(), pageNo:"1", ); if(entity.errorCode!.codeIsSuccessful){ if(entity.data!.keyInfos!.isEmpty){ state.dataLength.value = 0; }else if(entity.data!.keyInfos!.length == 1){ state.dataLength.value = 1; }else{ state.dataLength.value = 2; } state.lockMainEntity.value = entity; } } // 监听设备返回的数据 late StreamSubscription _addLockSubscription; void _initAddLockSubscription() { _addLockSubscription = EventBusManager().eventBus!.on().listen((event) async { getLockInfo(); }); } @override void onReady() { // TODO: implement onReady super.onReady(); print("onReady()"); _initAddLockSubscription(); } @override void onInit() { // TODO: implement onInit super.onInit(); print("onInit()"); getLockInfo(); } @override void onClose() { // TODO: implement onClose super.onClose(); _addLockSubscription.cancel(); } }