diff --git a/lib/main/lockDetail/lockSet/lockTime/lockTime_logic.dart b/lib/main/lockDetail/lockSet/lockTime/lockTime_logic.dart index e3ab45be..a6700931 100755 --- a/lib/main/lockDetail/lockSet/lockTime/lockTime_logic.dart +++ b/lib/main/lockDetail/lockSet/lockTime/lockTime_logic.dart @@ -1,4 +1,3 @@ - import 'dart:async'; import 'package:date_format/date_format.dart'; @@ -20,19 +19,21 @@ import '../../../../tools/dateTool.dart'; import '../../../../tools/storage.dart'; import 'lockTime_state.dart'; -class LockTimeLogic extends BaseGetXController{ +class LockTimeLogic extends BaseGetXController { final LockTimeState state = LockTimeState(); // 获取解析后的数据 late StreamSubscription _replySubscription; + void _initReplySubscription() { - _replySubscription = EventBusManager().eventBus!.on().listen((Reply reply) { - if(reply is TimingReply) { + _replySubscription = + EventBusManager().eventBus!.on().listen((Reply reply) { + if (reply is TimingReply) { _replyTiming(reply); } // 获取锁状态 - if(reply is GetStarLockStatuInfoReply && state.ifCurrentScreen.value == true) { + if (reply is GetStarLockStatuInfoReply) { _replyGetStarLockStatusInfo(reply); } }); @@ -50,16 +51,19 @@ class LockTimeLogic extends BaseGetXController{ // 有效时间 final List indate = reply.data.sublist(150, 154); final int indateValue = (0xff & indate[0]) << 24 | - (0xff & indate[1]) << 16 | - (0xff & indate[2]) << 8 | - (0xFF & indate[3]); - AppLog.log('indate:$indate indateValue:$indateValue'); + (0xff & indate[1]) << 16 | + (0xff & indate[2]) << 8 | + (0xFF & indate[3]); + AppLog.log( + '====================indate:$indate indateValue:$indateValue'); state.dateTime.value = DateTool().dateToYMDHNString('$indateValue'); break; case 0x06: //需要鉴权 - final List? privateKey = await Storage.getStringList(saveBluePrivateKey); - final List getPrivateKeyList = changeStringListToIntList(privateKey!); + final List? privateKey = + await Storage.getStringList(saveBluePrivateKey); + final List getPrivateKeyList = + changeStringListToIntList(privateKey!); IoSenderManage.senderGetStarLockStatuInfo( lockID: BlueManage().connectDeviceName, @@ -79,10 +83,11 @@ class LockTimeLogic extends BaseGetXController{ // 校时数据解析 Future _replyTiming(Reply reply) async { final int status = reply.data[2]; - switch(status){ + switch (status) { case 0x00: //成功 - final String dataEime = DateTool().dateToYMDHNString('${state.serverTime}'); + final String dataEime = + DateTool().dateToYMDHNString('${state.serverTime}'); state.dateTime.value = dataEime; state.sureBtnState.value = 0; @@ -118,43 +123,47 @@ class LockTimeLogic extends BaseGetXController{ // 校验时间 Future sendTiming() async { - if(state.sureBtnState.value == 1){ + if (state.sureBtnState.value == 1) { return; } state.sureBtnState.value = 1; showEasyLoading(); - showBlueConnetctToastTimer(action: (){ + showBlueConnetctToastTimer(action: () { dismissEasyLoading(); state.sureBtnState.value = 0; }); - BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async { + BlueManage().blueSendData(BlueManage().connectDeviceName, + (BluetoothConnectionState connectionState) async { if (connectionState == BluetoothConnectionState.connected) { - final List? privateKey = await Storage.getStringList(saveBluePrivateKey); - final List getPrivateKeyList = changeStringListToIntList(privateKey!); + final List? privateKey = + await Storage.getStringList(saveBluePrivateKey); + final List getPrivateKeyList = + changeStringListToIntList(privateKey!); final List? token = await Storage.getStringList(saveBlueToken); final List getTokenList = changeStringListToIntList(token!); - final List? signKey = await Storage.getStringList(saveBlueSignKey); + final List? signKey = + await Storage.getStringList(saveBlueSignKey); final List getSignKeyList = changeStringListToIntList(signKey!); IoSenderManage.senderTimingCommand( - lockID:BlueManage().connectDeviceName, - userID:await Storage.getUid(), + lockID: BlueManage().connectDeviceName, + userID: await Storage.getUid(), nowTime: state.serverTime, - token:getTokenList, - needAuthor:1, - signKey:getSignKeyList, - privateKey:getPrivateKeyList, + token: getTokenList, + needAuthor: 1, + signKey: getSignKeyList, + privateKey: getPrivateKeyList, ); } else if (connectionState == BluetoothConnectionState.disconnected) { dismissEasyLoading(); cancelBlueConnetctToastTimer(); state.sureBtnState.value = 0; - if(state.ifCurrentScreen.value == true){ - showBlueConnetctToast(); - } + // if (state.ifCurrentScreen.value == true) { + // showBlueConnetctToast(); + // } } }); } @@ -168,8 +177,10 @@ class LockTimeLogic extends BaseGetXController{ BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async { if (deviceConnectionState == BluetoothConnectionState.connected) { - final List? privateKey = await Storage.getStringList(saveBluePrivateKey); - final List getPrivateKeyList = changeStringListToIntList(privateKey!); + final List? privateKey = + await Storage.getStringList(saveBluePrivateKey); + final List getPrivateKeyList = + changeStringListToIntList(privateKey!); IoSenderManage.senderGetStarLockStatuInfo( lockID: BlueManage().connectDeviceName, @@ -179,41 +190,42 @@ class LockTimeLogic extends BaseGetXController{ isBeforeAddUser: false, privateKey: getPrivateKeyList, ); - } else if (deviceConnectionState == BluetoothConnectionState.disconnected) { + } else if (deviceConnectionState == + BluetoothConnectionState.disconnected) { dismissEasyLoading(); cancelBlueConnetctToastTimer(); - if (state.ifCurrentScreen.value == true) { - showBlueConnetctToast(); - } + // if (state.ifCurrentScreen.value == true) { + // showBlueConnetctToast(); + // } } }); } // 从网关获取时间 - Future getLockTimeFromGateway() async{ - final GetServerDatetimeEntity entity = await ApiRepository.to.getLockTimeFromGateway( + Future getLockTimeFromGateway() async { + final GetServerDatetimeEntity entity = + await ApiRepository.to.getLockTimeFromGateway( lockId: state.lockSetInfoData.value.lockId.toString(), ); - if(entity.errorCode!.codeIsSuccessful){ - - } + if (entity.errorCode!.codeIsSuccessful) {} } // 从服务器获取锁的时间 开锁时传入 - Future getServerDatetime(bool isSendTime) async{ - final GetServerDatetimeEntity entity = await ApiRepository.to.getServerDatetimeData(isUnShowLoading:false); - if(entity.errorCode!.codeIsSuccessful){ + Future getServerDatetime(bool isSendTime) async { + final GetServerDatetimeEntity entity = + await ApiRepository.to.getServerDatetimeData(isUnShowLoading: false); + if (entity.errorCode!.codeIsSuccessful) { state.serverTime = entity.data!.date! ~/ 1000; // AppLog.log("entity.data!.date! ~/ 1000:${entity.data!.date! ~/ 1000} DateTime.now().millisecondsSinceEpoch ~/ 1000:${DateTime.now().millisecondsSinceEpoch ~/ 1000} 服务器时间差:${state.differentialTime}"); - if(isSendTime == false){ + if (isSendTime == false) { getStarLockStatus(); - }else{ + } else { sendTiming(); } } } - int getLocalTime(){ + int getLocalTime() { final DateTime now = DateTime.now(); final Duration timeZoneOffset = now.timeZoneOffset; // AppLog.log('timeZoneOffset.inSeconds:$timeZoneOffset.inSeconds'); @@ -229,7 +241,6 @@ class LockTimeLogic extends BaseGetXController{ // getLockTimeFromGateway(); getServerDatetime(false); - } @override @@ -242,4 +253,4 @@ class LockTimeLogic extends BaseGetXController{ super.onClose(); _replySubscription.cancel(); } -} \ No newline at end of file +}