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;