From 319813b546c76c456ec4c48f7e8ce9339b80ecdc Mon Sep 17 00:00:00 2001 From: anfe <448468458@qq.com> Date: Fri, 10 May 2024 09:54:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E9=A6=96=E6=AC=A1?= =?UTF-8?q?=E5=BC=80=E9=94=81=E4=BC=9A=E5=A4=B1=E8=B4=A5=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- star_lock/lib/blue/blue_manage.dart | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/star_lock/lib/blue/blue_manage.dart b/star_lock/lib/blue/blue_manage.dart index 4d86e8be..f66b5da7 100644 --- a/star_lock/lib/blue/blue_manage.dart +++ b/star_lock/lib/blue/blue_manage.dart @@ -346,7 +346,7 @@ class BlueManage { if (isAddEquipment == false) { //取消缓存直接使用,存在配对场景设备信息会更变 startScan(10, (List scanDevices) { - _connectDevice(devicesList, deviceName, connectStateCallBack, + _connectDevice(scanDevices, deviceName, connectStateCallBack, isAddEquipment: isAddEquipment); }); } else { @@ -364,6 +364,7 @@ class BlueManage { (d.device.platformName == deviceName) || (d.advertisementData.advName == deviceName)); + ScanResult? scanResult;//使用局部变量防止出现缓存 if (knownDeviceIndex >= 0) { // 存在的时候赋值 connectDeviceMacAddress = @@ -380,7 +381,7 @@ class BlueManage { } // AppLog.log("1 connectDeviceId:$connectDeviceMacAddress connectDeviceName:$connectDeviceName"); // stopScan(); - if (connectDeviceMacAddress.isEmpty) { + if (scanResult == null ||connectDeviceMacAddress.isEmpty) { // connectStateCallBack(BluetoothConnectionState.disconnected!); return; } @@ -388,7 +389,7 @@ class BlueManage { // AppLog.log("调用了停止扫描的方法"); await stopScan(); - if ((scanResult!.advertisementData.serviceUuids[0].toString()[31] == "0") && + if ((scanResult.advertisementData.serviceUuids[0].toString()[31] == "0") && isAddEquipment == false) { connectStateCallBack(BluetoothConnectionState.disconnected); EasyLoading.showToast("该锁已被重置".tr, duration: 2000.milliseconds);