From 2c3a744a144f320567e06cad27277244a3bcd2e0 Mon Sep 17 00:00:00 2001 From: anfe <448468458@qq.com> Date: Wed, 22 May 2024 17:19:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=20=E9=94=81=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E4=BF=AE=E6=94=B9=E8=AE=BE=E5=A4=87=E5=90=8E=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=BB=91=E5=8A=A8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lockMian/lockList/lockList_logic.dart | 184 ++++++++++-------- lib/main/lockMian/lockList/lockList_page.dart | 131 ++++++------- .../lockMian/lockList/lockList_xhj_page.dart | 139 ++++++------- .../lockMian/lockMain/lockMain_logic.dart | 18 +- lib/main/lockMian/lockMain/lockMain_page.dart | 2 +- .../addLock/nearbyLock/nearbyLock_logic.dart | 120 ++++++------ 6 files changed, 312 insertions(+), 282 deletions(-) diff --git a/lib/main/lockMian/lockList/lockList_logic.dart b/lib/main/lockMian/lockList/lockList_logic.dart index fff0e86b..49a87d25 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,43 @@ 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 +68,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 +100,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 +166,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 +179,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 +196,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 +273,12 @@ class LockListLogic extends BaseGetXController{ @override void onReady() { - // TODO: implement onReady super.onReady(); - _initReplySubscription(); } - @override - void onInit() { - // TODO: implement onInit - super.onInit(); - } - @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);