优化了tcp实时更新对UI线程的压力和对用弹窗的重复弹窗的影响。
更换了路径规划的的经纬度的字段名和取操作的名字更换。
This commit is contained in:
@@ -33,6 +33,7 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
DevicesCubit? _devicesCubit;
|
||||
StreamSubscription? _permissionSubscription; // 🔥 权限监听订阅
|
||||
bool _isShowingPermissionDialog = false; // 🔥 防止弹窗重复显示
|
||||
bool? _lastPermissionDialogState; // 🔥 记录上次弹窗状态,检测状态变化
|
||||
bool _isLoadingPermission = true; // 🔥 标记是否正在加载权限状态
|
||||
|
||||
@override
|
||||
@@ -44,10 +45,28 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
// 🔥 监听权限弹窗状态变化 (只订阅一次)
|
||||
if (_permissionSubscription == null) {
|
||||
_permissionSubscription = _cubit.stream.listen((state) {
|
||||
// 🔥 加强防重复逻辑:只在状态真正变化且不在显示弹窗时才显示
|
||||
if (mounted &&
|
||||
// 🔥 关键修复:只有当状态更新类型是弹窗更新时才处理弹窗逻辑
|
||||
// 设备状态更新(500ms)不会触发弹窗显示
|
||||
if (state.updateType != 'permission_dialog') {
|
||||
// 如果是设备状态更新,只重置状态记录,不显示弹窗
|
||||
if (!state.showPermissionRequestDialog) {
|
||||
_lastPermissionDialogState = false;
|
||||
}
|
||||
return; // 跳过设备状态更新
|
||||
}
|
||||
|
||||
// 🔥 只有当状态从 false 变为 true 时才显示弹窗
|
||||
// 使用三个条件确保不会重复显示
|
||||
final wasFalseBefore =
|
||||
_lastPermissionDialogState == null ||
|
||||
_lastPermissionDialogState == false;
|
||||
final shouldShow =
|
||||
state.showPermissionRequestDialog &&
|
||||
!_isShowingPermissionDialog) {
|
||||
!_isShowingPermissionDialog &&
|
||||
wasFalseBefore;
|
||||
|
||||
if (mounted && shouldShow) {
|
||||
_lastPermissionDialogState = true; // 记录当前状态
|
||||
_isShowingPermissionDialog = true;
|
||||
debugPrint('🔔 [权限弹窗] 检测到 showPermissionRequestDialog=true,准备显示弹窗');
|
||||
// 使用微任务确保标志位已设置
|
||||
@@ -55,10 +74,17 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
_showPermissionDialog(state).then((_) {
|
||||
debugPrint('🔔 [权限弹窗] 弹窗已关闭,重置标志位');
|
||||
_isShowingPermissionDialog = false; // 弹窗关闭后重置标志
|
||||
_lastPermissionDialogState = false; // 重置状态记录
|
||||
});
|
||||
});
|
||||
} else if (!state.showPermissionRequestDialog) {
|
||||
// 状态变为 false 时,重置记录
|
||||
_lastPermissionDialogState = false;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 🔥 如果已经订阅,重置状态记录,确保下次能正确检测状态变化
|
||||
_lastPermissionDialogState = _cubit.state.showPermissionRequestDialog;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,7 +370,7 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
// debugPrint('👆 [权限弹窗] 用户点击了拒绝按钮');
|
||||
// debugPrint('👆 [权限弹窗] 用户点击了拒绝按钮');
|
||||
final deviceId =
|
||||
context
|
||||
.read<DevicesCubit>()
|
||||
@@ -355,19 +381,19 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
final remoteCubit = context.read<RemoteControlCubit>();
|
||||
|
||||
// 🔥 添加详细状态日志 - 检查为什么TCP指令发不出去
|
||||
// debugPrint('👆 [权限弹窗] ====================状态检查====================');
|
||||
// debugPrint('👆 [权限弹窗] showPermissionRequestDialog: ${remoteCubit.state.showPermissionRequestDialog}');
|
||||
// debugPrint('👆 [权限弹窗] targetDevice: ${remoteCubit.state.targetDevice}');
|
||||
// debugPrint('👆 [权限弹窗] requestingDeviceId: ${remoteCubit.state.requestingDeviceId}');
|
||||
// debugPrint('👆 [权限弹窗] hasPermission: ${remoteCubit.state.hasPermission}');
|
||||
// debugPrint('👆 [权限弹窗] ==============================================');
|
||||
// debugPrint('👆 [权限弹窗] ====================状态检查====================');
|
||||
// debugPrint('👆 [权限弹窗] showPermissionRequestDialog: ${remoteCubit.state.showPermissionRequestDialog}');
|
||||
// debugPrint('👆 [权限弹窗] targetDevice: ${remoteCubit.state.targetDevice}');
|
||||
// debugPrint('👆 [权限弹窗] requestingDeviceId: ${remoteCubit.state.requestingDeviceId}');
|
||||
// debugPrint('👆 [权限弹窗] hasPermission: ${remoteCubit.state.hasPermission}');
|
||||
// debugPrint('👆 [权限弹窗] ==============================================');
|
||||
|
||||
/* debugPrint(
|
||||
/* debugPrint(
|
||||
'📋 [权限弹窗] targetDevice=${remoteCubit.state.targetDevice}',
|
||||
);*/
|
||||
|
||||
// 🔥 先发送 TCP 响应,等完成后再关闭弹窗
|
||||
// debugPrint('🔑 [权限弹窗] 用户拒绝,调用 confirmPermissionResponse');
|
||||
// debugPrint('🔑 [权限弹窗] 用户拒绝,调用 confirmPermissionResponse');
|
||||
final targetDevice = remoteCubit.state.targetDevice;
|
||||
if (targetDevice != null) {
|
||||
debugPrint(
|
||||
@@ -385,8 +411,18 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
);
|
||||
}
|
||||
|
||||
// 🔥 关闭弹窗(在 TCP 发送完成后)
|
||||
// 🔥 关键修复:先重置弹窗标志位,再关闭弹窗
|
||||
// 避免 Navigator.pop() 后上下文失效导致后续代码不执行
|
||||
context.read<RemoteControlCubit>().resetPermissionCoolDown();
|
||||
context.read<RemoteControlCubit>().emit(
|
||||
context.read<RemoteControlCubit>().state.copyWith(
|
||||
showPermissionRequestDialog: false,
|
||||
),
|
||||
);
|
||||
|
||||
// 🔥 关闭弹窗(在状态重置之后)
|
||||
Navigator.pop(dialogContext);
|
||||
debugPrint('🔔 [权限弹窗] 弹窗已关闭,重置标志位');
|
||||
},
|
||||
child: Text(
|
||||
AppLocalizations.of(
|
||||
@@ -407,7 +443,7 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
final remoteCubit = context.read<RemoteControlCubit>();
|
||||
|
||||
// 🔥 添加详细状态日志 - 检查为什么TCP指令发不出去
|
||||
/* debugPrint(
|
||||
/* debugPrint(
|
||||
'👆 [权限弹窗] ====================状态检查====================',
|
||||
);
|
||||
debugPrint(
|
||||
@@ -434,9 +470,7 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
debugPrint('🔑 [权限弹窗] 用户同意,调用 confirmPermissionResponse');
|
||||
final targetDevice = remoteCubit.state.targetDevice;
|
||||
if (targetDevice != null) {
|
||||
debugPrint(
|
||||
'✅ [权限弹窗] targetDevice 不为空',
|
||||
);
|
||||
debugPrint('✅ [权限弹窗] targetDevice 不为空');
|
||||
await remoteCubit.confirmPermissionResponse(
|
||||
targetDevice.deviceName,
|
||||
'app',
|
||||
@@ -449,8 +483,18 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
);
|
||||
}
|
||||
|
||||
// 🔥 关闭弹窗(在 TCP 发送完成后)
|
||||
// 🔥 关键修复:先重置弹窗标志位,再关闭弹窗
|
||||
// 避免 Navigator.pop() 后上下文失效导致后续代码不执行
|
||||
context.read<RemoteControlCubit>().resetPermissionCoolDown();
|
||||
context.read<RemoteControlCubit>().emit(
|
||||
context.read<RemoteControlCubit>().state.copyWith(
|
||||
showPermissionRequestDialog: false,
|
||||
),
|
||||
);
|
||||
|
||||
// 🔥 关闭弹窗(在状态重置之后)
|
||||
Navigator.pop(dialogContext);
|
||||
debugPrint('🔔 [权限弹窗] 弹窗已关闭,重置标志位');
|
||||
},
|
||||
child: Text(
|
||||
AppLocalizations.of(
|
||||
|
||||
Reference in New Issue
Block a user