diff --git a/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_logic.dart b/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_logic.dart index 3869b32f..c0eb4073 100755 --- a/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_logic.dart +++ b/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_logic.dart @@ -5,7 +5,11 @@ import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:get/get.dart'; import 'package:star_lock/appRouters.dart'; import 'package:star_lock/app_settings/app_settings.dart'; +import 'package:star_lock/login/login/entity/LoginEntity.dart'; +import 'package:star_lock/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_entity.dart'; +import 'package:star_lock/main/lockDetail/authorizedAdmin/authorizedAdmin/notice_template_entity.dart'; import 'package:star_lock/mine/valueAddedServices/advancedFunctionRecord/advancedFunctionRecord_entity.dart'; +import 'package:star_lock/tools/NativeInteractionTool.dart'; import 'package:star_lock/tools/dateTool.dart'; import 'package:star_lock/tools/showCupertinoAlertView.dart'; @@ -26,18 +30,21 @@ import 'authorizedAdmin_state.dart'; class AuthorizedAdminLogic extends BaseGetXController { final AuthorizedAdminState state = AuthorizedAdminState(); + int? keyId; + // 监听设备返回的数据 late StreamSubscription _replySubscription; + void _initReplySubscription() { _replySubscription = - EventBusManager().eventBus!.on().listen((reply) async { + EventBusManager().eventBus!.on().listen((Reply reply) async { // 转移权限 if (reply is TransferPermissionsReply) { - var token = reply.data.sublist(2, 6); - var saveStrList = changeIntListToStringList(token); + final List token = reply.data.sublist(2, 6); + final List saveStrList = changeIntListToStringList(token); Storage.setStringList(saveBlueToken, saveStrList); - int status = reply.data[6]; + final int status = reply.data[6]; switch (status) { case 0x00: @@ -45,20 +52,24 @@ class AuthorizedAdminLogic extends BaseGetXController { break; case 0x06: //无权限 - var privateKey = await Storage.getStringList(saveBluePrivateKey); - List getPrivateKeyList = + final List? privateKey = + await Storage.getStringList(saveBluePrivateKey); + final List getPrivateKeyList = changeStringListToIntList(privateKey!); - var publicKey = await Storage.getStringList(saveBluePublicKey); - List publicKeyDataList = changeStringListToIntList(publicKey!); + final List? publicKey = + await Storage.getStringList(saveBluePublicKey); + final List publicKeyDataList = + changeStringListToIntList(publicKey!); - var token = await Storage.getStringList(saveBlueToken); - List getTokenList = changeStringListToIntList(token!); + final List? token = + await Storage.getStringList(saveBlueToken); + final List getTokenList = changeStringListToIntList(token!); IoSenderManage.senderFactoryDataReset( lockID: BlueManage().connectDeviceName, userID: await Storage.getUid(), - keyID: "1", + keyID: '1', needAuthor: 1, publicKey: publicKeyDataList, privateKey: getPrivateKeyList, @@ -76,21 +87,25 @@ class AuthorizedAdminLogic extends BaseGetXController { BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState state) async { if (state == BluetoothConnectionState.connected) { - var privateKey = await Storage.getStringList(saveBluePrivateKey); - List getPrivateKeyList = changeStringListToIntList(privateKey!); + final List? privateKey = + await Storage.getStringList(saveBluePrivateKey); + final List getPrivateKeyList = + changeStringListToIntList(privateKey!); - var publicKey = await Storage.getStringList(saveBluePublicKey); - List publicKeyDataList = changeStringListToIntList(publicKey!); + final List? publicKey = + await Storage.getStringList(saveBluePublicKey); + final List publicKeyDataList = + changeStringListToIntList(publicKey!); - var token = await Storage.getStringList(saveBlueToken); - List getTokenList = changeStringListToIntList(token!); + final List? token = await Storage.getStringList(saveBlueToken); + final List getTokenList = changeStringListToIntList(token!); IoSenderManage.senderTransferPermissions( lockID: BlueManage().connectDeviceName, authUserID: await Storage.getUid(), - keyID: "1", + keyID: '1', oldUserID: await Storage.getUid(), - newUserID: "100002", + newUserID: '100002', needAuthor: 1, publicKey: publicKeyDataList, privateKey: getPrivateKeyList, @@ -102,40 +117,40 @@ class AuthorizedAdminLogic extends BaseGetXController { //发送授权管理员列表请求 Future sendElectronicKeyRequest() async { if (state.emailOrPhoneController.text.isEmpty) { - showToast("请输入接收者账号"); + showToast('请输入接收者账号'); return; } if (state.keyNameController.text.isEmpty) { - showToast("请输入接收者姓名"); + showToast('请输入接收者姓名'); return; } - var startDate = "0"; - var endDate = "0"; - var startTime = "0"; - var endTime = "0"; - AppLog.log("state.type.value:${state.seletType.value}"); - String getKeyType = "1"; + String startDate = '0'; + String endDate = '0'; + String startTime = '0'; + String endTime = '0'; + AppLog.log('state.type.value:${state.seletType.value}'); + String getKeyType = '1'; if (state.seletType.value == 0) { - getKeyType = "2"; + getKeyType = '2'; startDate = DateTool().dateToTimestamp(state.beginDate.value, 1).toString(); endDate = DateTool().dateToTimestamp(state.endDate.value, 1).toString(); - startTime = "0"; - endTime = "0"; + startTime = '0'; + endTime = '0'; if (startDate.isEmpty) { - showToast("请选择开始时间"); + showToast('请选择开始时间'); return; } if (endDate.isEmpty) { - showToast("请选择结束时间"); + showToast('请选择结束时间'); return; } if (int.parse(startDate) >= int.parse(endDate)) { - showToast("失效时间要大于生效时间"); + showToast('失效时间要大于生效时间'); return; } } @@ -143,12 +158,12 @@ class AuthorizedAdminLogic extends BaseGetXController { //如果打开了实名认证,需要弹出输入身份证信息框 if (state.isAuthentication.value == true) { if (state.realNameController.text.isEmpty) { - showToast("请输入真实姓名".tr); + showToast('请输入真实姓名'.tr); return; } if (state.idCardController.text.isEmpty) { - showToast("请输入身份证号".tr); + showToast('请输入身份证号'.tr); return; } //弹出身份证信息确认框 @@ -179,38 +194,39 @@ class AuthorizedAdminLogic extends BaseGetXController { required String startDate, required String startTime, required String endTime}) async { - var entity = await ApiRepository.to.sendElectronicKey( - createUser: state.isCreateUser.value ? "1" : "0", - countryCode: state.countryCode.value, - usernameType: '1', - endDate: int.parse(endDate), - faceAuthentication: state.isAuthentication.value == true ? '1' : '2', - isCameraEnable: '2', - isRemoteUnlock: '2', - keyNameForAdmin: state.keyNameController.text, - keyRight: '1', - keyType: getKeyType, - lockId: CommonDataManage().currentKeyInfo.lockId!.toString(), - operatorUid: '', - receiverUsername: state.emailOrPhoneController.text, - remarks: '', - startDate: int.parse(startDate), - weekDays: state.weekdaysList, - startTime: int.parse(startTime), - endTime: int.parse(endTime), - isOnlyManageSelf: state.onlyManageYouCreatesUser.value ? 1 : 0, - realName: state.isRequireAuth.value == true - ? state.realNameController.text - : "", - idCardNumber: state.isRequireAuth.value == true - ? state.idCardController.text - : ""); + final AuthorizedAdminSendEntity entity = await ApiRepository.to + .sendElectronicKey( + createUser: state.isCreateUser.value ? '1' : '0', + countryCode: state.countryCode.value, + usernameType: '1', + endDate: int.parse(endDate), + faceAuthentication: + state.isAuthentication.value == true ? '1' : '2', + isCameraEnable: '2', + isRemoteUnlock: '2', + keyNameForAdmin: state.keyNameController.text, + keyRight: '1', + keyType: getKeyType, + lockId: CommonDataManage().currentKeyInfo.lockId!.toString(), + operatorUid: '', + receiverUsername: state.emailOrPhoneController.text, + remarks: '', + startDate: int.parse(startDate), + weekDays: state.weekdaysList, + startTime: int.parse(startTime), + endTime: int.parse(endTime), + isOnlyManageSelf: state.onlyManageYouCreatesUser.value ? 1 : 0, + realName: state.isRequireAuth.value == true + ? state.realNameController.text + : '', + idCardNumber: state.isRequireAuth.value == true + ? state.idCardController.text + : ''); if (entity.errorCode!.codeIsSuccessful) { state.isCreateUser.value = false; state.isSendSuccess.value = true; - // Toast.show(msg: "添加成功"); state.addUserId.value = entity.data!.receiverUser!.id.toString(); - // addUserConnectBlue(state.addUserId.value); + keyId = entity.data!.keyId; eventBus.fire(AuthorizedAdminPageRefreshUI()); } else { if (entity.errorCode == 425) { @@ -218,16 +234,15 @@ class AuthorizedAdminLogic extends BaseGetXController { state.isCreateUser.value = true; ShowTipView().showIosTipWithContentDialog( '${"是否发送授权管理员给未注册账号".tr}\n${state.emailOrPhoneController.text}', - () { - sendElectronicKeyRequest(); - }); + sendElectronicKeyRequest); } } } //检测实名认证是否支持开启 Future keyCheckFace() async { - AdvancedFunctionRecordEntity entity = await ApiRepository.to.keyCheckFace( + final AdvancedFunctionRecordEntity entity = + await ApiRepository.to.keyCheckFace( lockId: CommonDataManage().currentKeyInfo.lockId ?? 0, ); if (entity.errorCode!.codeIsSuccessful) { @@ -240,7 +255,7 @@ class AuthorizedAdminLogic extends BaseGetXController { titleStr: '实名认证为付费功能,请购买后再使用'.tr, sureClick: () { Get.toNamed(Routers.advancedFeaturesWebPage, - arguments: {'isShop': false}); + arguments: {'isShop': false}); }); } else if (entity.errorCode == 433) { //需联系管理员购买 @@ -250,12 +265,12 @@ class AuthorizedAdminLogic extends BaseGetXController { //标记房间为已入住 isOn:已入住: 1 空闲:2 Future updateRoomCheckIn() async { - var entity = await ApiRepository.to.setRoomStatusData( + final LoginEntity entity = await ApiRepository.to.setRoomStatusData( lockId: CommonDataManage().currentKeyInfo.lockId!, roomStatus: 1, ); if (entity.errorCode!.codeIsSuccessful) { - showToast("标记成功"); + showToast('标记成功'); } } @@ -279,6 +294,31 @@ class AuthorizedAdminLogic extends BaseGetXController { return currentController; } + //发送消息 + Future sendMsg({required bool isPhone}) async { + if (keyId == null) { + return; + } + final NoticeTemplateEntity entity = await ApiRepository.to + .getNoticeTemplate( + lockId: CommonDataManage().currentKeyInfo.lockId!, + keyId: keyId!, + channelType: isPhone ? 1 : 2); + if (entity.errorCode!.codeIsSuccessful) { + final List list = + entity.data!.list!.where((Item item) => item.isUse == 0).toList(); + if (list.isNotEmpty) { + final Item item = list.first!; + final String template = item.template ?? ''; + NativeInteractionTool().loadNativeShare(shareText: template); + } else { + showToast('获取模板失败 0x02'); + } + } else { + showToast('获取模板失败 0x01'); + } + } + @override void onReady() { // TODO: implement onReady diff --git a/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_page.dart b/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_page.dart index 6f3d0d2f..d1e2bb3d 100755 --- a/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_page.dart +++ b/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_page.dart @@ -362,8 +362,7 @@ class _AuthorizedAdminPageState extends State if (state.emailOrPhoneController.text.contains('@')) { Get.toNamed(Routers.sendEmailNotificationPage); } else { - NativeInteractionTool() - .loadNativeShare(shareText: state.pwdShareStr); + logic.sendMsg(isPhone: true); } }, ), @@ -373,8 +372,8 @@ class _AuthorizedAdminPageState extends State OutLineBtn( btnName: '微信通知', onClick: () { - NativeInteractionTool() - .loadNativeShare(shareText: state.pwdShareStr); + logic.sendMsg( + isPhone: state.emailOrPhoneController.text.contains('@')); }, ), SizedBox( diff --git a/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_state.dart b/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_state.dart index 0a350e43..36dceadf 100755 --- a/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_state.dart +++ b/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_state.dart @@ -15,25 +15,25 @@ class AuthorizedAdminState { final FlutterContactPicker contactPicker = FlutterContactPicker(); late Contact contact; - var isAuthentication = false.obs; //是否可以实名认证 - final onlyManageYouCreatesUser = false.obs; // 只能管理自己创建的用户 + RxBool isAuthentication = false.obs; //是否可以实名认证 + final RxBool onlyManageYouCreatesUser = false.obs; // 只能管理自己创建的用户 - var beginDate = DateTool() + RxString beginDate = DateTool() .dateToYMDHNString(DateTime.now().millisecondsSinceEpoch.toString()) .obs; //默认为当前时间 开始时间 - var endDate = DateTool() + RxString endDate = DateTool() .dateToYMDHNString(DateTime.now().millisecondsSinceEpoch.toString()) .obs; //默认为当前时间 结束时间 - var isSendSuccess = false.obs; - var countryName = '中国'.obs; - var countryCode = '86'.obs; - var weekdaysList = [].obs; - var isCreateUser = false.obs; //用户未注册时传1 已注册传0 + RxBool isSendSuccess = false.obs; + RxString countryName = '中国'.obs; + RxString countryCode = '86'.obs; + RxList weekdaysList = [].obs; + RxBool isCreateUser = false.obs; //用户未注册时传1 已注册传0 - var seletType = 0.obs; + RxInt seletType = 0.obs; String pwdShareStr = '您好,您的授权管理员生成成功'; - var addUserId = ''.obs; - var isRequireAuth = false.obs; //是否需要实名认证的必填项 + RxString addUserId = ''.obs; + RxBool isRequireAuth = false.obs; //是否需要实名认证的必填项 } diff --git a/lib/main/lockDetail/authorizedAdmin/volumeAuthorizationLock/notice_template_entity.dart b/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/notice_template_entity.dart similarity index 100% rename from lib/main/lockDetail/authorizedAdmin/volumeAuthorizationLock/notice_template_entity.dart rename to lib/main/lockDetail/authorizedAdmin/authorizedAdmin/notice_template_entity.dart diff --git a/lib/main/lockDetail/authorizedAdmin/volumeAuthorizationLock/volumeAuthorizationLock_logic.dart b/lib/main/lockDetail/authorizedAdmin/volumeAuthorizationLock/volumeAuthorizationLock_logic.dart index d75cd07c..0c4ab05b 100755 --- a/lib/main/lockDetail/authorizedAdmin/volumeAuthorizationLock/volumeAuthorizationLock_logic.dart +++ b/lib/main/lockDetail/authorizedAdmin/volumeAuthorizationLock/volumeAuthorizationLock_logic.dart @@ -2,7 +2,7 @@ import 'dart:ffi'; import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:get/get.dart'; -import 'package:star_lock/main/lockDetail/authorizedAdmin/volumeAuthorizationLock/notice_template_entity.dart'; +import 'package:star_lock/main/lockDetail/authorizedAdmin/authorizedAdmin/notice_template_entity.dart'; import 'package:star_lock/main/lockDetail/lockSet/basicInformation/basicInformation/KeyDetailEntity.dart'; import 'package:star_lock/network/api_repository.dart'; import 'package:star_lock/tools/baseGetXController.dart'; diff --git a/lib/main/lockMian/lockList/lockList_logic.dart b/lib/main/lockMian/lockList/lockList_logic.dart index fff0e86b..14b08463 100755 --- a/lib/main/lockMian/lockList/lockList_logic.dart +++ b/lib/main/lockMian/lockList/lockList_logic.dart @@ -4,7 +4,6 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/scheduler.dart'; import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:get/get.dart'; -import 'package:star_lock/blue/io_type.dart'; import 'package:star_lock/tools/baseGetXController.dart'; import '../../../blue/blue_manage.dart'; @@ -23,26 +22,44 @@ import '../../../translations/trans_lib.dart'; import '../entity/lockListInfo_entity.dart'; import 'lockList_state.dart'; -class LockListLogic extends BaseGetXController{ +class LockListLogic extends BaseGetXController { + LockListLogic(this.entity){ + } + LockListState state = LockListState(); + List groupDataList = []; + LockListInfoGroupEntity? entity; + + //设置数据 + void setLockListInfoGroupEntity(LockListInfoGroupEntity entity) { + this.entity = entity; + if (entity.pageNo == 1) { + groupDataList = []; + } + groupDataList.addAll(entity.groupList!); + update(); + } // 监听蓝牙协议返回结果 late StreamSubscription _replySubscription; + void _initReplySubscription() { - _replySubscription = EventBusManager().eventBus!.on().listen((reply) async { + _replySubscription = + EventBusManager().eventBus!.on().listen((Reply reply) async { // 恢复出厂设置 - if ((reply is FactoryDataResetReply) && (state.ifCurrentScreen.value == true)) { + if ((reply is FactoryDataResetReply) && + (state.ifCurrentScreen.value == true)) { _replyFactoryDataResetKey(reply); } }); } Future _replyFactoryDataResetKey(Reply reply) async { - var token = reply.data.sublist(2, 6); - var saveStrList = changeIntListToStringList(token); + final List token = reply.data.sublist(2, 6); + final List saveStrList = changeIntListToStringList(token); Storage.setStringList(saveBlueToken, saveStrList); - int status = reply.data[6]; + final int status = reply.data[6]; switch (status) { case 0x00: //成功 @@ -52,22 +69,24 @@ class LockListLogic extends BaseGetXController{ break; case 0x06: //无权限 - var token = await Storage.getStringList(saveBlueToken); - List getTokenList = changeStringListToIntList(token!); + final List? token = await Storage.getStringList(saveBlueToken); + final List getTokenList = changeStringListToIntList(token!); IoSenderManage.senderFactoryDataReset( lockID: BlueManage().connectDeviceName, userID: await Storage.getUid(), - keyID: "1", + keyID: '1', needAuthor: 1, - publicKey: state.lockListInfoItemEntity.bluetooth!.publicKey!.cast(), - privateKey: state.lockListInfoItemEntity.bluetooth!.privateKey!.cast(), + publicKey: + state.lockListInfoItemEntity.bluetooth!.publicKey!.cast(), + privateKey: + state.lockListInfoItemEntity.bluetooth!.privateKey!.cast(), token: getTokenList); break; case 0x07: //无权限 dismissEasyLoading(); - showToast("用户无权限"); + showToast('用户无权限'); break; case 0x09: // 权限校验错误 @@ -82,62 +101,63 @@ class LockListLogic extends BaseGetXController{ } } - String showElectricIcon (int electricnumber){ - if(electricnumber >= 100){ + String showElectricIcon(int electricnumber) { + if (electricnumber >= 100) { return 'images/main/icon_lockElectricLevel_5.png'; - }else if((electricnumber > 50) && (electricnumber < 100)){ + } else if ((electricnumber > 50) && (electricnumber < 100)) { return 'images/main/icon_lockElectricLevel_4.png'; - }else if((electricnumber > 25) && (electricnumber <= 50)){ + } else if ((electricnumber > 25) && (electricnumber <= 50)) { return 'images/main/icon_lockElectricLevel_3.png'; - }else if((electricnumber > 5) && (electricnumber <= 25)){ + } else if ((electricnumber > 5) && (electricnumber <= 25)) { return 'images/main/icon_lockElectricLevel_2.png'; - }else if(electricnumber <= 5){ + } else if (electricnumber <= 5) { return 'images/main/icon_lockElectricLevel_1.png'; } return 'images/main/icon_lockElectricLevel_5.png'; } - String getKeyEffective(LockListInfoItemEntity keyInfo){ + String getKeyEffective(LockListInfoItemEntity keyInfo) { // 当是限时、循环的时候 - if(keyInfo.keyType == XSConstantMacro.keyTypeTime || keyInfo.keyType == XSConstantMacro.keyTypeLoop){ + if (keyInfo.keyType == XSConstantMacro.keyTypeTime || + keyInfo.keyType == XSConstantMacro.keyTypeLoop) { // 当是正常使用跟待接收状态的时候 - if(keyInfo.keyStatus == XSConstantMacro.keyStatusNormalUse || keyInfo.keyStatus == XSConstantMacro.keyStatusWaitReceive) { + if (keyInfo.keyStatus == XSConstantMacro.keyStatusNormalUse || + keyInfo.keyStatus == XSConstantMacro.keyStatusWaitReceive) { return "${"余".tr}${DateTool().compareTimeGetDaysFromNow(keyInfo.endDate!)}${"天".tr}"; } else { return XSConstantMacro.getKeyStatusStr(keyInfo.keyStatus!); } } - return ""; + return ''; } -/// 以下为删除逻辑 - deleyLockLogicOfRoles(){ + /// 以下为删除逻辑 + void deleyLockLogicOfRoles() { if (state.lockListInfoItemEntity.isLockOwner == 1) { // 超级管理员必须通过连接蓝牙删除 - ShowTipView().showIosTipWithContentDialog("删除锁后,所有信息都会一起删除,确定删除锁吗?".tr, (){ + ShowTipView().showIosTipWithContentDialog('删除锁后,所有信息都会一起删除,确定删除锁吗?'.tr, + () { // 删除锁 - ShowTipView().showTFViewAlertDialog(state.passwordTF, "请输入登录密码".tr, "请输入登录密码".tr, (){ - checkLoginPassword(); - }); + ShowTipView().showTFViewAlertDialog( + state.passwordTF, '请输入登录密码'.tr, '请输入登录密码'.tr, checkLoginPassword); }); - } else if (state.lockListInfoItemEntity.keyRight == 1){ + } else if (state.lockListInfoItemEntity.keyRight == 1) { // 授权管理员弹框提示 - ShowTipView().showDeleteAdministratorIsHaveAllDataDialog("同时删除其发送的所有钥匙,钥匙删除后不能恢复".tr, (a){ + ShowTipView().showDeleteAdministratorIsHaveAllDataDialog( + '同时删除其发送的所有钥匙,钥匙删除后不能恢复'.tr, (bool a) { // 授权管理员删除 state.deleteAdministratorIsHaveAllData.value = a; deletKeyData(); }); - } else{ + } else { // 普通用户直接删除 - ShowTipView().showIosTipWithContentDialog("是否删除钥匙?".tr, (){ - deletKeyData(); - }); + ShowTipView().showIosTipWithContentDialog('是否删除钥匙?'.tr, deletKeyData); } } // 查询账户密码 - void checkLoginPassword() async { - var entity = await ApiRepository.to.checkLoginPassword( + Future checkLoginPassword() async { + final LockListInfoEntity entity = await ApiRepository.to.checkLoginPassword( password: state.passwordTF.text, ); if (entity.errorCode!.codeIsSuccessful) { @@ -147,12 +167,12 @@ class LockListLogic extends BaseGetXController{ } // 当是锁拥有者的时候,删除锁 - void deletLockInfoData() async { - var entity = await ApiRepository.to.deletOwnerLockData( + Future deletLockInfoData() async { + final LockListInfoEntity entity = await ApiRepository.to.deletOwnerLockData( lockId: state.lockListInfoItemEntity.lockId!, ); if (entity.errorCode!.codeIsSuccessful) { - BlueManage().connectDeviceMacAddress = ""; + BlueManage().connectDeviceMacAddress = ''; SchedulerBinding.instance.addPostFrameCallback((_) { eventBus.fire(RefreshLockListInfoDataEvent()); }); @@ -160,14 +180,14 @@ class LockListLogic extends BaseGetXController{ } // 普通用户或者授权管理员删除钥匙 - void deletKeyData() async { - var entity = await ApiRepository.to.deletOwnerKeyData( + Future deletKeyData() async { + final LockListInfoEntity entity = await ApiRepository.to.deletOwnerKeyData( lockId: state.lockListInfoItemEntity.lockId.toString(), keyId: state.lockListInfoItemEntity.keyId.toString(), - includeUnderlings: state.deleteAdministratorIsHaveAllData.value == true ? 1 : 0 - ); + includeUnderlings: + state.deleteAdministratorIsHaveAllData.value == true ? 1 : 0); if (entity.errorCode!.codeIsSuccessful) { - BlueManage().connectDeviceMacAddress = ""; + BlueManage().connectDeviceMacAddress = ''; SchedulerBinding.instance.addPostFrameCallback((_) { eventBus.fire(RefreshLockListInfoDataEvent()); }); @@ -177,62 +197,74 @@ class LockListLogic extends BaseGetXController{ // 恢复出厂设置 Future factoryDataResetAction() async { showEasyLoading(); - showBlueConnetctToastTimer(isShowBlueConnetctToast: false, action: (){ - dismissEasyLoading(); - showDeletAlertTipDialog(); - }); - BlueManage().blueSendData(state.lockListInfoItemEntity.lockName!, (BluetoothConnectionState connectionState) async { + showBlueConnetctToastTimer( + isShowBlueConnetctToast: false, + action: () { + dismissEasyLoading(); + showDeletAlertTipDialog(); + }); + BlueManage().blueSendData(state.lockListInfoItemEntity.lockName!, + (BluetoothConnectionState connectionState) async { if (connectionState == BluetoothConnectionState.connected) { - List publicKeyData = state.lockListInfoItemEntity.bluetooth!.publicKey!.cast(); - var saveStrList = changeIntListToStringList(publicKeyData); + final List publicKeyData = + state.lockListInfoItemEntity.bluetooth!.publicKey!.cast(); + final List saveStrList = + changeIntListToStringList(publicKeyData); Storage.setStringList(saveBluePublicKey, saveStrList); // 私钥 - List privateKeyData = state.lockListInfoItemEntity.bluetooth!.privateKey!.cast(); - var savePrivateKeyList = changeIntListToStringList(privateKeyData); + final List privateKeyData = + state.lockListInfoItemEntity.bluetooth!.privateKey!.cast(); + final List savePrivateKeyList = + changeIntListToStringList(privateKeyData); Storage.setStringList(saveBluePrivateKey, savePrivateKeyList); // signKey - List signKeyData = state.lockListInfoItemEntity.bluetooth!.signKey!.cast(); - var saveSignKeyList = changeIntListToStringList(signKeyData); + final List signKeyData = + state.lockListInfoItemEntity.bluetooth!.signKey!.cast(); + final List saveSignKeyList = + changeIntListToStringList(signKeyData); Storage.setStringList(saveBlueSignKey, saveSignKeyList); - var saveTokenList = changeIntListToStringList([0, 0, 0, 0]); + final List saveTokenList = + changeIntListToStringList([0, 0, 0, 0]); Storage.setStringList(saveBlueToken, saveTokenList); IoSenderManage.senderFactoryDataReset( lockID: BlueManage().connectDeviceName, userID: await Storage.getUid(), - keyID: "1", + keyID: '1', needAuthor: 1, - publicKey: state.lockListInfoItemEntity.bluetooth!.publicKey!.cast(), - privateKey: state.lockListInfoItemEntity.bluetooth!.privateKey!.cast(), - token: [0,0,0,0]); + publicKey: + state.lockListInfoItemEntity.bluetooth!.publicKey!.cast(), + privateKey: + state.lockListInfoItemEntity.bluetooth!.privateKey!.cast(), + token: [0, 0, 0, 0]); } else if (connectionState == BluetoothConnectionState.disconnected) { dismissEasyLoading(); cancelBlueConnetctToastTimer(); - if(state.ifCurrentScreen.value == true){ + if (state.ifCurrentScreen.value == true) { showDeletAlertTipDialog(); } } }); } - void showDeletAlertTipDialog({String? showContent = ""}) { + void showDeletAlertTipDialog({String? showContent = ''}) { // bool isContains = BlueManage().connectDeviceName!.contains("T9A"); - var content = showContent!.isEmpty ? "${"删除设备失败,请确保在设备附近,设备未被连接,设备已打开".tr}${BlueManage().connectDeviceName!.contains("T9A") == true ? "。如果是全自动锁,请使屏幕变亮".tr : ""}" : showContent; + final String content = showContent!.isEmpty + ? "${"删除设备失败,请确保在设备附近,设备未被连接,设备已打开".tr}${BlueManage().connectDeviceName.contains("T9A") == true ? "。如果是全自动锁,请使屏幕变亮".tr : ""}" + : showContent; showCupertinoDialog( context: Get.context!, - builder: (context) { + builder: (BuildContext context) { return CupertinoAlertDialog( - title: Text("提示".tr), + title: Text('提示'.tr), content: Text(content), - actions: [ + actions: [ CupertinoDialogAction( child: Text(TranslationLoader.lanKeys!.sure!.tr), - onPressed: () { - Get.back(); - }, + onPressed: Get.back, ), ], ); @@ -242,23 +274,18 @@ class LockListLogic extends BaseGetXController{ @override void onReady() { - // TODO: implement onReady super.onReady(); - _initReplySubscription(); } @override void onInit() { - // TODO: implement onInit super.onInit(); + setLockListInfoGroupEntity(entity!); } @override void onClose() { - // TODO: implement onClose - _replySubscription.cancel(); } - -} \ No newline at end of file +} diff --git a/lib/main/lockMian/lockList/lockList_page.dart b/lib/main/lockMian/lockList/lockList_page.dart index 38416753..53717840 100755 --- a/lib/main/lockMian/lockList/lockList_page.dart +++ b/lib/main/lockMian/lockList/lockList_page.dart @@ -3,6 +3,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_slidable/flutter_slidable.dart'; import 'package:get/get.dart'; import 'package:star_lock/flavors.dart'; +import 'package:star_lock/main/lockMian/lockList/lockList_state.dart'; import '../../../appRouters.dart'; import '../../../app_settings/app_colors.dart'; @@ -14,50 +15,53 @@ import 'lockListGroup_view.dart'; import 'lockList_logic.dart'; class LockListPage extends StatefulWidget { - final LockListInfoGroupEntity lockListInfoGroupEntity; - const LockListPage({Key? key, required this.lockListInfoGroupEntity}) + const LockListPage({required this.lockListInfoGroupEntity, Key? key}) : super(key: key); + final LockListInfoGroupEntity lockListInfoGroupEntity; @override State createState() => _LockListPageState(); } class _LockListPageState extends State with RouteAware { - final logic = Get.put(LockListLogic()); - final state = Get.find().state; + late LockListLogic logic; + late LockListState state; - var groupDataList = []; + @override + void initState() { + super.initState(); + logic = Get.put(LockListLogic(widget.lockListInfoGroupEntity)); + state = Get.find().state; + } @override Widget build(BuildContext context) { - if (widget.lockListInfoGroupEntity.pageNo == 1) { - groupDataList = []; - } - groupDataList.addAll( - widget.lockListInfoGroupEntity.groupList as Iterable); - - return Scaffold( - body: ListView.separated( - itemCount: groupDataList.length, - itemBuilder: (context, index) { - GroupList itemData = groupDataList[index]; - return _buildLockExpandedList(context, index, itemData); - }, - shrinkWrap: true, - physics: const AlwaysScrollableScrollPhysics(), - separatorBuilder: (context, index) { - return const Divider( - height: 1, - color: AppColors.greyLineColor, - ); - }), - ); + return GetBuilder(builder: (LockListLogic logic) { + return Scaffold( + body: ListView.separated( + itemCount: logic.groupDataList.length, + itemBuilder: (BuildContext context, int index) { + final GroupList itemData = logic.groupDataList[index]; + return _buildLockExpandedList(context, index, itemData); + }, + shrinkWrap: true, + physics: const AlwaysScrollableScrollPhysics(), + separatorBuilder: (BuildContext context, int index) { + return const Divider( + height: 1, + color: AppColors.greyLineColor, + ); + }), + ); + }); } //设备多层级列表 - Widget _buildLockExpandedList(context, index, GroupList itemData) { - List lockItemList = itemData.lockList ?? []; + Widget _buildLockExpandedList( + BuildContext context, int index, GroupList itemData) { + final List lockItemList = + itemData.lockList ?? []; return LockListGroupView( onTap: () { //是否选中组 @@ -65,28 +69,28 @@ class _LockListPageState extends State with RouteAware { } else {} setState(() {}); }, - typeImgList: const [], + typeImgList: const [], groupItem: itemData, child: ListView.separated( itemCount: lockItemList.length, shrinkWrap: true, physics: const NeverScrollableScrollPhysics(), - separatorBuilder: (context, index) { + separatorBuilder: (BuildContext context, int index) { return const Divider(height: 1, color: AppColors.greyLineColor); }, - itemBuilder: (c, index) { - LockListInfoItemEntity keyInfo = lockItemList[index]; + itemBuilder: (BuildContext c, int index) { + final LockListInfoItemEntity keyInfo = lockItemList[index]; bool isLast = false; if (lockItemList.length == index + 1) { isLast = true; } return Slidable( - key: ValueKey(keyInfo.keyId), + key: ValueKey(keyInfo.keyId), endActionPane: ActionPane( extentRatio: 0.2, motion: const ScrollMotion(), - children: [ + children: [ SlidableAction( onPressed: (BuildContext context) { state.lockListInfoItemEntity = keyInfo; @@ -104,26 +108,27 @@ class _LockListPageState extends State with RouteAware { keyInfo.keyType == XSConstantMacro.keyTypeLoop) && (keyInfo.keyStatus == XSConstantMacro.keyStatusWaitIneffective)) { - logic.showToast("您的钥匙未生效".tr); + logic.showToast('您的钥匙未生效'.tr); return; } if ((keyInfo.keyType == XSConstantMacro.keyTypeTime || keyInfo.keyType == XSConstantMacro.keyTypeLoop) && (keyInfo.keyStatus == XSConstantMacro.keyStatusFrozen)) { - logic.showToast("您的钥匙已冻结".tr); + logic.showToast('您的钥匙已冻结'.tr); return; } if ((keyInfo.keyType == XSConstantMacro.keyTypeTime || keyInfo.keyType == XSConstantMacro.keyTypeLoop) && (keyInfo.keyStatus == XSConstantMacro.keyStatusExpired)) { - logic.showToast("您的钥匙已过期".tr); + logic.showToast('您的钥匙已过期'.tr); return; } - Get.toNamed(Routers.lockDetailMainPage, arguments: { - // "lockMainEntity": widget.lockMainEntity, - "keyInfo": keyInfo, - "isOnlyOneData": false, - }); + Get.toNamed(Routers.lockDetailMainPage, + arguments: { + // "lockMainEntity": widget.lockMainEntity, + 'keyInfo': keyInfo, + 'isOnlyOneData': false, + }); }), ); }), @@ -152,18 +157,18 @@ class _LockListPageState extends State with RouteAware { ), child: Column( // mainAxisAlignment: MainAxisAlignment.center, - children: [ + children: [ SizedBox( height: 20.h, ), Row( - children: [ + children: [ SizedBox(width: 30.w), Expanded( child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start, - children: [ + children: [ Text( keyInfo.lockAlias!, style: TextStyle( @@ -184,7 +189,7 @@ class _LockListPageState extends State with RouteAware { ), SizedBox(width: 2.w), Text( - "${keyInfo.electricQuantity!}%", + '${keyInfo.electricQuantity!}%', style: TextStyle( fontSize: 18.sp, color: AppColors.darkGrayTextColor), ), @@ -193,9 +198,9 @@ class _LockListPageState extends State with RouteAware { ), SizedBox(height: 5.h), Visibility( - visible: keyInfo.passageMode == 1 ? true : false, + visible: keyInfo.passageMode == 1, child: Row( - children: [ + children: [ SizedBox(width: 30.w), Container( padding: EdgeInsets.only(right: 5.w, left: 5.w), @@ -203,7 +208,7 @@ class _LockListPageState extends State with RouteAware { borderRadius: BorderRadius.circular(5.w), color: AppColors.openPassageModeColor, ), - child: Text("常开模式开启".tr, + child: Text('常开模式开启'.tr, style: TextStyle( fontSize: 18.sp, color: AppColors.appBarIconColor)), @@ -212,12 +217,12 @@ class _LockListPageState extends State with RouteAware { )), SizedBox(height: 5.h), Visibility( - visible: keyInfo.lockSetting!.remoteUnlock == 1 ? true : false, + visible: keyInfo.lockSetting!.remoteUnlock == 1, child: Row( - children: [ + children: [ SizedBox(width: 30.w), Text( - "远程开锁".tr, + '远程开锁'.tr, style: TextStyle( fontSize: 18.sp, color: AppColors.darkGrayTextColor), ), @@ -225,19 +230,15 @@ class _LockListPageState extends State with RouteAware { )), SizedBox(height: 20.h), Visibility( - visible: ((keyInfo.keyType == XSConstantMacro.keyTypeTime || - keyInfo.keyType == XSConstantMacro.keyTypeLoop) && - (keyInfo.keyStatus == - XSConstantMacro.keyStatusWaitIneffective || - keyInfo.keyStatus == - XSConstantMacro.keyStatusFrozen || - keyInfo.keyStatus == - XSConstantMacro.keyStatusExpired)) - ? true - : false, + visible: (keyInfo.keyType == XSConstantMacro.keyTypeTime || + keyInfo.keyType == XSConstantMacro.keyTypeLoop) && + (keyInfo.keyStatus == + XSConstantMacro.keyStatusWaitIneffective || + keyInfo.keyStatus == XSConstantMacro.keyStatusFrozen || + keyInfo.keyStatus == XSConstantMacro.keyStatusExpired), // visible: true, child: Row( - children: [ + children: [ SizedBox(width: 30.w), Container( padding: EdgeInsets.only(right: 5.w, left: 5.w), @@ -257,7 +258,7 @@ class _LockListPageState extends State with RouteAware { )), SizedBox(height: 5.h), Row( - children: [ + children: [ SizedBox(width: 30.w), Text( "${logic.getUseKeyTypeStr(keyInfo.startDate, keyInfo.endDate, keyInfo.keyType)}/${keyInfo.isLockOwner == 1 ? '超级管理员'.tr : (keyInfo.keyRight == 1 ? "授权管理员".tr : "普通用户".tr)}", diff --git a/lib/main/lockMian/lockList/lockList_xhj_page.dart b/lib/main/lockMian/lockList/lockList_xhj_page.dart index 6bdd40b6..54f439e8 100755 --- a/lib/main/lockMian/lockList/lockList_xhj_page.dart +++ b/lib/main/lockMian/lockList/lockList_xhj_page.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_slidable/flutter_slidable.dart'; import 'package:get/get.dart'; -import 'package:star_lock/flavors.dart'; +import 'package:star_lock/main/lockMian/lockList/lockList_state.dart'; import '../../../appRouters.dart'; import '../../../app_settings/app_colors.dart'; @@ -14,87 +14,90 @@ import 'lockListGroup_view.dart'; import 'lockList_logic.dart'; class LockListXHJPage extends StatefulWidget { - final LockListInfoGroupEntity lockListInfoGroupEntity; - const LockListXHJPage({Key? key, required this.lockListInfoGroupEntity}) + const LockListXHJPage({required this.lockListInfoGroupEntity, Key? key}) : super(key: key); + final LockListInfoGroupEntity lockListInfoGroupEntity; @override State createState() => _LockListXHJPageState(); } class _LockListXHJPageState extends State with RouteAware { - final logic = Get.put(LockListLogic()); - final state = Get.find().state; + late LockListLogic logic; + late LockListState state; - var groupDataList = []; + @override + void initState() { + super.initState(); + logic = Get.put(LockListLogic(widget.lockListInfoGroupEntity)); + state = Get.find().state; + } @override Widget build(BuildContext context) { - if (widget.lockListInfoGroupEntity.pageNo == 1) { - groupDataList = []; - } - groupDataList.addAll( - widget.lockListInfoGroupEntity.groupList as Iterable); - return SafeArea( - bottom: false, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Align( - alignment: Alignment.topRight, - child: IconButton( - onPressed: () { - Get.toNamed(Routers.selectLockTypePage); - }, - icon: Icon( - Icons.add_circle, - size: 48.w, - color: AppColors.mainColor, - )), - ), - Padding( - padding: EdgeInsets.only(left: 45.w), - child: Text( - '常用程序'.tr, - style: TextStyle( - fontSize: 32.sp, - color: AppColors.blackColor, - fontWeight: FontWeight.w600, + return GetBuilder(builder: (LockListLogic logic) { + return SafeArea( + bottom: false, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Align( + alignment: Alignment.topRight, + child: IconButton( + onPressed: () { + Get.toNamed(Routers.selectLockTypePage); + }, + icon: Icon( + Icons.add_circle, + size: 48.w, + color: AppColors.mainColor, + )), + ), + Padding( + padding: EdgeInsets.only(left: 45.w), + child: Text( + '常用程序'.tr, + style: TextStyle( + fontSize: 32.sp, + color: AppColors.blackColor, + fontWeight: FontWeight.w600, + ), ), ), - ), - Expanded( - child: ListView.separated( - itemCount: groupDataList.length, - itemBuilder: (context, index) { - GroupList itemData = groupDataList[index]; - return _buildLockExpandedList(context, index, itemData); - }, - shrinkWrap: true, - physics: const AlwaysScrollableScrollPhysics(), - separatorBuilder: (context, index) { - return const Divider( - height: 1, - color: AppColors.greyLineColor, - ); - }), - ), - ], - ), - ); + Expanded( + child: ListView.separated( + itemCount: logic.groupDataList.length, + itemBuilder: (BuildContext context, int index) { + final GroupList itemData = logic.groupDataList[index]; + return _buildLockExpandedList(context, index, itemData); + }, + shrinkWrap: true, + physics: const AlwaysScrollableScrollPhysics(), + separatorBuilder: (BuildContext context, int index) { + return const Divider( + height: 1, + color: AppColors.greyLineColor, + ); + }), + ), + ], + ), + ); + }); } //设备多层级列表 Widget _buildLockExpandedList(context, index, GroupList itemData) { - List lockItemList = itemData.lockList ?? []; + final List lockItemList = + itemData.lockList ?? []; return LockListGroupView( onTap: () { setState(() {}); }, textStyle: TextStyle(fontSize: 28.sp, fontWeight: FontWeight.w600), backgroundColor: Colors.transparent, - typeImgList: const [], + typeImgList: const [], groupItem: itemData, child: GridView.extent( padding: EdgeInsets.symmetric(vertical: 15.h, horizontal: 15.w), @@ -109,9 +112,9 @@ class _LockListXHJPageState extends State with RouteAware { } List forItems(List lockItemList) { - List list = []; + final List list = []; for (int i = 0, j = 0; i < lockItemList.length; i++, j++) { - LockListInfoItemEntity keyInfo = lockItemList[i]; + final LockListInfoItemEntity keyInfo = lockItemList[i]; bool isLast = false; if (lockItemList.length == i + 1) { isLast = true; @@ -121,7 +124,7 @@ class _LockListXHJPageState extends State with RouteAware { endActionPane: ActionPane( extentRatio: 0.2, motion: const ScrollMotion(), - children: [ + children: [ SlidableAction( onPressed: (BuildContext context) { state.lockListInfoItemEntity = keyInfo; @@ -153,7 +156,7 @@ class _LockListXHJPageState extends State with RouteAware { logic.showToast("您的钥匙已过期".tr); return; } - Get.toNamed(Routers.lockDetailMainPage, arguments: { + Get.toNamed(Routers.lockDetailMainPage, arguments: { "keyInfo": keyInfo, "isOnlyOneData": false, }); @@ -189,9 +192,9 @@ class _LockListXHJPageState extends State with RouteAware { child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.center, - children: [ + children: [ Row( - children: [ + children: [ Image.asset( 'images/icon_lock_circle.png', width: 32.r, @@ -218,7 +221,7 @@ class _LockListXHJPageState extends State with RouteAware { child: Padding( padding: EdgeInsets.only(top: 5.h), child: Row( - children: [ + children: [ Container( padding: EdgeInsets.only(right: 5.w, left: 5.w), decoration: BoxDecoration( @@ -239,7 +242,7 @@ class _LockListXHJPageState extends State with RouteAware { child: Padding( padding: EdgeInsets.only(top: 5.h), child: Row( - children: [ + children: [ Text( "远程开锁".tr, style: TextStyle( @@ -263,7 +266,7 @@ class _LockListXHJPageState extends State with RouteAware { child: Padding( padding: EdgeInsets.only(top: 20.h), child: Row( - children: [ + children: [ Container( padding: EdgeInsets.only(right: 5.w, left: 5.w), decoration: BoxDecoration( @@ -284,7 +287,7 @@ class _LockListXHJPageState extends State with RouteAware { )), SizedBox(height: 5.h), Row( - children: [ + children: [ Expanded( child: Text( keyInfo.isLockOwner == 1 diff --git a/lib/main/lockMian/lockMain/lockMain_logic.dart b/lib/main/lockMian/lockMain/lockMain_logic.dart index af2032bf..50c0c767 100755 --- a/lib/main/lockMian/lockMain/lockMain_logic.dart +++ b/lib/main/lockMian/lockMain/lockMain_logic.dart @@ -1,7 +1,7 @@ - import 'dart:async'; import 'package:connectivity_plus/connectivity_plus.dart'; import 'package:get/get.dart'; +import 'package:star_lock/main/lockMian/lockList/lockList_logic.dart'; import '../../../app_settings/app_settings.dart'; import '../../../blue/blue_manage.dart'; @@ -15,7 +15,8 @@ import 'lockMain_state.dart'; class LockMainLogic extends BaseGetXController { final LockMainState state = LockMainState(); - Future getStarLockInfo({bool isUnShowLoading = false}) async { + Future getStarLockInfo( + {bool isUnShowLoading = false}) async { LockListInfoEntity entity = await ApiRepository.to.getStarLockListInfo( pageNo: pageNo, pageSize: 50, @@ -35,11 +36,11 @@ class LockMainLogic extends BaseGetXController { return entity; } - Future loadMainDataLogic(LockListInfoGroupEntity entity){ + void loadMainDataLogic(LockListInfoGroupEntity entity) { if (entity.groupList!.isEmpty) { state.dataLength.value = 0; } else if (entity.groupList!.length == 1) { - GroupList groupList = entity.groupList![0]; + final GroupList groupList = entity.groupList![0]; if (groupList.lockList!.length > 1) { state.dataLength.value = 2; } else { @@ -49,7 +50,11 @@ class LockMainLogic extends BaseGetXController { state.dataLength.value = 2; } state.lockListInfoGroupEntity.value = entity; - return Future.value(); + //检测控制器是否存在 + if (Get.isRegistered()) { + //设置控制器数据并刷新 + Get.find().setLockListInfoGroupEntity(entity); + } } /// 获取联网类型 @@ -81,7 +86,8 @@ class LockMainLogic extends BaseGetXController { connectListener() async { Connectivity().onConnectivityChanged.listen((ConnectivityResult result) { AppLog.log("设置网络切换监听:$result"); - if (state.networkConnectionStatus.value == 0 && result != ConnectivityResult.none) { + if (state.networkConnectionStatus.value == 0 && + result != ConnectivityResult.none) { // 从无网络到有网络 state.networkConnectionStatus.value = 1; getStarLockInfo(); diff --git a/lib/main/lockMian/lockMain/lockMain_page.dart b/lib/main/lockMian/lockMain/lockMain_page.dart index d8d7b3cb..43ec0957 100755 --- a/lib/main/lockMian/lockMain/lockMain_page.dart +++ b/lib/main/lockMian/lockMain/lockMain_page.dart @@ -43,7 +43,7 @@ class _StarLockMainPageState extends State with BaseWidget { await Storage.getLockMainListData(); if (lockListInfoGroupEntity != null) { var localLockListInfoGroupEntity = lockListInfoGroupEntity; - await logic.loadMainDataLogic(localLockListInfoGroupEntity); + logic.loadMainDataLogic(localLockListInfoGroupEntity); } await logic.getStarLockInfo(isUnShowLoading: isUnShowLoading); await Future.delayed(const Duration(milliseconds: 200)); diff --git a/lib/mine/addLock/nearbyLock/nearbyLock_logic.dart b/lib/mine/addLock/nearbyLock/nearbyLock_logic.dart index f703e39a..cd8e1f3a 100755 --- a/lib/mine/addLock/nearbyLock/nearbyLock_logic.dart +++ b/lib/mine/addLock/nearbyLock/nearbyLock_logic.dart @@ -43,7 +43,7 @@ class NearbyLockLogic extends BaseGetXController { // 点击连接设备 void connect(String deviceName) { - showTitleEasyLoading("获取锁信息 1/3"); + showTitleEasyLoading('获取锁信息 1/3'); // if(state.sureBtnState.value == 1){ // return; // } @@ -56,9 +56,9 @@ class NearbyLockLogic extends BaseGetXController { }); BlueManage().blueSendData(deviceName, (BluetoothConnectionState state) async { - AppLog.log("点击要添加的设备了"); + AppLog.log('点击要添加的设备了'); if (state == BluetoothConnectionState.connected) { - AppLog.log("开始获取公钥"); + AppLog.log('开始获取公钥'); IoSenderManage.getPublicKey(lockId: deviceName); } else if (state == BluetoothConnectionState.disconnected) { dismissEasyLoading(); @@ -108,18 +108,18 @@ class NearbyLockLogic extends BaseGetXController { switch (reply.status) { case 0x00: //成功 - AppLog.log("获取公钥成功"); + AppLog.log('获取公钥成功'); // 储存公钥 var publicKey = reply.data.sublist(3); var saveStrList = changeIntListToStringList(publicKey); Storage.setStringList(saveBluePublicKey, saveStrList); // 获取私钥 - AppLog.log("开始获取私钥"); - showTitleEasyLoading("获取锁信息 2/3"); + AppLog.log('开始获取私钥'); + showTitleEasyLoading('获取锁信息 2/3'); IoSenderManage.getPrivateKey( lockId: BlueManage().connectDeviceName, - keyID: "1", + keyID: '1', authUserID: await Storage.getUid(), nowTime: DateTime.now().millisecondsSinceEpoch ~/ 1000, publicKeyData: publicKey, @@ -127,7 +127,7 @@ class NearbyLockLogic extends BaseGetXController { break; default: // state.sureBtnState.value = 0; - AppLog.log("获取公钥失败"); + AppLog.log('获取公钥失败'); break; } } @@ -135,7 +135,7 @@ class NearbyLockLogic extends BaseGetXController { Future _replyGetPrivateKeyKey(Reply reply) async { switch (reply.status) { case 0x00: - AppLog.log("获取私钥成功"); + AppLog.log('获取私钥成功'); //成功 reply.data.removeAt(0); @@ -156,7 +156,7 @@ class NearbyLockLogic extends BaseGetXController { (0xff & timestamp[2]) << 8 | (0xFF & timestamp[3])); - showTitleEasyLoading("获取锁信息 3/3"); + showTitleEasyLoading('获取锁信息 3/3'); _getStarLockStatus(); break; default: @@ -171,83 +171,83 @@ class NearbyLockLogic extends BaseGetXController { switch (status) { case 0x00: //成功 - AppLog.log("获取锁状态成功"); + AppLog.log('获取锁状态成功'); // 厂商名称 var index = 3; var vendor = reply.data.sublist(index, index + 20); var vendorStr = utf8String(vendor); - state.lockInfo["vendor"] = vendorStr; + state.lockInfo['vendor'] = vendorStr; // state.lockInfo["vendor"] = "XL"; index = index + 20; - AppLog.log("厂商名称 vendorStr:$vendorStr"); + AppLog.log('厂商名称 vendorStr:$vendorStr'); // 锁设备类型 var product = reply.data[index]; - state.lockInfo["product"] = product; + state.lockInfo['product'] = product; index = index + 1; - AppLog.log("锁设备类型 product:$product"); + AppLog.log('锁设备类型 product:$product'); // 产品名称 var model = reply.data.sublist(index, index + 20); var modelStr = utf8String(model); - state.lockInfo["model"] = modelStr; + state.lockInfo['model'] = modelStr; // state.lockInfo["model"] = "JL-BLE-01"; index = index + 20; - AppLog.log("产品名称 mmodelStr:$modelStr"); + AppLog.log('产品名称 mmodelStr:$modelStr'); // 软件版本 var fwVersion = reply.data.sublist(index, index+20); var fwVersionStr = utf8String(fwVersion); - state.lockInfo["fwVersion"] = fwVersionStr; + state.lockInfo['fwVersion'] = fwVersionStr; index = index + 20; - AppLog.log("软件版本 fwVersionStr:$fwVersionStr"); + AppLog.log('软件版本 fwVersionStr:$fwVersionStr'); // 硬件版本 var hwVersion = reply.data.sublist(index, index+20); var hwVersionStr = utf8String(hwVersion); - state.lockInfo["hwVersion"] = hwVersionStr; + state.lockInfo['hwVersion'] = hwVersionStr; index = index + 20; - AppLog.log("硬件版本 hwVersionStr:$hwVersionStr"); + AppLog.log('硬件版本 hwVersionStr:$hwVersionStr'); // 厂商序列号 var serialNum0 = reply.data.sublist(index, index + 16); var serialNum0Str = utf8String(serialNum0); - state.lockInfo["serialNum0"] = serialNum0Str; + state.lockInfo['serialNum0'] = serialNum0Str; // state.lockInfo["serialNum0"] = "${DateTime.now().millisecondsSinceEpoch ~/ 10}"; index = index + 16; - AppLog.log("厂商序列号 serialNum0Str:${serialNum0Str.length}"); + AppLog.log('厂商序列号 serialNum0Str:${serialNum0Str.length}'); // 成品商序列号 var serialNum1 = reply.data.sublist(index, index + 16); var serialNum1Str = utf8String(serialNum1); - state.lockInfo["serialNum1"] = serialNum1Str; + state.lockInfo['serialNum1'] = serialNum1Str; index = index + 16; - AppLog.log("成品商序列号 serialNum1Str:$serialNum1Str"); + AppLog.log('成品商序列号 serialNum1Str:$serialNum1Str'); // 蓝牙名称 var btDeviceName = reply.data.sublist(index, index + 16); var btDeviceNameStr = utf8String(btDeviceName); - state.lockInfo["btDeviceName"] = btDeviceNameStr; + state.lockInfo['btDeviceName'] = btDeviceNameStr; index = index + 16; - AppLog.log("蓝牙名称 btDeviceNameStr:$btDeviceNameStr"); + AppLog.log('蓝牙名称 btDeviceNameStr:$btDeviceNameStr'); // 电池剩余电量 var battRemCap = reply.data[index]; - state.lockInfo["electricQuantity"] = battRemCap; + state.lockInfo['electricQuantity'] = battRemCap; index = index + 1; - AppLog.log("电池剩余电量 battRemCap:$battRemCap"); + AppLog.log('电池剩余电量 battRemCap:$battRemCap'); // 备用电池剩余电量 var battRemCapStandby = reply.data[index]; - state.lockInfo["electricQuantityStandby"] = battRemCapStandby; + state.lockInfo['electricQuantityStandby'] = battRemCapStandby; index = index + 1; - AppLog.log("电池剩余电量 battRemCap:$battRemCap"); + AppLog.log('电池剩余电量 battRemCap:$battRemCap'); // 重置次数 var restoreCounter = reply.data.sublist(index, index + 2); - state.lockInfo["restoreCount"] = restoreCounter[0] * 256 + restoreCounter[1]; + state.lockInfo['restoreCount'] = restoreCounter[0] * 256 + restoreCounter[1]; index = index + 2; - AppLog.log("重置次数 restoreCounter:${restoreCounter[0] * 256 + restoreCounter[1]}"); + AppLog.log('重置次数 restoreCounter:${restoreCounter[0] * 256 + restoreCounter[1]}'); // 重置时间 var restoreDate = reply.data.sublist(index, index + 4); @@ -256,16 +256,16 @@ class NearbyLockLogic extends BaseGetXController { (0xff & restoreDate[2]) << 8 | (0xFF & restoreDate[3])); // String restoreDateStr = DateTool().dateToYMDHNSString(restoreDateValue.toString()); - state.lockInfo["restoreDate"] = restoreDateValue * 1000; + state.lockInfo['restoreDate'] = restoreDateValue * 1000; index = index + 4; - AppLog.log("重置时间 restoreDateValue:$restoreDateValue"); + AppLog.log('重置时间 restoreDateValue:$restoreDateValue'); // 主控芯片型号 var icPartNo = reply.data.sublist(index, index + 10); var icPartNoStr = utf8String(icPartNo); - state.lockInfo["icPartNo"] = icPartNoStr; + state.lockInfo['icPartNo'] = icPartNoStr; index = index + 10; - AppLog.log("主控芯片型号 icPartNoStr:$icPartNoStr"); + AppLog.log('主控芯片型号 icPartNoStr:$icPartNoStr'); // 有效时间 var indate = reply.data.sublist(index, index + 4); @@ -274,27 +274,27 @@ class NearbyLockLogic extends BaseGetXController { (0xff & indate[2]) << 8 | (0xFF & indate[3])); // String indateStr = DateTool().dateToYMDHNSString("$indateValue"); - state.lockInfo["indate"] = indateValue * 1000; + state.lockInfo['indate'] = indateValue * 1000; index = index + 4; - AppLog.log("有效时间 indateValue:$indateValue"); + AppLog.log('有效时间 indateValue:$indateValue'); // mac地址 var macAddress = reply.data.sublist(index, index + 20); var macAddressStr = utf8String(macAddress); - state.lockInfo["mac"] = macAddressStr; + state.lockInfo['mac'] = macAddressStr; index = index + 20; - AppLog.log("mac地址 macAddressStr:$macAddressStr"); + AppLog.log('mac地址 macAddressStr:$macAddressStr'); // 锁特征值字符串长度 var featureValueLength = reply.data[index]; index = index + 1; - AppLog.log("锁特征值字符串长度 featureValueLength:$featureValueLength"); + AppLog.log('锁特征值字符串长度 featureValueLength:$featureValueLength'); // 锁特征值说明(本机能支持的功能) // 获取到锁给的字符数组 var featureNetxLength = index + featureValueLength; if (reply.data.length < featureNetxLength) { - showToast("锁数据异常,请重试"); + showToast('锁数据异常,请重试'); return; } var featureValue = reply.data.sublist(index, index + featureValueLength); @@ -303,17 +303,17 @@ class NearbyLockLogic extends BaseGetXController { // List allFeatureValueTwoList = charListChangeIntList(featureValue); // AppLog.log("featureValueLength:$featureValueLength featureValue:$featureValue \n featureValueStr:$featureValueStr"); index = index + featureValueLength; - AppLog.log("锁特征值字符串 featureValueStr:$featureValueStr"); + AppLog.log('锁特征值字符串 featureValueStr:$featureValueStr'); // 使能特征值字符串长度 var featureEnValLength = reply.data[index]; index = index + 1; - AppLog.log("使能特征值字符串长度 featureEnValLength:$featureEnValLength"); + AppLog.log('使能特征值字符串长度 featureEnValLength:$featureEnValLength'); // 使能锁特征值说明(本机启用的功能) var featureEnNextLength = index + featureEnValLength; if (reply.data.length < featureEnNextLength) { - showToast("锁数据异常,请重试"); + showToast('锁数据异常,请重试'); return; } var featureEnVal = reply.data.sublist(index, index + featureEnValLength); @@ -322,21 +322,21 @@ class NearbyLockLogic extends BaseGetXController { // List allFeatureEnValTwoList = charListChangeIntList(featureEnVal); // AppLog.log("featureEnValLength:$featureEnValLength featureEnVal:$featureEnVal \n featureEnValStr:$featureEnValStr"); index = index + featureEnValLength; - AppLog.log("使能锁特征值说明 featureEnValStr:$featureEnValStr"); + AppLog.log('使能锁特征值说明 featureEnValStr:$featureEnValStr'); // 支持的带参数特征值的总条目数 // var featureParaTotal = reply.data[index]; var featureParaTotalList = reply.data.sublist(index); state.featureSettingParams = featureParaTotalList; - AppLog.log("featureParaTotalList:$featureParaTotalList"); + AppLog.log('featureParaTotalList:$featureParaTotalList'); Get.toNamed(Routers.lockAddressGaoDePage, arguments: { - "pwdTimestamp": state.timestampValue * 1000, - "lockInfo": state.lockInfo, - "featureValue": state.featureValue, - "featureSettingValue": state.featureSettingValue, - "featureSettingParams": state.featureSettingParams, + 'pwdTimestamp': state.timestampValue * 1000, + 'lockInfo': state.lockInfo, + 'featureValue': state.featureValue, + 'featureSettingValue': state.featureSettingValue, + 'featureSettingParams': state.featureSettingParams, }); break; @@ -372,7 +372,7 @@ class NearbyLockLogic extends BaseGetXController { // if (state == BluetoothConnectionState.connected) { // dismissEasyLoading(); - AppLog.log("开始获取锁状态"); + AppLog.log('开始获取锁状态'); var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -397,9 +397,9 @@ class NearbyLockLogic extends BaseGetXController { ScanResult device = list[i]; if (((device.advertisementData.serviceUuids.isNotEmpty ? device.advertisementData.serviceUuids[0] - : "") + : '') .toString()[31] != - "1")) { + '1')) { state.devices.add(list[i]); } } @@ -413,17 +413,17 @@ class NearbyLockLogic extends BaseGetXController { // 点击连接设备,升级 ota 固件 void oTAUpgrade(String deviceName) { - showTitleEasyLoading("连接设备中..."); + showTitleEasyLoading('连接设备中...'); this.deviceName = deviceName; BlueManage().blueSendData(deviceName, (BluetoothConnectionState state) async { - AppLog.log("连接设备"); + AppLog.log('连接设备'); if (state == BluetoothConnectionState.connected) { - AppLog.log("连接成功"); + AppLog.log('连接成功'); dismissEasyLoading(); otaUpdate(); } else if (state == BluetoothConnectionState.disconnected) { - AppLog.log("连接失败"); + AppLog.log('连接失败'); dismissEasyLoading(); } }, isAddEquipment: true); diff --git a/lib/network/api_repository.dart b/lib/network/api_repository.dart index 4cea9c43..6e697cb5 100755 --- a/lib/network/api_repository.dart +++ b/lib/network/api_repository.dart @@ -1,7 +1,7 @@ import 'package:get/get.dart'; import 'package:star_lock/blue/entity/lock_user_no_list_entity.dart'; import 'package:star_lock/login/selectCountryRegion/common/countryRegionEntity.dart'; -import 'package:star_lock/main/lockDetail/authorizedAdmin/volumeAuthorizationLock/notice_template_entity.dart'; +import 'package:star_lock/main/lockDetail/authorizedAdmin/authorizedAdmin/notice_template_entity.dart'; import 'package:star_lock/main/lockDetail/doorLockLog/doorLockLog_entity.dart'; import 'package:star_lock/main/lockDetail/electronicKey/electronicKeyList/entity/ElectronicKeyListEntity.dart'; import 'package:star_lock/main/lockDetail/electronicKey/massSendElectronicKey/massSendLockGroupList/lockUserList/lockUserList_entity.dart'; diff --git a/lib/tools/NativeInteractionTool.dart b/lib/tools/NativeInteractionTool.dart index a94cf5e7..f971cfac 100755 --- a/lib/tools/NativeInteractionTool.dart +++ b/lib/tools/NativeInteractionTool.dart @@ -1,34 +1,38 @@ - import 'package:flutter/services.dart'; import '../app_settings/app_settings.dart'; ///原生交互配置 -class NativeInteractionConfig{ +class NativeInteractionConfig { static String methodSendChannel = 'starLockFlutterSend'; static String receiveEventChannel = 'starLockFlutterReceive'; } ///原生交互flutter向原生发送消息 typedef BlockBlueStatus = void Function(String status); -class NativeInteractionTool{ - var sendChannel = MethodChannel(NativeInteractionConfig.methodSendChannel); - var receiveChannel = MethodChannel(NativeInteractionConfig.receiveEventChannel); + +class NativeInteractionTool { + MethodChannel sendChannel = + MethodChannel(NativeInteractionConfig.methodSendChannel); + MethodChannel receiveChannel = + MethodChannel(NativeInteractionConfig.receiveEventChannel); ///加载原生分享 - loadNativeShare({required String shareText}){ - sendChannel.invokeMethod('loadNativeShare', {'shareText':shareText}); + void loadNativeShare({required String shareText}) { + sendChannel.invokeMethod( + 'loadNativeShare', {'shareText': shareText}); } ///获取设备蓝牙状态 - sendGetBlueStatus(){ + void sendGetBlueStatus() { sendChannel.invokeMethod('sendGetBlueStatus'); } ///获取设备蓝牙是否打开 - receiveChannelBlueIsOnEvent(BlockBlueStatus blockBlueStatus){ + void receiveChannelBlueIsOnEvent(BlockBlueStatus blockBlueStatus) { receiveChannel.setMethodCallHandler((MethodCall call) async { - AppLog.log('收到原生发送的信息call.method: ${call.method} call.arguments:${call.arguments}'); + AppLog.log( + '收到原生发送的信息call.method: ${call.method} call.arguments:${call.arguments}'); switch (call.method) { case 'getBlueStatus': // 获取设备蓝牙开启/关闭状态 @@ -42,5 +46,3 @@ class NativeInteractionTool{ }); } } - -