fix: 调整蓝牙开锁时出现重复响应,增加防抖处理。调整动画控制器在初始化之前进行赋值
This commit is contained in:
parent
8a5de7d442
commit
2e85975c41
@ -255,8 +255,8 @@ class BlueManage {
|
||||
scanDevices.clear();
|
||||
for (final ScanResult scanResult in results) {
|
||||
if (scanResult.advertisementData.serviceUuids.isNotEmpty) {
|
||||
AppLog.log(
|
||||
'扫描到的设备:${scanResult.advertisementData.serviceUuids[0].toString()}====${scanResult.advertisementData.advName}');
|
||||
// AppLog.log(
|
||||
// '扫描到的设备:${scanResult.advertisementData.serviceUuids[0].toString()}====${scanResult.advertisementData.advName}');
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
@ -683,6 +683,7 @@ class BlueManage {
|
||||
try {
|
||||
await bluetoothConnectDevice.connect(
|
||||
timeout: 5.seconds,
|
||||
mtu: 512,
|
||||
);
|
||||
break; // If the connection is successful, break the loop
|
||||
} catch (e) {
|
||||
@ -716,6 +717,10 @@ class BlueManage {
|
||||
_subScribeToCharacteristic(characteristic);
|
||||
bluetoothConnectionState = BluetoothConnectionState.connected;
|
||||
connectStateCallBack(bluetoothConnectionState!);
|
||||
|
||||
if (Platform.isAndroid) {
|
||||
await bluetoothConnectDevice.requestMtu(512);
|
||||
}
|
||||
BuglyTool.uploadException(
|
||||
message: '订阅成功 上传记录当前方法是:bluetoothDeviceConnect',
|
||||
detail: '发现服务,连接成功,订阅数据 bluetoothDeviceConnect:${bluetoothConnectDevice.toString()} ',
|
||||
|
||||
@ -54,7 +54,6 @@ class LockDetailLogic extends BaseGetXController {
|
||||
//节流器,用来限制开锁按钮的触发频率
|
||||
FunctionBlocker functionBlocker = FunctionBlocker(duration: const Duration(seconds: 2));
|
||||
|
||||
|
||||
// 防抖Timer
|
||||
Timer? _openDoorReplyDebounceTimer;
|
||||
|
||||
@ -64,7 +63,7 @@ class LockDetailLogic extends BaseGetXController {
|
||||
_openDoorReplyDebounceTimer?.cancel();
|
||||
|
||||
// 设置新的Timer,200ms后执行
|
||||
_openDoorReplyDebounceTimer = Timer(const Duration(milliseconds: 300), () {
|
||||
_openDoorReplyDebounceTimer = Timer(const Duration(milliseconds: 1500), () {
|
||||
_replyOpenLock(reply);
|
||||
});
|
||||
}
|
||||
@ -158,7 +157,7 @@ class LockDetailLogic extends BaseGetXController {
|
||||
await uploadElectricQuantityRequest();
|
||||
|
||||
resetOpenDoorState();
|
||||
state.animationController!.stop();
|
||||
state.animationController?.stop();
|
||||
|
||||
//锁数据更新
|
||||
AppLog.log('开锁成功,开始同步所记录:getLockRecordLastUploadDataTime');
|
||||
@ -355,7 +354,7 @@ class LockDetailLogic extends BaseGetXController {
|
||||
//开门指令失败
|
||||
void openDoorError() {
|
||||
resetOpenDoorState();
|
||||
state.animationController!.stop();
|
||||
state.animationController?.stop();
|
||||
blueManageDisconnect();
|
||||
}
|
||||
|
||||
@ -364,7 +363,7 @@ class LockDetailLogic extends BaseGetXController {
|
||||
state.openLockBtnState.value = 0;
|
||||
// state.openDoorBtnisUneable.value = true;
|
||||
if (state.animationController != null) {
|
||||
state.animationController!.stop(canceled: true);
|
||||
state.animationController?.stop(canceled: true);
|
||||
}
|
||||
cancelBlueConnetctToastTimer();
|
||||
}
|
||||
|
||||
@ -50,15 +50,15 @@ class _LockDetailPageState extends State<LockDetailPage> with TickerProviderStat
|
||||
@override
|
||||
void initState() {
|
||||
state.animationController = AnimationController(duration: const Duration(seconds: 1), vsync: this);
|
||||
state.animationController!.repeat();
|
||||
state.animationController?.repeat();
|
||||
//动画开始、结束、向前移动或向后移动时会调用StatusListener
|
||||
state.animationController!.addStatusListener((AnimationStatus status) {
|
||||
state.animationController?.addStatusListener((AnimationStatus status) {
|
||||
if (status == AnimationStatus.completed) {
|
||||
state.animationController!.reset();
|
||||
state.animationController!.forward();
|
||||
state.animationController?.reset();
|
||||
state.animationController?.forward();
|
||||
} else if (status == AnimationStatus.dismissed) {
|
||||
state.animationController!.reset();
|
||||
state.animationController!.forward();
|
||||
state.animationController?.reset();
|
||||
state.animationController?.forward();
|
||||
}
|
||||
});
|
||||
super.initState();
|
||||
@ -813,8 +813,19 @@ class _LockDetailPageState extends State<LockDetailPage> with TickerProviderStat
|
||||
);
|
||||
}
|
||||
|
||||
//旋转动画
|
||||
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(
|
||||
child: RotationTransition(
|
||||
//设置动画的旋转中心
|
||||
@ -832,8 +843,23 @@ class _LockDetailPageState extends State<LockDetailPage> with TickerProviderStat
|
||||
);
|
||||
}
|
||||
|
||||
//旋转动画
|
||||
//旋转动画
|
||||
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(
|
||||
child: RotationTransition(
|
||||
//设置动画的旋转中心
|
||||
@ -1337,7 +1363,7 @@ class _LockDetailPageState extends State<LockDetailPage> with TickerProviderStat
|
||||
// }
|
||||
state.iSOpenLock.value = true;
|
||||
state.openLockBtnState.value = 1;
|
||||
state.animationController!.forward();
|
||||
state.animationController?.forward();
|
||||
AppLog.log('点击开锁');
|
||||
if (isOpenLockNeedOnline) {
|
||||
// 不需要联网
|
||||
@ -1366,7 +1392,7 @@ class _LockDetailPageState extends State<LockDetailPage> with TickerProviderStat
|
||||
}
|
||||
state.iSOpenLock.value = false;
|
||||
state.openLockBtnState.value = 1;
|
||||
state.animationController!.forward();
|
||||
state.animationController?.forward();
|
||||
EasyLoading.showToast('正在尝试闭锁……'.tr, duration: 1000.milliseconds);
|
||||
AppLog.log('长按闭锁');
|
||||
if (state.isOpenLockNeedOnline.value == 0) {
|
||||
@ -1392,7 +1418,7 @@ class _LockDetailPageState extends State<LockDetailPage> with TickerProviderStat
|
||||
state.lockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceEvent?.cancel();
|
||||
state.LockSetChangeSetRefreshLockDetailWithTypeSubscription?.cancel();
|
||||
if (state.animationController != null) {
|
||||
state.animationController!.dispose();
|
||||
state.animationController?.dispose();
|
||||
state.animationController = null;
|
||||
}
|
||||
super.dispose();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user