fix:SKY环境下注释该锁已被重置的弹窗
This commit is contained in:
parent
ea96419e05
commit
d75754e14e
@ -5,6 +5,7 @@ import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:star_lock/app_settings/app_settings.dart';
|
||||
import 'package:star_lock/flavors.dart';
|
||||
import 'package:star_lock/tools/bugly/bugly_tool.dart';
|
||||
import 'package:star_lock/tools/commonDataManage.dart';
|
||||
|
||||
@ -551,7 +552,10 @@ class BlueManage {
|
||||
});
|
||||
} else {
|
||||
connectStateCallBack(BluetoothConnectionState.disconnected);
|
||||
EasyLoading.showToast('该锁已被重置'.tr, duration: 2000.milliseconds);
|
||||
if (!F.isSKY) {
|
||||
EasyLoading.showToast('该锁已被重置'.tr, duration: 2000.milliseconds);
|
||||
}
|
||||
|
||||
scanDevices.clear();
|
||||
|
||||
BuglyTool.uploadException(
|
||||
@ -582,7 +586,9 @@ class BlueManage {
|
||||
});
|
||||
} else {
|
||||
connectStateCallBack(BluetoothConnectionState.disconnected);
|
||||
EasyLoading.showToast('该锁已被重置'.tr, duration: 2000.milliseconds);
|
||||
if (!F.isSKY) {
|
||||
EasyLoading.showToast('该锁已被重置'.tr, duration: 2000.milliseconds);
|
||||
}
|
||||
scanDevices.clear();
|
||||
|
||||
BuglyTool.uploadException(
|
||||
@ -789,34 +795,39 @@ class BlueManage {
|
||||
int retryCount = 0;
|
||||
const int maxRetries = 3;
|
||||
const int retryDelayMs = 500;
|
||||
|
||||
|
||||
final List<int> valueList = value;
|
||||
final List subData = splitList(valueList, _mtuSize!);
|
||||
|
||||
|
||||
for (int i = 0; i < subData.length; i++) {
|
||||
// 对每个数据包都应用重试逻辑
|
||||
bool packetSent = false;
|
||||
retryCount = 0;
|
||||
|
||||
|
||||
while (!packetSent && retryCount < maxRetries) {
|
||||
try {
|
||||
if (characteristic.properties.writeWithoutResponse) {
|
||||
await characteristic.write(subData[i], withoutResponse: true);
|
||||
await characteristic.write(subData[i],
|
||||
withoutResponse: true);
|
||||
} else if (characteristic.properties.write) {
|
||||
await characteristic.write(subData[i]);
|
||||
} else {
|
||||
// 特性不支持写入
|
||||
throw Exception('This characteristic does not support writing.');
|
||||
throw Exception(
|
||||
'This characteristic does not support writing.');
|
||||
}
|
||||
|
||||
|
||||
// 如果到这里没有异常,则包发送成功
|
||||
packetSent = true;
|
||||
} catch (e) {
|
||||
if (e.toString().contains('UNKNOWN_GATT_ERROR (133)') && retryCount < maxRetries - 1) {
|
||||
if (e.toString().contains('UNKNOWN_GATT_ERROR (133)') &&
|
||||
retryCount < maxRetries - 1) {
|
||||
// GATT错误133,尝试重试
|
||||
retryCount++;
|
||||
AppLog.log('蓝牙写入失败(GATT 133),数据包 ${i+1}/${subData.length} 正在重试 $retryCount/$maxRetries...');
|
||||
await Future.delayed(Duration(milliseconds: retryDelayMs));
|
||||
AppLog.log(
|
||||
'蓝牙写入失败(GATT 133),数据包 ${i + 1}/${subData.length} 正在重试 $retryCount/$maxRetries...');
|
||||
await Future.delayed(
|
||||
Duration(milliseconds: retryDelayMs));
|
||||
continue;
|
||||
} else {
|
||||
// 其他错误或已达到最大重试次数,抛出异常
|
||||
@ -825,12 +836,13 @@ class BlueManage {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!packetSent) {
|
||||
throw Exception('蓝牙写入失败,数据包 ${i+1}/${subData.length} 已达到最大重试次数');
|
||||
throw Exception(
|
||||
'蓝牙写入失败,数据包 ${i + 1}/${subData.length} 已达到最大重试次数');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return; // 所有数据包都发送成功
|
||||
} on Exception catch (e, s) {
|
||||
AppLog.log('APP写入失败: $e $s');
|
||||
@ -840,7 +852,7 @@ class BlueManage {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 如果找不到合适的特性用于写入
|
||||
throw Exception('未找到适合写入的蓝牙特性');
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user