From 69de4e0ac6eef356e2316c3199721f6c825a12c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AD=8F=E5=B0=91=E9=98=B3?= <786612630@qq.com> Date: Tue, 2 Jan 2024 18:03:50 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E8=93=9D=E7=89=99=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- star_lock/lib/blue/blue_manage.dart | 71 ++++++------ .../lib/blue/io_protocol/io_openLock.dart | 12 -- .../card/addICCard/addICCard_logic.dart | 3 + .../card/cardList/cardList_logic.dart | 2 +- .../addFingerprint/addFingerprint_logic.dart | 2 +- .../fingerprintList_logic.dart | 2 +- .../automaticBlocking_logic.dart | 5 + .../automaticBlocking_page.dart | 7 +- .../burglarAlarm/burglarAlarm_logic.dart | 7 +- .../configuringWifi_logic.dart | 4 +- .../lcokSet/lockSet/lockSet_logic.dart | 105 +++++++++++------- .../lcokSet/lockSet/lockSet_page.dart | 32 +----- .../lockSoundSet/lockSoundSet_logic.dart | 7 +- .../lcokSet/lockTime/lockTime_logic.dart | 17 ++- .../lcokSet/lockTime/lockTime_page.dart | 3 +- .../normallyOpenMode_logic.dart | 5 + .../openDoorDirection_logic.dart | 5 + .../remoteUnlocking_logic.dart | 8 +- .../resetButton/resetButton_logic.dart | 7 +- .../lockDetail/lockDetail_logic.dart | 100 ++++++++--------- .../lockDetail/lockDetail_page.dart | 14 +-- .../lockDetail/lockDetail_state.dart | 2 +- .../addLock/nearbyLock/nearbyLock_logic.dart | 25 +++-- .../addLock/nearbyLock/nearbyLock_page.dart | 2 +- .../mine/addLock/saveLock/saveLock_logic.dart | 13 ++- .../mine/addLock/saveLock/saveLock_page.dart | 2 +- .../mine/mineSet/mineSet/mineSet_logic.dart | 2 +- star_lock/lib/tools/baseGetXController.dart | 4 + star_lock/lib/tools/titleAppBar.dart | 12 +- star_lock/lib/tools/toast.dart | 6 + 30 files changed, 274 insertions(+), 212 deletions(-) diff --git a/star_lock/lib/blue/blue_manage.dart b/star_lock/lib/blue/blue_manage.dart index 5f703b58..d56a72da 100644 --- a/star_lock/lib/blue/blue_manage.dart +++ b/star_lock/lib/blue/blue_manage.dart @@ -3,9 +3,7 @@ import 'dart:async'; import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; -import 'package:star_lock/blue/sender_manage.dart'; -import '../tools/toast.dart'; import 'io_tool/io_model.dart'; import 'io_tool/io_tool.dart'; import 'io_tool/manager_event_bus.dart'; @@ -19,7 +17,9 @@ class BlueManage{ final List scanDevices = []; // 用来写入的服务id - Uuid serviceId = Uuid.parse('0000FFF0-0000-1000-8000-00805F9B34FB'); + Uuid serviceIdConnect = Uuid.parse("fff0"); + // 用来写入的服务id + Uuid serviceIdWrite = Uuid.parse('0000FFF0-0000-1000-8000-00805F9B34FB'); // 用来订阅的特征id Uuid characteristicIdSubscription = Uuid.parse("fff1"); // 用来写入的特征id @@ -52,8 +52,8 @@ class BlueManage{ BlueManage? get manager => shareManager(); void _initBlue(){ + // print("蓝牙功能初始化了"); _flutterReactiveBle ??= FlutterReactiveBle(); - print("蓝牙功能初始化了"); _initSendStreamSubscription(); } @@ -92,8 +92,19 @@ class BlueManage{ }); } + /// 调用连接 + Future judgeReconnect(String deviceName, ConnectStateCallBack stateCallBack) async { + if(deviceConnectionState != DeviceConnectionState.connected){ + _connect(deviceName, (state){ + stateCallBack(deviceConnectionState!); + }); + }else{ + stateCallBack(deviceConnectionState!); + } + } + /// 连接监听状态 - Future connect(String deviceName, ConnectStateCallBack connectStateCallBack, {bool? isFrist = false ,bool isShowLoading = true}) async { + Future _connect(String deviceName, ConnectStateCallBack connectStateCallBack) async { connectDeviceName = deviceName; // 判断数组列表里面是否有这个设备 final knownDeviceIndex = scanDevices.indexWhere((d) => d.name == deviceName); @@ -107,15 +118,15 @@ class BlueManage{ Completer? completer = Completer(); Timer.periodic(const Duration(milliseconds: 1000), (timer) { ///定时任务 - print("timer index:$index"); - if(index >= 4){ + // print("timer index0:$index"); + if(index >= 5){ // 当超过5秒的时候取消定时任务 弹窗显示连接失败 completer.complete(); timer.cancel(); connectDeviceMacAddress = ""; - deviceConnectionState = DeviceConnectionState.disconnected; - connectStateCallBack(deviceConnectionState!); - Toast.show(msg: "未扫描到要连接的设备,请确保在设备附近,设备未被连接,设备已打开"); + // deviceConnectionState = DeviceConnectionState.disconnected; + // print("timer index1:$index"); + connectStateCallBack(DeviceConnectionState.disconnected); }else{ // 每秒判断数组列表里面是否有这个设备 final knownDeviceIndex = scanDevices.indexWhere((d) => d.name == deviceName); @@ -123,6 +134,7 @@ class BlueManage{ // 存在的时候销毁定时器,赋值 completer.complete(); timer.cancel(); + // print("timer index2:$index"); connectDeviceMacAddress = scanDevices[knownDeviceIndex].id; } else { // 不存在的时候返回-1 然后循环5秒 @@ -133,7 +145,6 @@ class BlueManage{ }); // 等待Completer完成 await completer.future; - // print("111111"); } print("connectDeviceId:$connectDeviceMacAddress connectDeviceName:$connectDeviceName"); @@ -141,21 +152,20 @@ class BlueManage{ return; } - _currentConnectionStream = _flutterReactiveBle!.connectToDevice(id: connectDeviceMacAddress, connectionTimeout: const Duration(milliseconds: 10000)).listen((connectionStateUpdate) async { + _currentConnectionStream = _flutterReactiveBle!.connectToDevice(id: connectDeviceMacAddress, connectionTimeout: const Duration(seconds: 10)).listen((connectionStateUpdate) async { // 获取状态 deviceConnectionState = connectionStateUpdate.connectionState; print('deviceConnectionState:$deviceConnectionState connectionStateUpdate.connectionState:${connectionStateUpdate.connectionState}'); if(connectionStateUpdate.connectionState == DeviceConnectionState.connected){ // 如果状态是连接的开始发现服务 try { - _subScribeToCharacteristic(QualifiedCharacteristic(characteristicId: characteristicIdSubscription, serviceId: Uuid.parse("fff0"), deviceId: connectDeviceMacAddress)); + _subScribeToCharacteristic(QualifiedCharacteristic(characteristicId: characteristicIdSubscription, serviceId: serviceIdConnect, deviceId: connectDeviceMacAddress)); print('Discovering services finished'); - if(isFrist == true){ - // 第一次添加锁的时候需要先获取公钥 - IoSenderManage.getPublicKey(lockId: deviceName); - } - // print("333333:$deviceConnectionState"); + // if(isFrist == true){ + // // 第一次添加锁的时候需要先获取公钥 + // IoSenderManage.getPublicKey(lockId: deviceName); + // } deviceConnectionState = connectionStateUpdate.connectionState; connectStateCallBack(deviceConnectionState!); } on Exception catch (e) { @@ -177,17 +187,6 @@ class BlueManage{ ); } - // 重新连接 - Future judgeReconnect(String deviceName, ConnectStateCallBack stateCallBack, {bool isShowLoading = true}) async { - if(deviceConnectionState != DeviceConnectionState.connected){ - connect(deviceName, (state){ - stateCallBack(deviceConnectionState!); - }, isShowLoading: false); - }else{ - stateCallBack(deviceConnectionState!); - } - } - // 听上报来的数据,参数来自前面扫描到的结果 var allData = []; _subScribeToCharacteristic(QualifiedCharacteristic characteristic) { @@ -231,8 +230,7 @@ class BlueManage{ // 写入 Future writeCharacteristicWithResponse(List value) async { - QualifiedCharacteristic characteristic = QualifiedCharacteristic(characteristicId: characteristicIdWrite, serviceId: serviceId, deviceId: connectDeviceMacAddress); - // print('Write with characteristicId:${characteristic.characteristicId} serviceId:${characteristic.serviceId} deviceId:${characteristic.deviceId} value : $value \nhexStr:${radixHex16String(value)}'); + QualifiedCharacteristic characteristic = QualifiedCharacteristic(characteristicId: characteristicIdWrite, serviceId: serviceIdWrite, deviceId: connectDeviceMacAddress); int mtuLength = await _flutterReactiveBle!.requestMtu(deviceId: characteristic.deviceId, mtu: 250); print("mtuLength:$mtuLength"); try { @@ -257,7 +255,7 @@ class BlueManage{ } // 读取 - Future> readCharacteristic(QualifiedCharacteristic characteristic) async { + Future> _readCharacteristic(QualifiedCharacteristic characteristic) async { try { final result = await _flutterReactiveBle!.readCharacteristic(characteristic); print("readListresult$result"); @@ -281,10 +279,10 @@ class BlueManage{ } // 停止扫描蓝牙设备 - Future stopScan() async { - await _scanSubscription?.cancel(); - _scanSubscription = null; - } + // Future stopScan() async { + // await _scanSubscription?.cancel(); + // _scanSubscription = null; + // } // 断开连接 Future disconnect(String deviceMAC) async { @@ -295,7 +293,6 @@ class BlueManage{ print("Error disconnecting from a device: $e"); } finally { deviceConnectionState = DeviceConnectionState.disconnected; - // _currentConnectionStream = null; } } diff --git a/star_lock/lib/blue/io_protocol/io_openLock.dart b/star_lock/lib/blue/io_protocol/io_openLock.dart index 1cecd9b3..27b53e75 100644 --- a/star_lock/lib/blue/io_protocol/io_openLock.dart +++ b/star_lock/lib/blue/io_protocol/io_openLock.dart @@ -59,18 +59,6 @@ class OpenLockCommand extends SenderProtocol { // OpenTime 4 int? d1 = openTime; - // var testData = []; - // testData.add((d1! & 0xff000000) >> 24); - // testData.add((d1 & 0xff0000) >> 16); - // testData.add((d1 & 0xff00) >> 8); - // testData.add((d1 & 0xff)); - // - // int value = ( - // (0xff & testData[(0)]) << 24 | - // (0xff & testData[1]) << 16 | - // (0xff & testData[2]) << 8 | - // (0xFF & testData[3])); - // print("d1:$d1 testData:$testData value:$value"); data.add((d1! & 0xff000000) >> 24); data.add((d1 & 0xff0000) >> 16); diff --git a/star_lock/lib/main/lockDetail/card/addICCard/addICCard_logic.dart b/star_lock/lib/main/lockDetail/card/addICCard/addICCard_logic.dart index 58b1a049..b5bc966e 100644 --- a/star_lock/lib/main/lockDetail/card/addICCard/addICCard_logic.dart +++ b/star_lock/lib/main/lockDetail/card/addICCard/addICCard_logic.dart @@ -240,6 +240,9 @@ class AddICCardLogic extends BaseGetXController{ privateKey:getPrivateKeyList, token: getTokenList, ); + } else if (deviceConnectionState == DeviceConnectionState.disconnected){ + Toast.show(msg: "连接设备失败,请确保在设备附近,设备未被连接,设备已打开"); + Get.close(2); } }); } diff --git a/star_lock/lib/main/lockDetail/card/cardList/cardList_logic.dart b/star_lock/lib/main/lockDetail/card/cardList/cardList_logic.dart index 74b4f464..69f4daf0 100644 --- a/star_lock/lib/main/lockDetail/card/cardList/cardList_logic.dart +++ b/star_lock/lib/main/lockDetail/card/cardList/cardList_logic.dart @@ -255,7 +255,7 @@ class CardListLogic extends BaseGetXController { privateKey:getPrivateKeyList, ); } - }, isShowLoading: false); + }); } // 删除卡片 diff --git a/star_lock/lib/main/lockDetail/fingerprint/addFingerprint/addFingerprint_logic.dart b/star_lock/lib/main/lockDetail/fingerprint/addFingerprint/addFingerprint_logic.dart index 429402b1..557e2c35 100644 --- a/star_lock/lib/main/lockDetail/fingerprint/addFingerprint/addFingerprint_logic.dart +++ b/star_lock/lib/main/lockDetail/fingerprint/addFingerprint/addFingerprint_logic.dart @@ -280,7 +280,7 @@ class AddFingerprintLogic extends BaseGetXController { token: getTokenList, ); }else if (deviceConnectionState == DeviceConnectionState.disconnected){ - // Toast.show(msg: "连接设备失败,请确保在设备附近,设备未被连接,设备已打开"); + Toast.show(msg: "连接设备失败,请确保在设备附近,设备未被连接,设备已打开"); Get.close(2); } }); diff --git a/star_lock/lib/main/lockDetail/fingerprint/fingerprintList/fingerprintList_logic.dart b/star_lock/lib/main/lockDetail/fingerprint/fingerprintList/fingerprintList_logic.dart index 4da53fef..ce4126b9 100644 --- a/star_lock/lib/main/lockDetail/fingerprint/fingerprintList/fingerprintList_logic.dart +++ b/star_lock/lib/main/lockDetail/fingerprint/fingerprintList/fingerprintList_logic.dart @@ -288,7 +288,7 @@ class FingerprintListLogic extends BaseGetXController{ privateKey:getPrivateKeyList, ); } - }, isShowLoading: false); + }); } // 删除指纹 diff --git a/star_lock/lib/main/lockDetail/lcokSet/automaticBlocking/automaticBlocking_logic.dart b/star_lock/lib/main/lockDetail/lcokSet/automaticBlocking/automaticBlocking_logic.dart index 6e1070ea..bdc4c68b 100644 --- a/star_lock/lib/main/lockDetail/lcokSet/automaticBlocking/automaticBlocking_logic.dart +++ b/star_lock/lib/main/lockDetail/lcokSet/automaticBlocking/automaticBlocking_logic.dart @@ -154,8 +154,10 @@ class AutomaticBlockingLogic extends BaseGetXController{ // 设置支持功能(带参数) Future sendAutoLock() async { + showEasyLoading(); BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { if (connectionState == DeviceConnectionState.connected) { + dismissEasyLoading(); var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -186,6 +188,9 @@ class AutomaticBlockingLogic extends BaseGetXController{ needAuthor: 1, publicKey: getPublicKeyList, privateKey: getPrivateKeyList); + } else if (connectionState == DeviceConnectionState.disconnected) { + dismissEasyLoading(); + showBlueConnetctToast(); } }); } diff --git a/star_lock/lib/main/lockDetail/lcokSet/automaticBlocking/automaticBlocking_page.dart b/star_lock/lib/main/lockDetail/lcokSet/automaticBlocking/automaticBlocking_page.dart index 985c4bd7..ae33426c 100644 --- a/star_lock/lib/main/lockDetail/lcokSet/automaticBlocking/automaticBlocking_page.dart +++ b/star_lock/lib/main/lockDetail/lcokSet/automaticBlocking/automaticBlocking_page.dart @@ -9,6 +9,7 @@ import '../../../../app_settings/app_colors.dart'; import '../../../../tools/commonItem.dart'; import '../../../../tools/showBottomSheetTool.dart'; import '../../../../tools/titleAppBar.dart'; +import '../../../../tools/toast.dart'; import '../../../../translations/trans_lib.dart'; import 'automaticBlocking_logic.dart'; @@ -40,6 +41,10 @@ class _AutomaticBlockingPageState extends State { if(state.isJustForShow.value == true){ return; } + if(state.isCustomLockTime.value == true && state.timeController.text.isEmpty){ + Toast.show(msg: "请输入自定义时间"); + return; + } logic.sendAutoLock(); }, )), @@ -120,7 +125,7 @@ class _AutomaticBlockingPageState extends State { maxLines: 1, controller: state.timeController, autofocus: false, - readOnly: state.isJustForShow.value == true ? false : true, + readOnly: state.isJustForShow.value == true ? true : false, decoration: InputDecoration( //输入里面输入文字内边距设置 contentPadding: diff --git a/star_lock/lib/main/lockDetail/lcokSet/burglarAlarm/burglarAlarm_logic.dart b/star_lock/lib/main/lockDetail/lcokSet/burglarAlarm/burglarAlarm_logic.dart index 59731b7f..5f24f753 100644 --- a/star_lock/lib/main/lockDetail/lcokSet/burglarAlarm/burglarAlarm_logic.dart +++ b/star_lock/lib/main/lockDetail/lcokSet/burglarAlarm/burglarAlarm_logic.dart @@ -26,7 +26,7 @@ class BurglarAlarmLogic extends BaseGetXController{ antiPrySwitch:state.burglarAlarmEnable.value == 1 ? 0 : 1, // 1-开启、2-关闭; ); if(entity.errorCode!.codeIsSuccessful){ - eventBus.fire(RefreshLockListInfoDataEvent()); + // eventBus.fire(RefreshLockListInfoDataEvent()); state.burglarAlarmEnable.value = state.burglarAlarmEnable.value == 1 ? 0 : 1; state.lockSetInfoData.value.lockSettingInfo!.antiPrySwitch = state.burglarAlarmEnable.value; @@ -138,8 +138,10 @@ class BurglarAlarmLogic extends BaseGetXController{ // 设置支持功能(带参数) Future sendBurglarAlarm() async { + showEasyLoading(); BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { if (connectionState == DeviceConnectionState.connected) { + dismissEasyLoading(); var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -158,6 +160,9 @@ class BurglarAlarmLogic extends BaseGetXController{ needAuthor: 1, publicKey: getPublicKeyList, privateKey: getPrivateKeyList); + } else if (connectionState == DeviceConnectionState.disconnected) { + dismissEasyLoading(); + showBlueConnetctToast(); } }); } diff --git a/star_lock/lib/main/lockDetail/lcokSet/configuringWifi/configuringWifi_logic.dart b/star_lock/lib/main/lockDetail/lcokSet/configuringWifi/configuringWifi_logic.dart index 98395c11..5694d342 100644 --- a/star_lock/lib/main/lockDetail/lcokSet/configuringWifi/configuringWifi_logic.dart +++ b/star_lock/lib/main/lockDetail/lcokSet/configuringWifi/configuringWifi_logic.dart @@ -131,7 +131,9 @@ class ConfiguringWifiLogic extends BaseGetXController{ // 点击配置wifi Future senderConfiguringWifiAction() async { + showEasyLoading(); BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { + dismissEasyLoading(); if (connectionState == DeviceConnectionState.connected){ var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -172,7 +174,7 @@ class ConfiguringWifiLogic extends BaseGetXController{ privateKey: getPrivateKeyList, ); } - }, isShowLoading: true); + }); } final _networkInfo = NetworkInfo(); diff --git a/star_lock/lib/main/lockDetail/lcokSet/lockSet/lockSet_logic.dart b/star_lock/lib/main/lockDetail/lcokSet/lockSet/lockSet_logic.dart index 6659a444..45a26211 100644 --- a/star_lock/lib/main/lockDetail/lcokSet/lockSet/lockSet_logic.dart +++ b/star_lock/lib/main/lockDetail/lcokSet/lockSet/lockSet_logic.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; import 'package:get/get.dart'; import 'package:star_lock/blue/io_protocol/io_deletUser.dart'; @@ -18,6 +19,7 @@ import '../../../../blue/sender_manage.dart'; import '../../../../network/api_repository.dart'; import '../../../../tools/baseGetXController.dart'; import '../../../../tools/eventBusEventManage.dart'; +import '../../../../tools/showTFView.dart'; import '../../../../tools/storage.dart'; import '../../../../tools/toast.dart'; import '../../../../translations/trans_lib.dart'; @@ -251,38 +253,40 @@ class LockSetLogic extends BaseGetXController { // 删除用户 Future deletUserAction() async { BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { - if (connectionState == DeviceConnectionState.connected) { - var privateKey = await Storage.getStringList(saveBluePrivateKey); - List getPrivateKeyList = changeStringListToIntList(privateKey!); + if (connectionState == DeviceConnectionState.connected) { + var privateKey = await Storage.getStringList(saveBluePrivateKey); + List getPrivateKeyList = changeStringListToIntList(privateKey!); - var publicKey = await Storage.getStringList(saveBluePublicKey); - List publicKeyDataList = changeStringListToIntList(publicKey!); + var publicKey = await Storage.getStringList(saveBluePublicKey); + List publicKeyDataList = changeStringListToIntList(publicKey!); - var token = await Storage.getStringList(saveBlueToken); - List getTokenList = changeStringListToIntList(token!); + var token = await Storage.getStringList(saveBlueToken); + List getTokenList = changeStringListToIntList(token!); - IoSenderManage.deletUser( - lockID: BlueManage().connectDeviceName, - authUserID:state.lockBasicInfo.value.senderUserId.toString(), - keyID:state.lockBasicInfo.value.keyId.toString(), - delUserID:await Storage.getUid(), - // authUserID: "100001", - // keyID: "1", - // delUserID: "100001", - needAuthor: 1, - publicKey: publicKeyDataList, - privateKey: getPrivateKeyList, - token: getTokenList); - }else{ - showDeletAlertTipDialog(Get.context!); - } - }); + IoSenderManage.deletUser( + lockID: BlueManage().connectDeviceName, + authUserID:state.lockBasicInfo.value.senderUserId.toString(), + keyID:state.lockBasicInfo.value.keyId.toString(), + delUserID:await Storage.getUid(), + // authUserID: "100001", + // keyID: "1", + // delUserID: "100001", + needAuthor: 1, + publicKey: publicKeyDataList, + privateKey: getPrivateKeyList, + token: getTokenList); + } else if (connectionState == DeviceConnectionState.disconnected) { + showDeletAlertTipDialog(Get.context!); + } + }); } // 恢复出厂设置 Future factoryDataResetAction() async { - BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState state) async { - if (state == DeviceConnectionState.connected){ + showEasyLoading(); + BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { + if (connectionState == DeviceConnectionState.connected){ + dismissEasyLoading(); var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -301,7 +305,8 @@ class LockSetLogic extends BaseGetXController { privateKey:getPrivateKeyList, token: getTokenList ); - }else{ + } else if (connectionState == DeviceConnectionState.disconnected) { + dismissEasyLoading(); showDeletAlertTipDialog(Get.context!); } }); @@ -335,8 +340,10 @@ class LockSetLogic extends BaseGetXController { // 设置支持功能(带参数) Future sendBurglarAlarm(int type) async { + showEasyLoading(); BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { if (connectionState == DeviceConnectionState.connected) { + dismissEasyLoading(); var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -371,6 +378,9 @@ class LockSetLogic extends BaseGetXController { needAuthor: 1, publicKey: getPublicKeyList, privateKey: getPrivateKeyList); + } else if (connectionState == DeviceConnectionState.disconnected) { + dismissEasyLoading(); + showBlueConnetctToast(); } }); } @@ -421,30 +431,45 @@ class LockSetLogic extends BaseGetXController { } } + void showDeletPasswordAlertDialog(BuildContext context) { + showDialog( + context: context, + builder: (BuildContext context) { + return ShowTFView( + title: "请输入登录密码", + tipTitle: "", + controller: state.passwordTF, + sureClick: () { + //发送删除锁请求 + if (state.passwordTF.text.isEmpty) { + Toast.show(msg: "请输入登录密码"); + return; + } + checkLoginPassword(); + }, + cancelClick: () { + Get.back(); + }, + ); + }, + ); + } + // 查询账户密码 - void checkLoginPassword(BlockDeletNumberCheckPasswordCallback blockDeletNumberCheckPasswordCallback) async { + void checkLoginPassword() async { var entity = await ApiRepository.to.checkLoginPassword( password: state.passwordTF.text, ); if (entity.errorCode!.codeIsSuccessful) { - // deletLockInfoData(); + // blockDeletNumberCheckPasswordCallback(); + Get.back(); - blockDeletNumberCheckPasswordCallback(); - // if(state.currentDeviceUUid.value.isEmpty){ - // Toast.show(msg: "未扫描到当前设备,请确保您在设备旁边、设备已开启、设备未被其他人连接"); - // return; - // } // if(state.currentDeviceUUid.value[31] == "1"){ // 判断是否是锁的拥有者 if(state.lockSetInfoData.value.lockBasicInfo!.isLockOwner == 1){ - // 判断是否扫描到当前设备 - if(BlueManage().connectDeviceMacAddress.isNotEmpty){ - // 调用删除锁协议 - factoryDataResetAction(); - }else{ - showDeletAlertTipDialog(Get.context!); - } + // 判断是否扫描到当前设备 调用删除锁协议 + factoryDataResetAction(); }else{ // 判断是否扫描到当前设备 if(BlueManage().connectDeviceMacAddress.isNotEmpty){ diff --git a/star_lock/lib/main/lockDetail/lcokSet/lockSet/lockSet_page.dart b/star_lock/lib/main/lockDetail/lcokSet/lockSet/lockSet_page.dart index 4bd7da7a..8eea1058 100644 --- a/star_lock/lib/main/lockDetail/lcokSet/lockSet/lockSet_page.dart +++ b/star_lock/lib/main/lockDetail/lcokSet/lockSet/lockSet_page.dart @@ -811,8 +811,8 @@ class _LockSetPageState extends State with RouteAware { CupertinoDialogAction( child: Text(TranslationLoader.lanKeys!.sure!.tr), onPressed: () { - Navigator.pop(context); - showDeletPasswordAlertDialog(context); + Get.back(); + logic.showDeletPasswordAlertDialog(context); }, ), ], @@ -844,34 +844,6 @@ class _LockSetPageState extends State with RouteAware { // ); // } - void showDeletPasswordAlertDialog( - BuildContext context, - ) { - showDialog( - context: context, - builder: (BuildContext context) { - return ShowTFView( - title: "请输入登录密码", - tipTitle: "", - controller: state.passwordTF, - sureClick: () { - //发送删除锁请求 - if (state.passwordTF.text.isEmpty) { - Toast.show(msg: "请输入登录密码"); - return; - } - logic.checkLoginPassword(() { - Navigator.pop(context); - }); - }, - cancelClick: () { - Navigator.pop(context); - }, - ); - }, - ); - } - @override void didChangeDependencies() { // TODO: implement didChangeDependencies diff --git a/star_lock/lib/main/lockDetail/lcokSet/lockSoundSet/lockSoundSet_logic.dart b/star_lock/lib/main/lockDetail/lcokSet/lockSoundSet/lockSoundSet_logic.dart index 9b85f499..c9e929ed 100644 --- a/star_lock/lib/main/lockDetail/lcokSet/lockSoundSet/lockSoundSet_logic.dart +++ b/star_lock/lib/main/lockDetail/lcokSet/lockSoundSet/lockSoundSet_logic.dart @@ -29,7 +29,7 @@ class LockSoundSetLogic extends BaseGetXController { ); if(entity.errorCode!.codeIsSuccessful){ - eventBus.fire(RefreshLockListInfoDataEvent()); + // eventBus.fire(RefreshLockListInfoDataEvent()); state.lockSetInfoData.value.lockSettingInfo!.lockSound = state.isOpenLockSound.value == true ? 1 :2; state.lockSetInfoData.value.lockSettingInfo!.lockSoundVolume = state.lockSoundLevel.value; eventBus.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value)); @@ -146,8 +146,10 @@ class LockSoundSetLogic extends BaseGetXController { // 设置支持功能(带参数) Future sendLockSound() async { + showEasyLoading(); BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { if (connectionState == DeviceConnectionState.connected) { + dismissEasyLoading(); var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -175,6 +177,9 @@ class LockSoundSetLogic extends BaseGetXController { needAuthor: 1, publicKey: getPublicKeyList, privateKey: getPrivateKeyList); + } else if (connectionState == DeviceConnectionState.disconnected) { + dismissEasyLoading(); + showBlueConnetctToast(); } }); } diff --git a/star_lock/lib/main/lockDetail/lcokSet/lockTime/lockTime_logic.dart b/star_lock/lib/main/lockDetail/lcokSet/lockTime/lockTime_logic.dart index 9daf89ce..ebf3e6d5 100644 --- a/star_lock/lib/main/lockDetail/lcokSet/lockTime/lockTime_logic.dart +++ b/star_lock/lib/main/lockDetail/lcokSet/lockTime/lockTime_logic.dart @@ -146,8 +146,10 @@ class LockTimeLogic extends BaseGetXController{ // 校验时间 Future sendTiming() async { - BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState state) async { - if (state == DeviceConnectionState.connected) { + showEasyLoading(); + BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { + if (connectionState == DeviceConnectionState.connected) { + dismissEasyLoading(); var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -166,6 +168,9 @@ class LockTimeLogic extends BaseGetXController{ signKey:getSignKeyList, privateKey:getPrivateKeyList, ); + } else if (connectionState == DeviceConnectionState.disconnected) { + dismissEasyLoading(); + showBlueConnetctToast(); } }); } @@ -181,14 +186,16 @@ class LockTimeLogic extends BaseGetXController{ } // 从服务器获取锁的时间 - void getServerDatetime() async{ + void getServerDatetime(bool isSendBlue) async{ var entity = await ApiRepository.to.getServerDatetimeData( lockId: state.lockSetInfoData.value.lockId.toString(), ); if(entity.errorCode!.codeIsSuccessful){ String dataEime = DateTool().dateToYMDHNSString("${entity.data!.date!}"); state.dateTime.value = dataEime; - sendTiming(); + if(isSendBlue){ + sendTiming(); + } } } @@ -200,7 +207,7 @@ class LockTimeLogic extends BaseGetXController{ _initReplySubscription(); // getLockTimeFromGateway(); - getServerDatetime(); + getServerDatetime(false); } @override diff --git a/star_lock/lib/main/lockDetail/lcokSet/lockTime/lockTime_page.dart b/star_lock/lib/main/lockDetail/lcokSet/lockTime/lockTime_page.dart index 7ac7f01b..118eacc6 100644 --- a/star_lock/lib/main/lockDetail/lcokSet/lockTime/lockTime_page.dart +++ b/star_lock/lib/main/lockDetail/lcokSet/lockTime/lockTime_page.dart @@ -53,8 +53,9 @@ class _LockTimePageState extends State { padding: EdgeInsets.only(top: 20.w, bottom: 20.w), onClick: () { // print("1111111"); - logic.sendTiming(); + // logic.sendTiming(); // logic.getServerDatetime(); + logic.getServerDatetime(true); }), SizedBox( height: 40.h, diff --git a/star_lock/lib/main/lockDetail/lcokSet/normallyOpenMode/normallyOpenMode_logic.dart b/star_lock/lib/main/lockDetail/lcokSet/normallyOpenMode/normallyOpenMode_logic.dart index ad41b2eb..ab8dd28b 100644 --- a/star_lock/lib/main/lockDetail/lcokSet/normallyOpenMode/normallyOpenMode_logic.dart +++ b/star_lock/lib/main/lockDetail/lcokSet/normallyOpenMode/normallyOpenMode_logic.dart @@ -165,8 +165,10 @@ class NormallyOpenModeLogic extends BaseGetXController{ // 设置支持功能(带参数) Future sendAutoLock() async { + showEasyLoading(); BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { if (connectionState == DeviceConnectionState.connected) { + dismissEasyLoading(); var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -194,6 +196,9 @@ class NormallyOpenModeLogic extends BaseGetXController{ needAuthor: 1, publicKey: getPublicKeyList, privateKey: getPrivateKeyList); + } else if (connectionState == DeviceConnectionState.disconnected) { + dismissEasyLoading(); + showBlueConnetctToast(); } }); } diff --git a/star_lock/lib/main/lockDetail/lcokSet/openDoorDirection/openDoorDirection_logic.dart b/star_lock/lib/main/lockDetail/lcokSet/openDoorDirection/openDoorDirection_logic.dart index 9472e096..252c8257 100644 --- a/star_lock/lib/main/lockDetail/lcokSet/openDoorDirection/openDoorDirection_logic.dart +++ b/star_lock/lib/main/lockDetail/lcokSet/openDoorDirection/openDoorDirection_logic.dart @@ -139,7 +139,9 @@ class OpenDoorDirectionLogic extends BaseGetXController { // 设置支持功能(带参数) Future sendOpenDoorDirection() async { + showEasyLoading(); BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { + dismissEasyLoading(); if (connectionState == DeviceConnectionState.connected) { var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -159,6 +161,9 @@ class OpenDoorDirectionLogic extends BaseGetXController { needAuthor: 1, publicKey: getPublicKeyList, privateKey: getPrivateKeyList); + }else if (connectionState == DeviceConnectionState.disconnected) { + dismissEasyLoading(); + showBlueConnetctToast(); } }); } diff --git a/star_lock/lib/main/lockDetail/lcokSet/remoteUnlocking/remoteUnlocking_logic.dart b/star_lock/lib/main/lockDetail/lcokSet/remoteUnlocking/remoteUnlocking_logic.dart index 87c7467a..b1be39d0 100644 --- a/star_lock/lib/main/lockDetail/lcokSet/remoteUnlocking/remoteUnlocking_logic.dart +++ b/star_lock/lib/main/lockDetail/lcokSet/remoteUnlocking/remoteUnlocking_logic.dart @@ -133,11 +133,12 @@ class RemoteUnlockingLogic extends BaseGetXController{ privateKey: getPrivateKeyList ); } - }, isShowLoading: true); + }); } - // 设置支持功能(带参数) + // 设置支持功能(带参数) 远程开锁 Future sendBurglarAlarm() async { + showEasyLoading(); BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { if (connectionState == DeviceConnectionState.connected) { var privateKey = await Storage.getStringList(saveBluePrivateKey); @@ -158,6 +159,9 @@ class RemoteUnlockingLogic extends BaseGetXController{ needAuthor: 1, publicKey: getPublicKeyList, privateKey: getPrivateKeyList); + } else if (connectionState == DeviceConnectionState.disconnected) { + dismissEasyLoading(); + showBlueConnetctToast(); } }); } diff --git a/star_lock/lib/main/lockDetail/lcokSet/resetButton/resetButton_logic.dart b/star_lock/lib/main/lockDetail/lcokSet/resetButton/resetButton_logic.dart index 69a2bc14..c1a2809f 100644 --- a/star_lock/lib/main/lockDetail/lcokSet/resetButton/resetButton_logic.dart +++ b/star_lock/lib/main/lockDetail/lcokSet/resetButton/resetButton_logic.dart @@ -28,7 +28,7 @@ class ResetButtonLogic extends BaseGetXController{ resetSwitch:state.resetButtonEnable.value == 1 ? 0 : 1, ); if(entity.errorCode!.codeIsSuccessful){ - eventBus.fire(RefreshLockListInfoDataEvent()); + // eventBus.fire(RefreshLockListInfoDataEvent()); state.resetButtonEnable.value = state.resetButtonEnable.value == 1 ? 2 : 1; state.lockSetInfoData.value.lockSettingInfo!.resetSwitch = state.resetButtonEnable.value; @@ -140,8 +140,10 @@ class ResetButtonLogic extends BaseGetXController{ // 设置支持功能(带参数) Future sendBurglarAlarm() async { + showEasyLoading(); BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { if (connectionState == DeviceConnectionState.connected) { + dismissEasyLoading(); var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -160,6 +162,9 @@ class ResetButtonLogic extends BaseGetXController{ needAuthor: 1, publicKey: getPublicKeyList, privateKey: getPrivateKeyList); + } else if (connectionState == DeviceConnectionState.disconnected) { + dismissEasyLoading(); + showBlueConnetctToast(); } }); } diff --git a/star_lock/lib/main/lockDetail/lockDetail/lockDetail_logic.dart b/star_lock/lib/main/lockDetail/lockDetail/lockDetail_logic.dart index 7bd26bbc..f7e11409 100644 --- a/star_lock/lib/main/lockDetail/lockDetail/lockDetail_logic.dart +++ b/star_lock/lib/main/lockDetail/lockDetail/lockDetail_logic.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'dart:io'; +import 'package:flutter/material.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; import 'package:permission_handler/permission_handler.dart'; @@ -345,12 +346,7 @@ class LockDetailLogic extends BaseGetXController{ // 点击开门事件 Future openDoorAction() async { - // if(BlueManage().connectDeviceMacAddress.isEmpty){ - // Toast.show(msg: "正在连接设备,请稍等。"); - // return; - // } BlueManage().judgeReconnect(state.keyInfos.value.bluetooth!.bluetoothDeviceName!, (DeviceConnectionState deviceConnectionState) async { - print("77777777:$deviceConnectionState"); if (deviceConnectionState == DeviceConnectionState.connected){ var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -368,7 +364,6 @@ class LockDetailLogic extends BaseGetXController{ } print("openDoorTokenPubToken:$getTokenList getPrivateKeyList:$getPrivateKeyList"); - print("millisecondsSinceEpoch/1000:${DateTime.now().millisecondsSinceEpoch~/1000}"); IoSenderManage.senderOpenLock( keyID: BlueManage().connectDeviceName, userID: await Storage.getUid(), @@ -381,13 +376,13 @@ class LockDetailLogic extends BaseGetXController{ privateKey: getPrivateKeyList, ); }else if (deviceConnectionState == DeviceConnectionState.disconnected){ - // Toast.show(msg: "连接设备失败,请确保在设备附近,设备未被连接,设备已打开"); + Toast.show(msg: "连接设备失败,请确保在设备附近,设备未被连接,设备已打开"); state.lockState.value = 4; state.animationController.reset(); state.animationController.forward(); } - }, isShowLoading: false); + }); } // 编辑用户事件 @@ -427,28 +422,28 @@ class LockDetailLogic extends BaseGetXController{ // 备用逻辑,进入管理钥匙界面获取锁状态 - Future connectBlue(String bluetoothDeviceName) async { - // 进来之后首先连接 - BlueManage().connect(bluetoothDeviceName, (DeviceConnectionState state) async { - if(EasyLoading.isShow){ - EasyLoading.dismiss(); - } - if (state == DeviceConnectionState.connected){ - // var privateKey = await Storage.getStringList(saveBluePrivateKey); - // List getPrivateKeyList = changeStringListToIntList(privateKey!); - // // IoSenderManage.senderGetLockStatu( - // // lockID:BlueManage().connectDeviceName, - // // userID:await Storage.getUid(), - // // privateKey:getPrivateKeyList, - // // ); - // IoSenderManage.senderGetStarLockStatuInfo( - // lockID:BlueManage().connectDeviceName, - // userID:await Storage.getUid(), - // privateKey:getPrivateKeyList, - // ); - } - }, isShowLoading: false); - } + // Future _connectBlue(String bluetoothDeviceName) async { + // // 进来之后首先连接 + // BlueManage().connect(bluetoothDeviceName, (DeviceConnectionState state) async { + // if(EasyLoading.isShow){ + // EasyLoading.dismiss(); + // } + // if (state == DeviceConnectionState.connected){ + // // var privateKey = await Storage.getStringList(saveBluePrivateKey); + // // List getPrivateKeyList = changeStringListToIntList(privateKey!); + // // // IoSenderManage.senderGetLockStatu( + // // // lockID:BlueManage().connectDeviceName, + // // // userID:await Storage.getUid(), + // // // privateKey:getPrivateKeyList, + // // // ); + // // IoSenderManage.senderGetStarLockStatuInfo( + // // lockID:BlueManage().connectDeviceName, + // // userID:await Storage.getUid(), + // // privateKey:getPrivateKeyList, + // // ); + // } + // }, isShowLoading: false); + // } // 查询事件记录(时间查询) Future senderReferEventRecordTime(int time) async { @@ -475,7 +470,7 @@ class LockDetailLogic extends BaseGetXController{ privateKey:getPrivateKeyList, ); } - }, isShowLoading: false); + }); } // 添加用户(普通用户接收电子钥匙) @@ -513,12 +508,18 @@ class LockDetailLogic extends BaseGetXController{ token: getTokenList ); } - }, isShowLoading: false); + }); } //开始连接 startConnect() { - state.lockState.value = 1; + if(state.lockState.value == 4){ + // 当状态为4的时候,代表是已经连接过一次了,但是连接失败了,所以要重新连接 + state.lockState.value = 3; + }else{ + // 其他代表是第一次连接 + state.lockState.value = 1; + } state.animationController.forward(); if(state.lockUserNo == 0){ @@ -535,10 +536,6 @@ class LockDetailLogic extends BaseGetXController{ } } - //关闭连接 - stopConnect() { - - } // 获取手机联网token,根据锁设置里面获取的开锁时是否联网来判断是否调用这个接口 void getLockNetToken() async { @@ -581,6 +578,22 @@ class LockDetailLogic extends BaseGetXController{ } } + // connectBlueAndAnimationController(){ + // state.lockState.value = 1; + // state.animationController.forward(); + // BlueManage().judgeReconnect(state.keyInfos.value.bluetooth!.bluetoothDeviceName!, (DeviceConnectionState deviceConnectionState) async { + // if (deviceConnectionState == DeviceConnectionState.connected){ + // state.lockState.value = 2; + // }else if (deviceConnectionState == DeviceConnectionState.disconnected){ + // Toast.show(msg: "连接设备失败,请确保在设备附近,设备未被连接,设备已打开"); + // + // state.lockState.value = 4; + // state.animationController.reset(); + // state.animationController.forward(); + // } + // }); + // } + /// 锁设置里面开启关闭考勤刷新锁详情 StreamSubscription? _lockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceEvent; void initLockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceAction() { @@ -604,31 +617,18 @@ class LockDetailLogic extends BaseGetXController{ super.onReady(); print("onReady()"); - // List model = [5, 3, 2, 16, 100, 176, 0, 244, 249, 83, 101, 223, 74, 100, 40, 228, 96]; - // var modelStr = utf8String(model); - // print("modelStrmodelStrmodelStr:$modelStr"); - _initReplySubscription(); initLockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceAction(); - // EasyLoading.show(status: "正在连接设备,请稍等。", maskType: EasyLoadingMaskType.none, dismissOnTap: true); - // Future.delayed(const Duration(seconds: 12), () { - // if(EasyLoading.isShow){ - // EasyLoading.dismiss(); - // Toast.show(msg: "连接设备失败,请确保在设备附近,设备未被连接,设备已打开"); - // } - // }); } @override void onInit() { // TODO: implement onInit super.onInit(); - // print("lockDetail_onInit()"); // 进来获取锁状态 // connectBlue(); - // factoryDataResetAction(); } @override diff --git a/star_lock/lib/main/lockDetail/lockDetail/lockDetail_page.dart b/star_lock/lib/main/lockDetail/lockDetail/lockDetail_page.dart index fba741a6..6748cc4f 100644 --- a/star_lock/lib/main/lockDetail/lockDetail/lockDetail_page.dart +++ b/star_lock/lib/main/lockDetail/lockDetail/lockDetail_page.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; @@ -124,7 +125,7 @@ class _LockDetailPageState extends State with TickerProviderStat child: Obx(() => Stack( children: [ Image.asset( - (state.lockState.value == 4 || state.lockState.value == 0) ? 'images/main/icon_main_openLockBtn_grey.png' : 'images/main/icon_main_openLockBtn_center.png', + (state.lockState.value == 4 || state.lockState.value == 3) ? 'images/main/icon_main_openLockBtn_grey.png' : 'images/main/icon_main_openLockBtn_center.png', width: 330.w, height: 330.w, ), @@ -372,9 +373,6 @@ class _LockDetailPageState extends State with TickerProviderStat if (state.keyInfos.value.lockFeature!.videoIntercom == 1) { showWidgetArr.add( bottomItem('images/main/icon_catEyes.png', TranslationLoader.lanKeys!.monitoring!.tr, () { - // Navigator.pushNamed(context, Routers.otherTypeKeyListPage, - // arguments: 1); - // Toast.show(msg: "功能暂未开放"); Get.toNamed(Routers.lockMonitoringPage, arguments: { "lockId": widget.lockListInfoItemEntity.lockId }); @@ -443,14 +441,14 @@ class _LockDetailPageState extends State with TickerProviderStat ); } - listeningAnimations() { - Future.delayed(Duration.zero, () { + listeningAnimations() async { + await Future.delayed(Duration.zero, () { state.animationController = AnimationController( duration: const Duration(seconds: 20), vsync: this); state.animationController.repeat(); //动画开始、结束、向前移动或向后移动时会调用StatusListener state.animationController.addStatusListener((status) { - print("AnimationStatus:$status"); + // print("AnimationStatus:$status"); if (status == AnimationStatus.completed) { state.animationController.reset(); state.animationController.forward(); @@ -460,6 +458,8 @@ class _LockDetailPageState extends State with TickerProviderStat } }); }); + + // logic.connectBlueAndAnimationController(); } String showElectricIcon (int electricnumber){ diff --git a/star_lock/lib/main/lockDetail/lockDetail/lockDetail_state.dart b/star_lock/lib/main/lockDetail/lockDetail/lockDetail_state.dart index 878d3fde..cd2c08ff 100644 --- a/star_lock/lib/main/lockDetail/lockDetail/lockDetail_state.dart +++ b/star_lock/lib/main/lockDetail/lockDetail/lockDetail_state.dart @@ -26,5 +26,5 @@ class LockDetailState { //过渡动画控制器 late AnimationController animationController; - var lockState = 0.obs;// 0未连接普通状态 1连接开锁中(展示动画) 2已连接开锁成功 3检测可用性 4连接失败 + var lockState = 0.obs;// 0未连接普通状态 1连接开锁中(展示动画) 2已连接开锁成功 3检测可用性 4连接失败 5连接失败重连中 } \ No newline at end of file diff --git a/star_lock/lib/mine/addLock/nearbyLock/nearbyLock_logic.dart b/star_lock/lib/mine/addLock/nearbyLock/nearbyLock_logic.dart index 355fec18..daaea393 100644 --- a/star_lock/lib/mine/addLock/nearbyLock/nearbyLock_logic.dart +++ b/star_lock/lib/mine/addLock/nearbyLock/nearbyLock_logic.dart @@ -28,16 +28,16 @@ class NearbyLockLogic extends BaseGetXController{ final NearbyLockState state = NearbyLockState(); // 点击连接设备 - void connect(String lockId, String deviceName){ - // BlueManage().stopScan(); - // BlueManage().judgeReconnect(lockId, deviceName, (DeviceConnectionState state) async { - // if (state == DeviceConnectionState.connected) { - // IoSenderManage.getPublicKey(lockId: deviceName); - // } - // }, isShowLoading: true); - BlueManage().connect(deviceName, (state){ - - }, isFrist: true, isShowLoading: true); + void connect(String deviceName){ + showEasyLoading(); + BlueManage().judgeReconnect(deviceName, (DeviceConnectionState state) async { + if (state == DeviceConnectionState.connected) { + IoSenderManage.getPublicKey(lockId: deviceName); + }else if (state == DeviceConnectionState.disconnected) { + dismissEasyLoading(); + showBlueConnetctToast(); + } + }); } // 获取解析后的数据 @@ -317,6 +317,7 @@ class NearbyLockLogic extends BaseGetXController{ // 进来之后首先连接 BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState state) async { if (state == DeviceConnectionState.connected) { + dismissEasyLoading(); var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); // IoSenderManage.senderGetLockStatu( @@ -329,8 +330,10 @@ class NearbyLockLogic extends BaseGetXController{ userID:await Storage.getUid(), privateKey:getPrivateKeyList, ); + } else if (state == DeviceConnectionState.disconnected) { + dismissEasyLoading(); } - }, isShowLoading: false); + }); } late StreamSubscription> _scanListDiscoveredDeviceSubscription; diff --git a/star_lock/lib/mine/addLock/nearbyLock/nearbyLock_page.dart b/star_lock/lib/mine/addLock/nearbyLock/nearbyLock_page.dart index 7d1c05af..2f433572 100644 --- a/star_lock/lib/mine/addLock/nearbyLock/nearbyLock_page.dart +++ b/star_lock/lib/mine/addLock/nearbyLock/nearbyLock_page.dart @@ -55,7 +55,7 @@ class _NearbyLockPageState extends State { // logic.getPublicKey(state.devices[index].serviceUuids[0].toString()); state.seletLockName.value = state.devices[index].name; // print("connect-lockId:${state.devices[index].id} deviceName:${state.devices[index].name}"); - logic.connect(state.devices[index].id, state.devices[index].name); + logic.connect(state.devices[index].name); // Get.toNamed(Routers.lockAddressGaoDePage); }); }, diff --git a/star_lock/lib/mine/addLock/saveLock/saveLock_logic.dart b/star_lock/lib/mine/addLock/saveLock/saveLock_logic.dart index 7233b953..e2741b30 100644 --- a/star_lock/lib/mine/addLock/saveLock/saveLock_logic.dart +++ b/star_lock/lib/mine/addLock/saveLock/saveLock_logic.dart @@ -98,15 +98,17 @@ class SaveLockLogic extends BaseGetXController { } // 保存事件,先调用蓝牙,蓝牙调用成功后再调用后台接口 - saveLockAction(){ - addUserConnectBlue(); - } + // saveLockAction(){ + // addUserConnectBlue(); + // } // 添加用户 Future addUserConnectBlue() async { // 进来之后首先连接 + showEasyLoading(); BlueManage().judgeReconnect(BlueManage().connectDeviceName, (DeviceConnectionState state) async { if (state == DeviceConnectionState.connected){ + dismissEasyLoading(); // 私钥 var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -136,12 +138,15 @@ class SaveLockLogic extends BaseGetXController { privateKey:getPrivateKeyList, token: getTokenList ); + } else if (state == DeviceConnectionState.disconnected) { + dismissEasyLoading(); + showBlueConnetctToast(); } }); } void bindBlueAdmin() async{ - print("state.lockInfo:${state.lockInfo}"); + // print("state.lockInfo:${state.lockInfo}"); var positionMap = {}; positionMap['longitude'] = state.addressInfo["longitude"]; diff --git a/star_lock/lib/mine/addLock/saveLock/saveLock_page.dart b/star_lock/lib/mine/addLock/saveLock/saveLock_page.dart index 0d6aec1f..0f3e8311 100644 --- a/star_lock/lib/mine/addLock/saveLock/saveLock_page.dart +++ b/star_lock/lib/mine/addLock/saveLock/saveLock_page.dart @@ -101,7 +101,7 @@ class _SaveLockPageState extends State { ), onClick: (){ // Navigator.pop(context); - logic.saveLockAction(); + logic.addUserConnectBlue(); } ), ], diff --git a/star_lock/lib/mine/mineSet/mineSet/mineSet_logic.dart b/star_lock/lib/mine/mineSet/mineSet/mineSet_logic.dart index 6b758a3c..1b474dfd 100644 --- a/star_lock/lib/mine/mineSet/mineSet/mineSet_logic.dart +++ b/star_lock/lib/mine/mineSet/mineSet/mineSet_logic.dart @@ -53,7 +53,7 @@ class MineSetLogic extends BaseGetXController { LoginEntity entity = await ApiRepository.to.userLogout(); if (entity.errorCode!.codeIsSuccessful) { logOut(); - BlueManage().stopScan(); + // BlueManage().stopScan(); BlueManage().disconnect(BlueManage().connectDeviceMacAddress); Get.offNamedUntil(Routers.starLockLoginPage, (route) => false); } diff --git a/star_lock/lib/tools/baseGetXController.dart b/star_lock/lib/tools/baseGetXController.dart index 96ef0d2f..870fcc25 100644 --- a/star_lock/lib/tools/baseGetXController.dart +++ b/star_lock/lib/tools/baseGetXController.dart @@ -54,6 +54,10 @@ class BaseGetXController extends GetxController{ void dismissEasyLoading() => EasyLoading.dismiss(); + void showBlueConnetctToast() { + showToast("未扫描到要连接的设备,请确保在设备附近,设备未被连接,设备已打开"); + } + void showToast(String status,{Function? something}) { EasyLoading.showToast(status,duration: 2000.milliseconds); if(something != null) { diff --git a/star_lock/lib/tools/titleAppBar.dart b/star_lock/lib/tools/titleAppBar.dart index 71c3615c..587a9c4b 100644 --- a/star_lock/lib/tools/titleAppBar.dart +++ b/star_lock/lib/tools/titleAppBar.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; class TitleAppBar extends AppBar { @@ -45,7 +46,16 @@ class _TitleAppBarState extends State { ? IconButton( icon: Icon(Icons.arrow_back_ios, color: widget.iconColor ?? Colors.white), - onPressed: () => widget.backAction ?? Navigator.of(context).pop(), + onPressed: () { + if (widget.backAction != null) { + widget.backAction!(); + } else { + if(EasyLoading.isShow){ + EasyLoading.dismiss(); + } + Navigator.pop(context); + } + } ) : Container()), backgroundColor: widget.backgroundColor ?? Colors.white, diff --git a/star_lock/lib/tools/toast.dart b/star_lock/lib/tools/toast.dart index ee7bebb4..02047cf4 100644 --- a/star_lock/lib/tools/toast.dart +++ b/star_lock/lib/tools/toast.dart @@ -22,6 +22,12 @@ class Toast{ ); } + /// 土司提示 + /// 隐藏 + static hidden(){ + ToastPlugins.Fluttertoast.cancel(); + } + /// 显示模态弹窗 /// context: 上下文 /// title:标题