From 0ec92eaad042c3dcb2f00fc15d251f58198faa5a Mon Sep 17 00:00:00 2001 From: anfe <448468458@qq.com> Date: Tue, 28 May 2024 14:58:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E4=BC=98=E5=8C=96=E8=93=9D=E7=89=99?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=EF=BC=8Candroid=20=E4=BD=8E=E9=85=8D?= =?UTF-8?q?=E6=89=8B=E6=9C=BA=E6=96=B0=E5=A2=9E=E4=BF=9D=E5=BA=95=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/blue/blue_manage.dart | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/blue/blue_manage.dart b/lib/blue/blue_manage.dart index 0ed3e921..dcbced19 100755 --- a/lib/blue/blue_manage.dart +++ b/lib/blue/blue_manage.dart @@ -71,6 +71,7 @@ class BlueManage { // 保存上一次的数据,用来判断是否收到重复的数据 List lastTimeData = []; int? dataLen; + Timer? scanSingleTimer; static BlueManage? _manager; @@ -322,10 +323,13 @@ class BlueManage { !isExistDevice && isCurrentDevice && mac != null) { + scanSingleTimer?.cancel(); //兼容android 的低配手机 await doNotSearchBLE(mac, connectStateCallBack); - await Future.delayed(3.seconds); - startScanSingle(deviceName, 15, (List scanDevices) => null); + scanSingleTimer = Timer(3.seconds, () { + scanSingleTimer?.cancel(); + startScanSingle(deviceName, 15, (List scanDevices) => null); + }); } else if (isAddEquipment == false && isExistDevice == false) { //取消缓存直接使用,存在配对场景设备信息会更变 startScanSingle(deviceName, 15, (List scanDevices) { @@ -436,7 +440,7 @@ class BlueManage { //直接给蓝牙设备写入 Future doNotSearchBLE( String masAdds, ConnectStateCallBack connectStateCallBack) async { - // FlutterBluePlus.setLogLevel(LogLevel.debug); + await FlutterBluePlus.stopScan(); final BluetoothDevice device = BluetoothDevice.fromId(masAdds); // 重连三次 const int maxAttempts = 3;