diff --git a/lib/main/lockDetail/lockSet/burglarAlarm/burglarAlarm_logic.dart b/lib/main/lockDetail/lockSet/burglarAlarm/burglarAlarm_logic.dart index 74e2c236..95830a3b 100755 --- a/lib/main/lockDetail/lockSet/burglarAlarm/burglarAlarm_logic.dart +++ b/lib/main/lockDetail/lockSet/burglarAlarm/burglarAlarm_logic.dart @@ -1,4 +1,3 @@ - import 'dart:async'; import 'package:flutter_blue_plus/flutter_blue_plus.dart'; @@ -17,31 +16,36 @@ import '../../../../tools/eventBusEventManage.dart'; import '../../../../tools/storage.dart'; import 'burglarAlarm_state.dart'; -class BurglarAlarmLogic extends BaseGetXController{ +class BurglarAlarmLogic extends BaseGetXController { BurglarAlarmState state = BurglarAlarmState(); // 配置锁的常开模式设置 -> 防撬报警 - Future _setLockSetGeneralSetting() async{ + Future _setLockSetGeneralSetting() async { final LoginEntity entity = await ApiRepository.to.setBurglarAlarmData( lockId: state.lockSetInfoData.value.lockId!, - antiPrySwitch:state.burglarAlarmEnable.value == 1 ? 0 : 1, // 1-开启、2-关闭; + antiPrySwitch: state.burglarAlarmEnable.value == 1 ? 0 : 1, // 1-开启、2-关闭; ); - if(entity.errorCode!.codeIsSuccessful){ - // eventBus.fire(RefreshLockListInfoDataEvent()); + if (entity.errorCode!.codeIsSuccessful) { + eventBus.fire(RefreshLockListInfoDataEvent()); - state.burglarAlarmEnable.value = state.burglarAlarmEnable.value == 1 ? 0 : 1; - state.lockSetInfoData.value.lockSettingInfo!.antiPrySwitch = state.burglarAlarmEnable.value; - showToast('操作成功'.tr, something: (){ - eventBus.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value)); + state.burglarAlarmEnable.value = + state.burglarAlarmEnable.value == 1 ? 0 : 1; + state.lockSetInfoData.value.lockSettingInfo!.antiPrySwitch = + state.burglarAlarmEnable.value; + showToast('操作成功'.tr, something: () { + eventBus + .fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value)); }); } } // 获取解析后的数据 late StreamSubscription _replySubscription; + void _initReplySubscription() { - _replySubscription = EventBusManager().eventBus!.on().listen((Reply reply) { - if(reply is SetSupportFunctionsNoParametersReply) { + _replySubscription = + EventBusManager().eventBus!.on().listen((Reply reply) { + if (reply is SetSupportFunctionsNoParametersReply) { _replySetSupportFunctionsWithParameters(reply); } @@ -71,7 +75,7 @@ class BurglarAlarmLogic extends BaseGetXController{ // 设置自动落锁数据解析 Future _replySetSupportFunctionsWithParameters(Reply reply) async { final int status = reply.data[2]; - switch(status){ + switch (status) { case 0x00: //成功 state.sureBtnState.value = 0; @@ -91,41 +95,47 @@ class BurglarAlarmLogic extends BaseGetXController{ // 设置支持功能(带参数) Future sendBurglarAlarm() async { - if(state.sureBtnState.value == 1){ + if (state.sureBtnState.value == 1) { return; } state.sureBtnState.value = 1; EasyLoading.show(); - 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? publicKey = await Storage.getStringList(saveBluePublicKey); - final List getPublicKeyList = changeStringListToIntList(publicKey!); + final List? publicKey = + await Storage.getStringList(saveBluePublicKey); + final List getPublicKeyList = + changeStringListToIntList(publicKey!); IoSenderManage.setSupportFunctionsNoParametersCommand( - keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(), - userID: await Storage.getUid(), - featureBit: 30, - featureEnable: state.burglarAlarmEnable.value == 1 ? 0 : 1, - token: getTokenList, - needAuthor: 1, - publicKey: getPublicKeyList, - privateKey: getPrivateKeyList); + keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(), + userID: await Storage.getUid(), + featureBit: 30, + featureEnable: state.burglarAlarmEnable.value == 1 ? 0 : 1, + token: getTokenList, + needAuthor: 1, + publicKey: getPublicKeyList, + privateKey: getPrivateKeyList, + ); } else if (connectionState == BluetoothConnectionState.disconnected) { dismissEasyLoading(); cancelBlueConnetctToastTimer(); state.sureBtnState.value = 0; - if(state.ifCurrentScreen.value == true){ + if (state.ifCurrentScreen.value == true) { showBlueConnetctToast(); } } @@ -152,5 +162,4 @@ class BurglarAlarmLogic extends BaseGetXController{ _replySubscription.cancel(); } - } diff --git a/lib/main/lockDetail/lockSet/remoteUnlocking/remoteUnlocking_logic.dart b/lib/main/lockDetail/lockSet/remoteUnlocking/remoteUnlocking_logic.dart index d5cc7d9d..3d62a5c1 100755 --- a/lib/main/lockDetail/lockSet/remoteUnlocking/remoteUnlocking_logic.dart +++ b/lib/main/lockDetail/lockSet/remoteUnlocking/remoteUnlocking_logic.dart @@ -21,9 +21,10 @@ class RemoteUnlockingLogic extends BaseGetXController { RemoteUnlockingState state = RemoteUnlockingState(); void remoteUnlockingOpenOrClose() async { - final LoginEntity entity = await ApiRepository.to.remoteUnlockingOpenOrClose( - lockId: state.lockSetInfoData.value.lockId!, - remoteUnlock: state.remoteEnable.value == 1 ? 0 : 1); + final LoginEntity entity = await ApiRepository.to + .remoteUnlockingOpenOrClose( + lockId: state.lockSetInfoData.value.lockId!, + remoteUnlock: state.remoteEnable.value == 1 ? 0 : 1); if (entity.errorCode!.codeIsSuccessful) { showToast('操作成功'.tr, something: () { eventBus.fire(RefreshLockListInfoDataEvent()); @@ -32,7 +33,6 @@ class RemoteUnlockingLogic extends BaseGetXController { state.remoteEnable.value; eventBus .fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value)); - eventBus.fire(RefreshLockListInfoDataEvent()); eventBus.fire(LockSetChangeSetRefreshLockDetailWithType( 5, state.lockSetInfoData.value.lockSettingInfo!.remoteUnlock! @@ -44,6 +44,7 @@ class RemoteUnlockingLogic extends BaseGetXController { // 获取解析后的数据 late StreamSubscription _replySubscription; + void _initReplySubscription() { _replySubscription = EventBusManager().eventBus!.on().listen((reply) {