fix: 调整蓝牙开锁时出现重复响应,增加防抖处理。调整动画控制器在初始化之前进行赋值

This commit is contained in:
liyi 2025-09-26 18:49:41 +08:00
parent 8a5de7d442
commit 2e85975c41
3 changed files with 48 additions and 18 deletions

View File

@ -255,8 +255,8 @@ class BlueManage {
scanDevices.clear(); scanDevices.clear();
for (final ScanResult scanResult in results) { for (final ScanResult scanResult in results) {
if (scanResult.advertisementData.serviceUuids.isNotEmpty) { if (scanResult.advertisementData.serviceUuids.isNotEmpty) {
AppLog.log( // AppLog.log(
'扫描到的设备:${scanResult.advertisementData.serviceUuids[0].toString()}====${scanResult.advertisementData.advName}'); // '扫描到的设备:${scanResult.advertisementData.serviceUuids[0].toString()}====${scanResult.advertisementData.advName}');
} else { } else {
continue; continue;
} }
@ -683,6 +683,7 @@ class BlueManage {
try { try {
await bluetoothConnectDevice.connect( await bluetoothConnectDevice.connect(
timeout: 5.seconds, timeout: 5.seconds,
mtu: 512,
); );
break; // If the connection is successful, break the loop break; // If the connection is successful, break the loop
} catch (e) { } catch (e) {
@ -716,6 +717,10 @@ class BlueManage {
_subScribeToCharacteristic(characteristic); _subScribeToCharacteristic(characteristic);
bluetoothConnectionState = BluetoothConnectionState.connected; bluetoothConnectionState = BluetoothConnectionState.connected;
connectStateCallBack(bluetoothConnectionState!); connectStateCallBack(bluetoothConnectionState!);
if (Platform.isAndroid) {
await bluetoothConnectDevice.requestMtu(512);
}
BuglyTool.uploadException( BuglyTool.uploadException(
message: '订阅成功 上传记录当前方法是bluetoothDeviceConnect', message: '订阅成功 上传记录当前方法是bluetoothDeviceConnect',
detail: '发现服务,连接成功,订阅数据 bluetoothDeviceConnect:${bluetoothConnectDevice.toString()} ', detail: '发现服务,连接成功,订阅数据 bluetoothDeviceConnect:${bluetoothConnectDevice.toString()} ',

View File

@ -54,7 +54,6 @@ class LockDetailLogic extends BaseGetXController {
// //
FunctionBlocker functionBlocker = FunctionBlocker(duration: const Duration(seconds: 2)); FunctionBlocker functionBlocker = FunctionBlocker(duration: const Duration(seconds: 2));
// Timer // Timer
Timer? _openDoorReplyDebounceTimer; Timer? _openDoorReplyDebounceTimer;
@ -64,7 +63,7 @@ class LockDetailLogic extends BaseGetXController {
_openDoorReplyDebounceTimer?.cancel(); _openDoorReplyDebounceTimer?.cancel();
// Timer200ms后执行 // Timer200ms后执行
_openDoorReplyDebounceTimer = Timer(const Duration(milliseconds: 300), () { _openDoorReplyDebounceTimer = Timer(const Duration(milliseconds: 1500), () {
_replyOpenLock(reply); _replyOpenLock(reply);
}); });
} }
@ -158,7 +157,7 @@ class LockDetailLogic extends BaseGetXController {
await uploadElectricQuantityRequest(); await uploadElectricQuantityRequest();
resetOpenDoorState(); resetOpenDoorState();
state.animationController!.stop(); state.animationController?.stop();
// //
AppLog.log('开锁成功,开始同步所记录:getLockRecordLastUploadDataTime'); AppLog.log('开锁成功,开始同步所记录:getLockRecordLastUploadDataTime');
@ -355,7 +354,7 @@ class LockDetailLogic extends BaseGetXController {
// //
void openDoorError() { void openDoorError() {
resetOpenDoorState(); resetOpenDoorState();
state.animationController!.stop(); state.animationController?.stop();
blueManageDisconnect(); blueManageDisconnect();
} }
@ -364,7 +363,7 @@ class LockDetailLogic extends BaseGetXController {
state.openLockBtnState.value = 0; state.openLockBtnState.value = 0;
// state.openDoorBtnisUneable.value = true; // state.openDoorBtnisUneable.value = true;
if (state.animationController != null) { if (state.animationController != null) {
state.animationController!.stop(canceled: true); state.animationController?.stop(canceled: true);
} }
cancelBlueConnetctToastTimer(); cancelBlueConnetctToastTimer();
} }

View File

@ -50,15 +50,15 @@ class _LockDetailPageState extends State<LockDetailPage> with TickerProviderStat
@override @override
void initState() { void initState() {
state.animationController = AnimationController(duration: const Duration(seconds: 1), vsync: this); state.animationController = AnimationController(duration: const Duration(seconds: 1), vsync: this);
state.animationController!.repeat(); state.animationController?.repeat();
//StatusListener //StatusListener
state.animationController!.addStatusListener((AnimationStatus status) { state.animationController?.addStatusListener((AnimationStatus status) {
if (status == AnimationStatus.completed) { if (status == AnimationStatus.completed) {
state.animationController!.reset(); state.animationController?.reset();
state.animationController!.forward(); state.animationController?.forward();
} else if (status == AnimationStatus.dismissed) { } else if (status == AnimationStatus.dismissed) {
state.animationController!.reset(); state.animationController?.reset();
state.animationController!.forward(); state.animationController?.forward();
} }
}); });
super.initState(); super.initState();
@ -813,8 +813,19 @@ class _LockDetailPageState extends State<LockDetailPage> with TickerProviderStat
); );
} }
//
Widget xhjBuildRotationTransition({required double width, required double height}) { Widget xhjBuildRotationTransition({required double width, required double height}) {
// animationController null
if (state.animationController == null) {
return Positioned(
child: Image.asset(
'images/icon_circle_dotted.png',
width: width,
height: height,
color: state.isOpenPassageMode.value == 1 ? Colors.red : AppColors.mainColor,
),
);
}
return Positioned( return Positioned(
child: RotationTransition( child: RotationTransition(
// //
@ -832,8 +843,23 @@ class _LockDetailPageState extends State<LockDetailPage> with TickerProviderStat
); );
} }
// //
Widget buildRotationTransition({required double width, required double height}) { Widget buildRotationTransition({required double width, required double height}) {
//
if (state.animationController == null) {
return Positioned(
child: FlavorsImg(
child: Image.asset(
state.isOpenPassageMode.value == 1
? 'images/main/icon_main_normallyOpenMode_circle.png'
: 'images/main/icon_main_openLockBtn_circle.png',
width: width,
height: height,
),
),
);
}
return Positioned( return Positioned(
child: RotationTransition( child: RotationTransition(
// //
@ -1337,7 +1363,7 @@ class _LockDetailPageState extends State<LockDetailPage> with TickerProviderStat
// } // }
state.iSOpenLock.value = true; state.iSOpenLock.value = true;
state.openLockBtnState.value = 1; state.openLockBtnState.value = 1;
state.animationController!.forward(); state.animationController?.forward();
AppLog.log('点击开锁'); AppLog.log('点击开锁');
if (isOpenLockNeedOnline) { if (isOpenLockNeedOnline) {
// //
@ -1366,7 +1392,7 @@ class _LockDetailPageState extends State<LockDetailPage> with TickerProviderStat
} }
state.iSOpenLock.value = false; state.iSOpenLock.value = false;
state.openLockBtnState.value = 1; state.openLockBtnState.value = 1;
state.animationController!.forward(); state.animationController?.forward();
EasyLoading.showToast('正在尝试闭锁……'.tr, duration: 1000.milliseconds); EasyLoading.showToast('正在尝试闭锁……'.tr, duration: 1000.milliseconds);
AppLog.log('长按闭锁'); AppLog.log('长按闭锁');
if (state.isOpenLockNeedOnline.value == 0) { if (state.isOpenLockNeedOnline.value == 0) {
@ -1392,7 +1418,7 @@ class _LockDetailPageState extends State<LockDetailPage> with TickerProviderStat
state.lockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceEvent?.cancel(); state.lockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceEvent?.cancel();
state.LockSetChangeSetRefreshLockDetailWithTypeSubscription?.cancel(); state.LockSetChangeSetRefreshLockDetailWithTypeSubscription?.cancel();
if (state.animationController != null) { if (state.animationController != null) {
state.animationController!.dispose(); state.animationController?.dispose();
state.animationController = null; state.animationController = null;
} }
super.dispose(); super.dispose();