feat:优化蓝牙搜索速度
This commit is contained in:
parent
36f872188a
commit
0b9583723e
@ -189,6 +189,8 @@ class BlueManage {
|
||||
FlutterBluePlus.startScan(
|
||||
continuousDivisor: divisor,
|
||||
continuousUpdates: true,
|
||||
// withServiceData:[ServiceDataFilter()],
|
||||
withKeywords: <String>[deviceName],
|
||||
timeout: Duration(seconds: timeout));
|
||||
final Completer<dynamic> completer = Completer<dynamic>();
|
||||
final StreamSubscription<List<ScanResult>> subscription =
|
||||
@ -374,9 +376,7 @@ class BlueManage {
|
||||
connectDeviceName = deviceName;
|
||||
final List<ScanResult> devicesList = scanDevices;
|
||||
|
||||
final bool isExistDevice = scanDevices.any((ScanResult element) =>
|
||||
element.device.platformName == connectDeviceName ||
|
||||
element.advertisementData.advName == connectDeviceName);
|
||||
final bool isExistDevice = isExistScanDevices(connectDeviceName);
|
||||
|
||||
if (isAddEquipment == false && isExistDevice == false) {
|
||||
//取消缓存直接使用,存在配对场景设备信息会更变
|
||||
@ -390,6 +390,15 @@ class BlueManage {
|
||||
}
|
||||
}
|
||||
|
||||
//查找缓存里面是否有设备
|
||||
bool isExistScanDevices(String connectDeviceName){
|
||||
final bool isExistDevice = scanDevices.any((ScanResult element) =>
|
||||
element.device.platformName == connectDeviceName ||
|
||||
element.advertisementData.advName == connectDeviceName);
|
||||
return isExistDevice;
|
||||
}
|
||||
|
||||
|
||||
Future<void> _connectDevice(List<ScanResult> devicesList, String deviceName,
|
||||
ConnectStateCallBack connectStateCallBack,
|
||||
{bool isAddEquipment = false}) async {
|
||||
|
||||
@ -314,7 +314,8 @@ class LockDetailLogic extends BaseGetXController {
|
||||
final List<int> getPrivateKeyList =
|
||||
changeStringListToIntList(privateKey!);
|
||||
|
||||
final List<String>? token = await Storage.getStringList(saveBlueToken);
|
||||
final List<String>? token = await Storage.getStringList(
|
||||
saveBlueToken);
|
||||
final List<int> getTokenList = changeStringListToIntList(token!);
|
||||
|
||||
final List<String>? publicKey =
|
||||
@ -343,13 +344,17 @@ class LockDetailLogic extends BaseGetXController {
|
||||
await ApiRepository.to.getServerDatetimeData();
|
||||
if (entity.errorCode!.codeIsSuccessful) {
|
||||
state.differentialTime = entity.data!.date! ~/ 1000 -
|
||||
DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
DateTime
|
||||
.now()
|
||||
.millisecondsSinceEpoch ~/ 1000;
|
||||
// AppLog.log("entity.data!.date! ~/ 1000:${entity.data!.date! ~/ 1000} DateTime.now().millisecondsSinceEpoch ~/ 1000:${DateTime.now().millisecondsSinceEpoch ~/ 1000} 服务器时间差:${state.differentialTime}");
|
||||
}
|
||||
}
|
||||
|
||||
int getUTCNetTime() {
|
||||
return DateTime.now().millisecondsSinceEpoch ~/ 1000 +
|
||||
return DateTime
|
||||
.now()
|
||||
.millisecondsSinceEpoch ~/ 1000 +
|
||||
state.differentialTime;
|
||||
}
|
||||
|
||||
@ -478,7 +483,8 @@ class LockDetailLogic extends BaseGetXController {
|
||||
state.keyInfos.value.keyStatus == XSConstantMacro.keyStatusDeleted ||
|
||||
state.keyInfos.value.keyStatus == XSConstantMacro.keyStatusReset) {
|
||||
text =
|
||||
"${"你的钥匙".tr}${XSConstantMacro.getKeyStatusStr(state.keyInfos.value.keyStatus!)}";
|
||||
"${"你的钥匙".tr}${XSConstantMacro.getKeyStatusStr(
|
||||
state.keyInfos.value.keyStatus!)}";
|
||||
} else {
|
||||
text = state.isOpenPassageMode.value == 1
|
||||
? '常开模式启动!长按闭锁'.tr
|
||||
@ -510,5 +516,18 @@ class LockDetailLogic extends BaseGetXController {
|
||||
|
||||
await PermissionDialog.request(Permission.location);
|
||||
await PermissionDialog.requestBluetooth();
|
||||
|
||||
final String connectDeviceName = state.keyInfos.value.bluetooth!
|
||||
.bluetoothDeviceName!;
|
||||
if (!BlueManage().isExistScanDevices(connectDeviceName)) {
|
||||
BlueManage().startScanSingle(
|
||||
connectDeviceName, 15, (List<ScanResult> p0) => null);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,8 +53,9 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||
# 1.0.43+2024052001:打包给公司测试
|
||||
# 1.0.44+2024052002:打包给公司测试
|
||||
# 1.0.45+2024052003:打包给公司测试
|
||||
# 1.0.46+2024052004:打包给公司测试
|
||||
|
||||
version: 1.0.45+2024052003
|
||||
version: 1.0.46+2024052004
|
||||
|
||||
environment:
|
||||
sdk: '>=2.12.0 <3.0.0'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user