完善遥控权限、控制发送和急停反馈
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -7,12 +7,40 @@ import '../../domain/entities/reverse_camera_data.dart';
|
||||
|
||||
enum RemoteControlStatus { initial, controlling, error }
|
||||
|
||||
/// 本次遥控会话的最后一次用户操作,不代表设备已执行。
|
||||
enum MowerLastOperation { none, turnOn, turnOff }
|
||||
|
||||
enum PermissionRequestPhase {
|
||||
idle,
|
||||
checking,
|
||||
sending,
|
||||
waiting,
|
||||
granted,
|
||||
failed,
|
||||
timedOut,
|
||||
}
|
||||
|
||||
class RemoteControlState extends Equatable {
|
||||
final RemoteControlStatus status;
|
||||
final MachineControlStatusEntity controlEntity; // 控制业务实体
|
||||
final MowerLastOperation lastMowerOperation;
|
||||
final String? errorMessage;
|
||||
final bool hasPermission; // 是否获得 0x12 权限
|
||||
final PermissionRequestPhase permissionRequestPhase;
|
||||
final String permissionFeedbackKey;
|
||||
final int permissionFeedbackId;
|
||||
|
||||
bool get isPermissionRequestBusy =>
|
||||
permissionRequestPhase == PermissionRequestPhase.checking ||
|
||||
permissionRequestPhase == PermissionRequestPhase.sending ||
|
||||
permissionRequestPhase == PermissionRequestPhase.waiting;
|
||||
final bool isEmergency;
|
||||
final bool hasEmergencyStatus;
|
||||
|
||||
/// 本地急停请求状态,不代表已取得设备动作确认。
|
||||
final bool isEmergencyRequestPending;
|
||||
final bool emergencyRequestFailed;
|
||||
final String emergencyFeedbackKey;
|
||||
final bool isLocked;
|
||||
final int ping;
|
||||
final int battery; //电池量
|
||||
@@ -42,9 +70,17 @@ class RemoteControlState extends Equatable {
|
||||
const RemoteControlState({
|
||||
this.status = RemoteControlStatus.initial,
|
||||
required this.controlEntity,
|
||||
this.lastMowerOperation = MowerLastOperation.none,
|
||||
this.errorMessage,
|
||||
this.hasPermission = false,
|
||||
this.permissionRequestPhase = PermissionRequestPhase.idle,
|
||||
this.permissionFeedbackKey = '',
|
||||
this.permissionFeedbackId = 0,
|
||||
this.isEmergency = false,
|
||||
this.hasEmergencyStatus = false,
|
||||
this.isEmergencyRequestPending = false,
|
||||
this.emergencyRequestFailed = false,
|
||||
this.emergencyFeedbackKey = '',
|
||||
this.isLocked = false,
|
||||
this.ping = 0,
|
||||
this.battery = 0,
|
||||
@@ -70,9 +106,17 @@ class RemoteControlState extends Equatable {
|
||||
RemoteControlState copyWith({
|
||||
RemoteControlStatus? status,
|
||||
MachineControlStatusEntity? controlEntity,
|
||||
MowerLastOperation? lastMowerOperation,
|
||||
String? errorMessage,
|
||||
bool? hasPermission,
|
||||
PermissionRequestPhase? permissionRequestPhase,
|
||||
String? permissionFeedbackKey,
|
||||
int? permissionFeedbackId,
|
||||
bool? isEmergency,
|
||||
bool? hasEmergencyStatus,
|
||||
bool? isEmergencyRequestPending,
|
||||
bool? emergencyRequestFailed,
|
||||
String? emergencyFeedbackKey,
|
||||
bool? isLocked,
|
||||
int? ping,
|
||||
int? battery,
|
||||
@@ -90,15 +134,28 @@ class RemoteControlState extends Equatable {
|
||||
bool? topRightIsExpanded,
|
||||
bool? obstacleRecognitionFlag,
|
||||
DeviceEntity? targetDevice,
|
||||
bool clearTargetDevice = false,
|
||||
String? updateType,
|
||||
ReverseCameraData? reverseCamera,
|
||||
}) {
|
||||
return RemoteControlState(
|
||||
status: status ?? this.status,
|
||||
controlEntity: controlEntity ?? this.controlEntity,
|
||||
lastMowerOperation: lastMowerOperation ?? this.lastMowerOperation,
|
||||
errorMessage: errorMessage ?? this.errorMessage,
|
||||
hasPermission: hasPermission ?? this.hasPermission,
|
||||
permissionRequestPhase:
|
||||
permissionRequestPhase ?? this.permissionRequestPhase,
|
||||
permissionFeedbackKey:
|
||||
permissionFeedbackKey ?? this.permissionFeedbackKey,
|
||||
permissionFeedbackId: permissionFeedbackId ?? this.permissionFeedbackId,
|
||||
isEmergency: isEmergency ?? this.isEmergency,
|
||||
hasEmergencyStatus: hasEmergencyStatus ?? this.hasEmergencyStatus,
|
||||
isEmergencyRequestPending:
|
||||
isEmergencyRequestPending ?? this.isEmergencyRequestPending,
|
||||
emergencyRequestFailed:
|
||||
emergencyRequestFailed ?? this.emergencyRequestFailed,
|
||||
emergencyFeedbackKey: emergencyFeedbackKey ?? this.emergencyFeedbackKey,
|
||||
isLocked: isLocked ?? this.isLocked,
|
||||
ping: ping ?? this.ping,
|
||||
battery: battery ?? this.battery,
|
||||
@@ -113,11 +170,14 @@ class RemoteControlState extends Equatable {
|
||||
showRightPip: showRightPip ?? this.showRightPip,
|
||||
runningStatusModel: runningStatusModel ?? this.runningStatusModel,
|
||||
obstacleFlag: obstacleFlag ?? this.obstacleFlag,
|
||||
hasReceivedStatusPush: hasReceivedStatusPush ?? this.hasReceivedStatusPush,
|
||||
hasReceivedStatusPush:
|
||||
hasReceivedStatusPush ?? this.hasReceivedStatusPush,
|
||||
topRightIsExpanded: topRightIsExpanded ?? this.topRightIsExpanded,
|
||||
obstacleRecognitionFlag:
|
||||
obstacleRecognitionFlag ?? this.obstacleRecognitionFlag,
|
||||
targetDevice: targetDevice ?? this.targetDevice,
|
||||
targetDevice: clearTargetDevice
|
||||
? null
|
||||
: targetDevice ?? this.targetDevice,
|
||||
updateType: updateType, // 不使用 ??,因为我们想要 null 的时候就是 null
|
||||
reverseCamera: reverseCamera ?? this.reverseCamera,
|
||||
);
|
||||
@@ -127,9 +187,17 @@ class RemoteControlState extends Equatable {
|
||||
List<Object?> get props => [
|
||||
status,
|
||||
controlEntity,
|
||||
lastMowerOperation,
|
||||
errorMessage,
|
||||
hasPermission,
|
||||
permissionRequestPhase,
|
||||
permissionFeedbackKey,
|
||||
permissionFeedbackId,
|
||||
isEmergency,
|
||||
hasEmergencyStatus,
|
||||
isEmergencyRequestPending,
|
||||
emergencyRequestFailed,
|
||||
emergencyFeedbackKey,
|
||||
isLocked,
|
||||
ping,
|
||||
battery,
|
||||
|
||||
@@ -8,7 +8,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
import 'package:maibu_satabot_v2/core/consts/tcp_consts.dart';
|
||||
import 'package:maibu_satabot_v2/core/env/env_config.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
|
||||
import '../../../../core/app/app_user_cubit.dart';
|
||||
@@ -19,6 +19,7 @@ import '../bloc/remote_control_cubit.dart';
|
||||
import '../bloc/remote_control_state.dart';
|
||||
import '../widgets/center_control_area.dart';
|
||||
import '../widgets/emergency_overlay.dart';
|
||||
import '../widgets/emergency_stop_button.dart';
|
||||
import '../widgets/left_joystick_area.dart';
|
||||
import '../widgets/right_joystick_area.dart';
|
||||
import '../widgets/driving_guide_overlay.dart';
|
||||
@@ -120,33 +121,30 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
// 🔥 离开安全模式:启动 90 秒倒计时
|
||||
GetIt.I<AuthCubit>().exitSafeMode();
|
||||
|
||||
// 释放远程控制权限(type=2:退出远程遥控页面释放)
|
||||
// Schedule the priority zero before ending control; release only after the
|
||||
// rate-limited stop finishes, so release cannot overtake the final stop.
|
||||
final pendingStop = _controlSessionStarted
|
||||
? _cubit.stopAllMovement(reason: 'page_dispose')
|
||||
: Future<void>.value();
|
||||
if (_controlSessionStarted) _cubit.stopControlLoop();
|
||||
final deviceId = _cubit.state.targetDevice?.deviceName;
|
||||
if (_controlSessionStarted && deviceId != null && deviceId.isNotEmpty) {
|
||||
_cubit.releasePermission(deviceId: deviceId, type: 2).then((success) {
|
||||
CapsuleToast.show(
|
||||
success
|
||||
? _l10n.translate('remote_control.toast_released')
|
||||
: _l10n.translate('remote_control.toast_release_failed'),
|
||||
showCheck: success,
|
||||
);
|
||||
});
|
||||
pendingStop
|
||||
.then((_) => _cubit.releasePermission(deviceId: deviceId, type: 2))
|
||||
.then((success) {
|
||||
CapsuleToast.show(
|
||||
success
|
||||
? _l10n.translate('remote_control.toast_released')
|
||||
: _l10n.translate('remote_control.toast_release_failed'),
|
||||
showCheck: success,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
_permissionSubscription?.cancel(); // 🔥 取消订阅
|
||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||
// 🔥 退页先把车真正停下:归零双轴 + 连发 30 帧停止指令。
|
||||
// 只靠 stopControlLoop() 断掉 200ms 循环是不够的:设备只认“最后收到的
|
||||
// 运动帧”,若手指还压在摇杆上就退出(没走松手归零),已下发的高速帧会
|
||||
// 让车继续跑到它自己的失联保护为止。与新版 HUD 折叠/退出的 deactivate()
|
||||
// 同一口径。
|
||||
// 必须放在 stopControlLoop() 之前:stopAllMovement 末尾会按 _controlWanted
|
||||
// 决定是否重启循环,这里同步把意图关掉,就不会在退页后留下无主定时器。
|
||||
if (_controlSessionStarted) {
|
||||
unawaited(_cubit.stopAllMovement());
|
||||
_cubit.stopControlLoop();
|
||||
}
|
||||
// The priority stop above uses the same >=250ms sender as normal movement.
|
||||
_cubit.stopReverseCameraMock(); // 🔥 停止倒车影像 Mock,避免定时器空转
|
||||
// 🔥 重置权限状态,避免单例 hasPermission 残留导致下次进入不再查询接口
|
||||
_cubit.resetPermissionState();
|
||||
@@ -158,6 +156,7 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
deviceId: _modeDeviceId,
|
||||
target: ControlModeTarget.remote,
|
||||
cancelToPreview: true,
|
||||
emergencyStopControl: const EmergencyStopButton(),
|
||||
onReady: () {
|
||||
if (_cubit.state.targetDevice?.deviceName != _modeDeviceId) return;
|
||||
_controlSessionStarted = true;
|
||||
@@ -229,7 +228,7 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
token != null &&
|
||||
token.isNotEmpty) {
|
||||
_videoStreamUrl =
|
||||
"webrtc://${TCPConsts.TCP_IP}/live/livestream/$deviceId?token=$token";
|
||||
"webrtc://${EnvConfig.webRtcStreamAuthority}/live/livestream/$deviceId?token=$token";
|
||||
debugPrint('🎬 [WebRTC] URL构建成功: $_videoStreamUrl');
|
||||
} else {
|
||||
_videoStreamUrl = '';
|
||||
@@ -279,9 +278,11 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
),
|
||||
|
||||
BlocBuilder<RemoteControlCubit, RemoteControlState>(
|
||||
buildWhen: (p, c) => p.isEmergency != c.isEmergency,
|
||||
buildWhen: (p, c) =>
|
||||
p.isEmergency != c.isEmergency ||
|
||||
p.hasEmergencyStatus != c.hasEmergencyStatus,
|
||||
builder: (context, state) {
|
||||
return state.isEmergency
|
||||
return state.isEmergency && state.hasEmergencyStatus
|
||||
? const Positioned.fill(child: EmergencyOverlay())
|
||||
: const SizedBox.shrink();
|
||||
},
|
||||
@@ -300,6 +301,8 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
},
|
||||
buildWhen: (p, c) =>
|
||||
p.hasPermission != c.hasPermission ||
|
||||
p.permissionRequestPhase != c.permissionRequestPhase ||
|
||||
p.permissionFeedbackId != c.permissionFeedbackId ||
|
||||
p.isLocked != c.isLocked ||
|
||||
p.topRightIsExpanded != c.topRightIsExpanded ||
|
||||
p.obstacleRecognitionFlag != c.obstacleRecognitionFlag ||
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import 'package:cc_ui_kit/cc_ui_kit.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'remote_control_link_feedback.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
|
||||
import '../bloc/remote_control_cubit.dart';
|
||||
import '../bloc/remote_control_state.dart';
|
||||
import 'emergency_stop_button.dart';
|
||||
|
||||
class CenterControlArea extends StatelessWidget {
|
||||
@@ -43,7 +45,7 @@ class CenterControlArea extends StatelessWidget {
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
_buildSliderBox(expandedWidth, 'chassis', true,context),
|
||||
_buildSliderBox(expandedWidth, 'chassis', true, context),
|
||||
SizedBox(height: totalWidth * 0.01),
|
||||
],
|
||||
),
|
||||
@@ -60,7 +62,9 @@ class CenterControlArea extends StatelessWidget {
|
||||
SizedBox(height: totalWidth * 0.05),
|
||||
|
||||
Text(
|
||||
AppLocalizations.of(context).translate('remote_control.switch_view_hint'),
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('remote_control.switch_view_hint'),
|
||||
style: const TextStyle(fontSize: 8, color: Colors.grey),
|
||||
),
|
||||
],
|
||||
@@ -73,7 +77,31 @@ class CenterControlArea extends StatelessWidget {
|
||||
width: expandedWidth,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [_buildSliderBox(expandedWidth, 'mower', false,context)],
|
||||
children: [
|
||||
_buildSliderBox(expandedWidth, 'mower', false, context),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('remote_control.mower_last_operation', {
|
||||
'operation': AppLocalizations.of(context).translate(
|
||||
switch (remoteState.lastMowerOperation) {
|
||||
MowerLastOperation.turnOn =>
|
||||
'remote_control.mower_operation_on',
|
||||
MowerLastOperation.turnOff =>
|
||||
'remote_control.mower_operation_off',
|
||||
MowerLastOperation.none =>
|
||||
'remote_control.mower_operation_none',
|
||||
},
|
||||
),
|
||||
}),
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.65),
|
||||
fontSize: 10,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -83,12 +111,17 @@ class CenterControlArea extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSliderBox(double boxWidth, String deviceKey, bool isLeft,BuildContext context) {
|
||||
Widget _buildSliderBox(
|
||||
double boxWidth,
|
||||
String deviceKey,
|
||||
bool isLeft,
|
||||
BuildContext context,
|
||||
) {
|
||||
// 🔥 使用deviceKey作为唯一标识,不依赖显示文本
|
||||
final label = deviceKey == 'chassis'
|
||||
final label = deviceKey == 'chassis'
|
||||
? AppLocalizations.of(context).translate('remote_control.chassis')
|
||||
: AppLocalizations.of(context).translate('remote_control.mower');
|
||||
|
||||
|
||||
return SizedBox(
|
||||
width: boxWidth,
|
||||
child: Center(
|
||||
@@ -98,7 +131,7 @@ class CenterControlArea extends StatelessWidget {
|
||||
child: CCExpandSlider(
|
||||
label: label,
|
||||
svgStart: "assets/svgs/remote_up.svg",
|
||||
svgCenter: deviceKey == 'mower'
|
||||
svgCenter: deviceKey == 'mower'
|
||||
? "assets/svgs/remote_scissors.svg"
|
||||
: "assets/svgs/remote_layers.svg",
|
||||
svgEnd: "assets/svgs/remote_down.svg",
|
||||
@@ -113,7 +146,12 @@ class CenterControlArea extends StatelessWidget {
|
||||
}
|
||||
|
||||
// 🔥 新增:统一的业务逻辑分发方法
|
||||
void _handleSliderAction(String deviceKey, String action, BuildContext context) {
|
||||
void _handleSliderAction(
|
||||
String deviceKey,
|
||||
String action,
|
||||
BuildContext context,
|
||||
) {
|
||||
RemoteControlLinkNotice.showIfDisconnected(context);
|
||||
debugPrint('🎯 [Slider 业务] deviceKey: $deviceKey, action: $action');
|
||||
|
||||
// 🔥 门槛检查:与摇杆一致,未收到 TCP 0x02 推送时禁止操作并提示。
|
||||
@@ -133,7 +171,7 @@ class CenterControlArea extends StatelessWidget {
|
||||
_handleMowerAction(action, context);
|
||||
break;
|
||||
default:
|
||||
debugPrint('⚠️ 未知的 deviceKey: $deviceKey');
|
||||
debugPrint('⚠️ 未知的 deviceKey: $deviceKey');
|
||||
}
|
||||
// 🔥 在指令执行后触发震动反馈(增强手感)
|
||||
HapticFeedback.mediumImpact();
|
||||
@@ -147,40 +185,34 @@ class CenterControlArea extends StatelessWidget {
|
||||
case "start":
|
||||
debugPrint('⬆️ 底盘 - 向上(例如:前进)');
|
||||
// TODO: 发送底盘前进指令
|
||||
cubit.sendChassisCommand(1);
|
||||
cubit.sendChassisCommand(1);
|
||||
break;
|
||||
case "center":
|
||||
debugPrint('️ 底盘 - 中间(例如:停止)');
|
||||
// TODO: 发送底盘停止指令
|
||||
cubit.sendChassisCommand(0);
|
||||
cubit.sendChassisCommand(0);
|
||||
break;
|
||||
case "end":
|
||||
debugPrint('⬇️ 底盘 - 向下(例如:后退)');
|
||||
// TODO: 发送底盘后退指令
|
||||
cubit.sendChassisCommand(2);
|
||||
cubit.sendChassisCommand(2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 🔥 割刀的业务逻辑(右滑块)
|
||||
// 割刀开关(右滑块);段位映射由 Cubit 统一处理。
|
||||
void _handleMowerAction(String action, BuildContext context) {
|
||||
final cubit = context.read<RemoteControlCubit>();
|
||||
|
||||
switch (action) {
|
||||
case "start":
|
||||
debugPrint('⬆️ 割刀 - 向上(例如:抬刀)');
|
||||
// TODO: 发送抬刀指令
|
||||
cubit.sendMowerCommand(1);
|
||||
cubit.sendMowerSliderCommand(1);
|
||||
break;
|
||||
case "center":
|
||||
debugPrint('⏹️ 割刀 - 中间(例如:保持)');
|
||||
// TODO: 发送保持指令
|
||||
cubit.sendMowerCommand(0);
|
||||
cubit.sendMowerSliderCommand(0);
|
||||
break;
|
||||
case "end":
|
||||
debugPrint('⬇️ 割刀 - 向下(例如:降刀)');
|
||||
// TODO: 发送降刀指令
|
||||
cubit.sendMowerCommand(2);
|
||||
cubit.sendMowerSliderCommand(2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,190 +3,141 @@ import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:vibration/vibration.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
|
||||
import '../../../../components/capsule_toast.dart';
|
||||
import '../../../../core/localization/app_localizations.dart';
|
||||
import '../bloc/remote_control_cubit.dart';
|
||||
import 'emergency_stop_confirmation.dart';
|
||||
import '../../../device_control_mode/presentation/widgets/mode_independent_control.dart';
|
||||
|
||||
class EmergencyStopButton extends StatefulWidget {
|
||||
const EmergencyStopButton({super.key, this.width = 120});
|
||||
final double width;
|
||||
const EmergencyStopButton({
|
||||
Key? key,
|
||||
this.width = 120,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<EmergencyStopButton> createState() => _EmergencyStopButtonState();
|
||||
}
|
||||
|
||||
class _EmergencyStopButtonState extends State<EmergencyStopButton>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late AnimationController _progressController;
|
||||
bool _isPressing = false;
|
||||
class _EmergencyStopButtonState extends State<EmergencyStopButton> {
|
||||
bool _isConfirming = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_progressController = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(seconds: 3),
|
||||
);
|
||||
|
||||
// 添加监听器,确保动画值变化时重建 UI
|
||||
_progressController.addListener(() {
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
});
|
||||
Future<void> _confirmAndSubmitEmergency(bool on) async {
|
||||
final cubit = context.read<RemoteControlCubit>();
|
||||
if (_isConfirming || cubit.state.isEmergencyRequestPending) return;
|
||||
if (!cubit.checkEmergencyRequest(on)) {
|
||||
CapsuleToast.show(
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('remote_control.${cubit.state.emergencyFeedbackKey}'),
|
||||
showCheck: false,
|
||||
);
|
||||
return;
|
||||
}
|
||||
final sn = cubit.state.targetDevice?.deviceName;
|
||||
_isConfirming = true;
|
||||
bool confirmed;
|
||||
try {
|
||||
confirmed = await confirmEmergencyStop(context, engage: on, sn: sn ?? '');
|
||||
} finally {
|
||||
_isConfirming = false;
|
||||
}
|
||||
if (!confirmed || !mounted || sn != cubit.state.targetDevice?.deviceName) {
|
||||
return;
|
||||
}
|
||||
await cubit.updateEmergency(on);
|
||||
if (!mounted || sn != cubit.state.targetDevice?.deviceName) return;
|
||||
final key = cubit.state.emergencyFeedbackKey;
|
||||
if (key.isNotEmpty) {
|
||||
CapsuleToast.show(
|
||||
AppLocalizations.of(context).translate('remote_control.$key'),
|
||||
showCheck: false,
|
||||
duration: const Duration(seconds: 3),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_progressController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _resetProgress() {
|
||||
setState(() => _isPressing = false);
|
||||
_progressController.stop();
|
||||
_progressController.value = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isEmergencyActive = context
|
||||
.watch<RemoteControlCubit>()
|
||||
.state
|
||||
.isEmergency;
|
||||
Widget build(BuildContext context) =>
|
||||
ModeIndependentControl(child: _buildButton(context));
|
||||
|
||||
Widget _buildButton(BuildContext context) {
|
||||
final state = context.watch<RemoteControlCubit>().state;
|
||||
final active = state.isEmergency;
|
||||
final pending = state.isEmergencyRequestPending;
|
||||
final width = widget.width * 0.65;
|
||||
final double indicatorSize = width + 20;
|
||||
|
||||
return SizedBox(
|
||||
width: indicatorSize,
|
||||
height: indicatorSize,
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
// 进度环 - 只在按压时显示
|
||||
AnimatedOpacity(
|
||||
opacity: _isPressing ? 1.0 : 0.0,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
child: SizedBox(
|
||||
width: indicatorSize,
|
||||
height: indicatorSize,
|
||||
child: CircularProgressIndicator(
|
||||
value: _progressController.value,
|
||||
strokeWidth: 6,
|
||||
color: Colors.red.withOpacity(0.9),
|
||||
backgroundColor: Colors.red.withValues(alpha: 0.2),
|
||||
),
|
||||
width: width + 20,
|
||||
height: width + 20,
|
||||
child: Center(
|
||||
child: GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: pending
|
||||
? null
|
||||
: () {
|
||||
HapticFeedback.heavyImpact();
|
||||
_vibrate();
|
||||
_confirmAndSubmitEmergency(!active);
|
||||
},
|
||||
child: Container(
|
||||
width: width,
|
||||
height: width,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: active
|
||||
? Colors.red.withValues(alpha: 0.5)
|
||||
: const Color(0x80C53030),
|
||||
boxShadow: active
|
||||
? [
|
||||
BoxShadow(
|
||||
color: Colors.red.withValues(alpha: 0.5),
|
||||
blurRadius: 20,
|
||||
),
|
||||
]
|
||||
: [],
|
||||
),
|
||||
),
|
||||
|
||||
// 按钮主体
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
debugPrint('🔴 [点击] 触发急停');
|
||||
_triggerVibration();
|
||||
if (!isEmergencyActive) {
|
||||
context.read<RemoteControlCubit>().updateEmergency(true);
|
||||
context.read<RemoteControlCubit>().toggleLock();
|
||||
HapticFeedback.heavyImpact();
|
||||
}
|
||||
},
|
||||
onLongPressStart: (_) {
|
||||
debugPrint('🔴 [长按开始] isEmergency=$isEmergencyActive');
|
||||
_triggerVibration();
|
||||
if (isEmergencyActive && !_isPressing) {
|
||||
setState(() => _isPressing = true);
|
||||
debugPrint('🔴 [开始动画] 从 0 开始');
|
||||
_triggerVibration();
|
||||
_progressController.reset();
|
||||
_progressController.forward().then((_) {
|
||||
debugPrint('🔴 [动画完成] _isPressing=$_isPressing');
|
||||
if (_isPressing && mounted) {
|
||||
debugPrint('✅ [解除急停] 执行');
|
||||
_triggerVibration();
|
||||
context.read<RemoteControlCubit>().updateEmergency(false);
|
||||
context.read<RemoteControlCubit>().toggleLock();
|
||||
HapticFeedback.vibrate();
|
||||
setState(() => _isPressing = false);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
onLongPressEnd: (_) {
|
||||
_triggerVibration();
|
||||
debugPrint('🔴 [长按结束]');
|
||||
if (_isPressing) {
|
||||
_resetProgress();
|
||||
|
||||
}
|
||||
},
|
||||
onLongPressCancel: () {
|
||||
_triggerVibration();
|
||||
debugPrint('🔴 [长按取消]');
|
||||
if (_isPressing) {
|
||||
_resetProgress();
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
width: width,
|
||||
height: width,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: isEmergencyActive
|
||||
? Colors.red.withOpacity(0.5)
|
||||
: const Color(0x80C53030),
|
||||
boxShadow: isEmergencyActive
|
||||
? [
|
||||
BoxShadow(
|
||||
color: Colors.red.withValues(alpha: 0.5),
|
||||
blurRadius: 20,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SvgPicture.asset(
|
||||
'assets/svgs/remote_alert.svg',
|
||||
width: width * 0.4,
|
||||
colorFilter: ColorFilter.mode(
|
||||
Colors.white.withValues(alpha: 0.5),
|
||||
BlendMode.srcIn,
|
||||
),
|
||||
]
|
||||
: [],
|
||||
),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SvgPicture.asset(
|
||||
'assets/svgs/remote_alert.svg',
|
||||
width: width * 0.4,
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
AppLocalizations.of(context).translate(
|
||||
pending
|
||||
? 'remote_control.emergency_submitting'
|
||||
: !state.hasEmergencyStatus
|
||||
? 'remote_control.emergency_unknown'
|
||||
: active
|
||||
? 'remote_control.emergency_stopping'
|
||||
: 'remote_control.emergency_inactive',
|
||||
),
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.5),
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w900,
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
isEmergencyActive
|
||||
? AppLocalizations.of(context).translate('remote_control.emergency_stopping')
|
||||
: AppLocalizations.of(context).translate('remote_control.emergency_stop'),
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.5),
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w900,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _triggerVibration() {
|
||||
Vibration.hasVibrator().then((hasVibrator) {
|
||||
if (hasVibrator ?? false) {
|
||||
Vibration.vibrate(duration: 50, amplitude: 380);
|
||||
debugPrint(' 震动执行 - 10ms');
|
||||
} else {
|
||||
debugPrint(' 设备不支持震动');
|
||||
Future<void> _vibrate() async {
|
||||
try {
|
||||
if (await Vibration.hasVibrator()) {
|
||||
await Vibration.vibrate(duration: 50, amplitude: 255);
|
||||
}
|
||||
}).catchError((e) {
|
||||
debugPrint('震动失败:$e');
|
||||
});
|
||||
} catch (_) {
|
||||
// 无震动能力时仍可正常发起急停请求。
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../core/localization/app_localizations.dart';
|
||||
|
||||
/// 只确认用户意图;关闭、返回或取消弹窗均不发送控制请求。
|
||||
Future<bool> confirmEmergencyStop(
|
||||
BuildContext context, {
|
||||
required bool engage,
|
||||
required String sn,
|
||||
}) async {
|
||||
final tr = AppLocalizations.of(context);
|
||||
return await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
title: Text(
|
||||
tr.translate(
|
||||
engage
|
||||
? 'remote_control.emergency_confirm_title'
|
||||
: 'remote_control.emergency_release_title',
|
||||
),
|
||||
),
|
||||
content: Text(
|
||||
tr.translate(
|
||||
engage
|
||||
? 'remote_control.emergency_confirm_message'
|
||||
: 'remote_control.emergency_release_message',
|
||||
{'sn': sn},
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
key: const ValueKey('emergency-cancel'),
|
||||
onPressed: () => Navigator.of(dialogContext).pop(false),
|
||||
child: Text(tr.translate('remote_control.emergency_cancel')),
|
||||
),
|
||||
FilledButton(
|
||||
key: const ValueKey('emergency-confirm'),
|
||||
onPressed: () => Navigator.of(dialogContext).pop(true),
|
||||
child: Text(
|
||||
tr.translate(
|
||||
engage
|
||||
? 'remote_control.emergency_confirm_stop'
|
||||
: 'remote_control.emergency_confirm_release',
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
) ??
|
||||
false;
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
import '../../../../core/logging/remote_control_diagnostics.dart';
|
||||
import 'dart:async';
|
||||
import 'package:cc_ui_kit/cc_ui_kit.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'remote_control_link_feedback.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:vibration/vibration.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
@@ -28,6 +30,10 @@ class _LeftJoystickAreaState extends State<LeftJoystickArea> {
|
||||
|
||||
/// 检查是否可以控制,不能则弹出提示
|
||||
bool _checkCanControl(BuildContext context) {
|
||||
if (!_hasShownNoPushDialog &&
|
||||
RemoteControlLinkNotice.showIfDisconnected(context)) {
|
||||
_hasShownNoPushDialog = true;
|
||||
}
|
||||
// 🔥 临时关闭「未收到推送不能控制」门槛,便于机器未开时用 Mock 假数据联调倒车影像。
|
||||
// 联调完成后取消下面注释即可恢复。切勿删除本段逻辑。
|
||||
// final cubit = context.read<RemoteControlCubit>();
|
||||
@@ -88,6 +94,7 @@ class _LeftJoystickAreaState extends State<LeftJoystickArea> {
|
||||
child: CCJoystick(
|
||||
radius: widget.width,
|
||||
axisHint: AxisHint.forwardBackward,
|
||||
onDiagnostic: (event, fields) => RemoteControlDiagnostics.instance.event('joystick_' + event, fields),
|
||||
onValueChanged: (value) {
|
||||
if (!_checkCanControl(context)) return;
|
||||
// 标记:正在触摸
|
||||
@@ -135,7 +142,7 @@ class _LeftJoystickAreaState extends State<LeftJoystickArea> {
|
||||
debugPrint('✅ 摇杆已停止 -> 强制 X=0, Y=0 停车');
|
||||
|
||||
// 🔥 使用安全方法,一次性清零双轴,确保只发送 (X=0, Y=0)
|
||||
await context.read<RemoteControlCubit>().stopAllMovement();
|
||||
await context.read<RemoteControlCubit>().stopAllMovement(reason: 'forward_release');
|
||||
}
|
||||
|
||||
void _triggerVibration() {
|
||||
@@ -143,4 +150,4 @@ class _LeftJoystickAreaState extends State<LeftJoystickArea> {
|
||||
if (has ?? false) Vibration.vibrate(duration: 12);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../../components/capsule_toast.dart';
|
||||
import '../../../../core/localization/app_localizations.dart';
|
||||
import '../bloc/remote_control_cubit.dart';
|
||||
import '../bloc/remote_control_state.dart';
|
||||
|
||||
/// Shared by both control entry points. Telemetry rebuilds never repeat a toast.
|
||||
class PermissionRequestFeedback extends StatelessWidget {
|
||||
const PermissionRequestFeedback({
|
||||
super.key,
|
||||
required this.cubit,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
final RemoteControlCubit cubit;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) =>
|
||||
BlocListener<RemoteControlCubit, RemoteControlState>(
|
||||
bloc: cubit,
|
||||
listenWhen: (previous, current) =>
|
||||
previous.permissionFeedbackId != current.permissionFeedbackId &&
|
||||
current.permissionFeedbackKey.isNotEmpty,
|
||||
listener: (context, state) => CapsuleToast.show(
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('remote_control.' + state.permissionFeedbackKey),
|
||||
duration: const Duration(seconds: 3),
|
||||
showCheck:
|
||||
state.permissionRequestPhase == PermissionRequestPhase.granted,
|
||||
),
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
|
||||
String permissionStatusText(BuildContext context, RemoteControlState state) {
|
||||
final key = switch (state.permissionRequestPhase) {
|
||||
PermissionRequestPhase.checking => 'permission_checking',
|
||||
PermissionRequestPhase.sending => 'permission_sending',
|
||||
PermissionRequestPhase.waiting => 'permission_waiting',
|
||||
PermissionRequestPhase.timedOut => 'permission_unconfirmed',
|
||||
PermissionRequestPhase.failed when !state.hasPermission =>
|
||||
'permission_request_failed',
|
||||
_ => state.hasPermission ? 'controlling' : 'not_controlling',
|
||||
};
|
||||
return AppLocalizations.of(context).translate('remote_control.' + key);
|
||||
}
|
||||
|
||||
String permissionStatusHint(BuildContext context, RemoteControlState state) =>
|
||||
state.permissionFeedbackKey.isEmpty
|
||||
? permissionStatusText(context, state)
|
||||
: AppLocalizations.of(
|
||||
context,
|
||||
).translate('remote_control.' + state.permissionFeedbackKey);
|
||||
@@ -0,0 +1,106 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
import 'package:maibu_satabot_v2/core/di/injection.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
|
||||
import '../bloc/remote_control_cubit.dart';
|
||||
|
||||
/// 只展示已有连接收到的心跳,不发送数据,也不参与重连或控制门控。
|
||||
class RemoteControlHeartbeatIndicator extends StatefulWidget {
|
||||
const RemoteControlHeartbeatIndicator({
|
||||
super.key,
|
||||
required this.heartbeats,
|
||||
this.size = 10,
|
||||
});
|
||||
|
||||
final Stream<void> heartbeats;
|
||||
final double size;
|
||||
|
||||
@override
|
||||
State<RemoteControlHeartbeatIndicator> createState() =>
|
||||
_RemoteControlHeartbeatIndicatorState();
|
||||
}
|
||||
|
||||
class _RemoteControlHeartbeatIndicatorState
|
||||
extends State<RemoteControlHeartbeatIndicator> {
|
||||
StreamSubscription<void>? _subscription;
|
||||
Timer? _pulseTimer;
|
||||
bool _lit = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_listen();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(RemoteControlHeartbeatIndicator oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.heartbeats != widget.heartbeats) {
|
||||
_subscription?.cancel();
|
||||
_pulseTimer?.cancel();
|
||||
_lit = false;
|
||||
_listen();
|
||||
}
|
||||
}
|
||||
|
||||
void _listen() {
|
||||
_subscription = widget.heartbeats.listen((_) {
|
||||
if (!mounted) return;
|
||||
_pulseTimer?.cancel();
|
||||
setState(() => _lit = true);
|
||||
_pulseTimer = Timer(const Duration(milliseconds: 300), () {
|
||||
if (mounted) setState(() => _lit = false);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_subscription?.cancel();
|
||||
_pulseTimer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Tooltip(
|
||||
message: AppLocalizations.of(
|
||||
context,
|
||||
).translate('remote_control.tcp_heartbeat'),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(6),
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 100),
|
||||
width: widget.size,
|
||||
height: widget.size,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: _lit ? const Color(0xFF36C878) : const Color(0xFF86909C),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 操作时读取现有 TCP 连接状态,仅提示,不拦截、不重连、不改变指令。
|
||||
class RemoteControlLinkNotice {
|
||||
static DateTime? _lastShownAt;
|
||||
|
||||
static bool showIfDisconnected(BuildContext context) {
|
||||
if (sl<RemoteControlCubit>().isControlLinkConnected) return false;
|
||||
final now = DateTime.now();
|
||||
if (_lastShownAt == null ||
|
||||
now.difference(_lastShownAt!) >= const Duration(seconds: 2)) {
|
||||
_lastShownAt = now;
|
||||
CapsuleToast.show(
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('remote_control.tcp_unavailable'),
|
||||
showCheck: false,
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import '../../../../core/logging/remote_control_diagnostics.dart';
|
||||
import 'package:cc_ui_kit/cc_ui_kit.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'remote_control_link_feedback.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:vibration/vibration.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
@@ -27,6 +29,10 @@ class _RightJoystickAreaState extends State<RightJoystickArea> {
|
||||
|
||||
/// 检查是否可以控制,不能则弹出提示
|
||||
bool _checkCanControl(BuildContext context) {
|
||||
if (!_hasShownNoPushDialog &&
|
||||
RemoteControlLinkNotice.showIfDisconnected(context)) {
|
||||
_hasShownNoPushDialog = true;
|
||||
}
|
||||
// 🔥 临时关闭「未收到推送不能控制」门槛,便于机器未开时用 Mock 假数据联调倒车影像。
|
||||
// 联调完成后取消下面注释即可恢复。切勿删除本段逻辑。
|
||||
// final cubit = context.read<RemoteControlCubit>();
|
||||
@@ -87,6 +93,7 @@ class _RightJoystickAreaState extends State<RightJoystickArea> {
|
||||
child: CCJoystick(
|
||||
radius: widget.width,
|
||||
axisHint: AxisHint.leftRight,
|
||||
onDiagnostic: (event, fields) => RemoteControlDiagnostics.instance.event('joystick_' + event, fields),
|
||||
onValueChanged: (value) {
|
||||
if (!_checkCanControl(context)) return;
|
||||
int currentX = value.x.toInt();
|
||||
@@ -107,7 +114,7 @@ class _RightJoystickAreaState extends State<RightJoystickArea> {
|
||||
_lastX = 0;
|
||||
|
||||
// 🔥 使用安全方法,一次性清零双轴,确保只发送 (X=0, Y=0)
|
||||
await context.read<RemoteControlCubit>().stopAllMovement();
|
||||
await context.read<RemoteControlCubit>().stopAllMovement(reason: 'turn_release');
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -128,4 +135,4 @@ class _RightJoystickAreaState extends State<RightJoystickArea> {
|
||||
void _triggerVibration() {
|
||||
Vibration.vibrate(duration: 12);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ import '../../../../core/logging/i_logger_service.dart';
|
||||
import '../../../devices/domain/entities/device_entity.dart';
|
||||
import '../../../devices/presentation/bloc/devices_cubit.dart';
|
||||
import '../../data/models/running_status_model.dart';
|
||||
import 'remote_control_link_feedback.dart';
|
||||
import 'permission_request_feedback.dart';
|
||||
import '../bloc/remote_control_cubit.dart';
|
||||
|
||||
class TopStatusBar extends StatelessWidget {
|
||||
@@ -83,41 +85,37 @@ class TopStatusBar extends StatelessWidget {
|
||||
const SizedBox(width: 8),
|
||||
|
||||
// 2. 控制状态 (对应 StatusChipLeft)
|
||||
StatusChip(
|
||||
text: remoteState.hasPermission
|
||||
? AppLocalizations.of(
|
||||
context,
|
||||
).translate('remote_control.controlling')
|
||||
: AppLocalizations.of(
|
||||
context,
|
||||
).translate('remote_control.not_controlling'),
|
||||
color: remoteState.hasPermission
|
||||
? const Color(0xFF1DB954)
|
||||
: Colors.red,
|
||||
icon: Icons.eighteen_mp,
|
||||
breathing: !remoteState.hasPermission,
|
||||
onTap: () {
|
||||
if (!remoteState.hasPermission) {
|
||||
// 🔥 点击后发起抢占:查权限 + 无权限则发 TCP switch_control
|
||||
debugPrint('🔑 [TopStatusBar] 👆 用户手动点击“未在控制”,请求抢占控制权');
|
||||
final targetDevice =
|
||||
_remoteControlCubit.state.targetDevice;
|
||||
if (targetDevice != null) {
|
||||
PermissionRequestFeedback(
|
||||
cubit: _remoteControlCubit,
|
||||
child: Tooltip(
|
||||
message: permissionStatusHint(context, remoteState),
|
||||
child: StatusChip(
|
||||
text: permissionStatusText(context, remoteState),
|
||||
color: remoteState.isPermissionRequestBusy
|
||||
? Colors.orange
|
||||
: remoteState.hasPermission
|
||||
? const Color(0xFF1DB954)
|
||||
: Colors.red,
|
||||
icon: Icons.eighteen_mp,
|
||||
breathing: !remoteState.hasPermission,
|
||||
onTap: () {
|
||||
if (remoteState.hasPermission || remoteState.isPermissionRequestBusy) return;
|
||||
_remoteControlCubit.requestControlPermissionS(
|
||||
targetDevice.deviceName,
|
||||
_remoteControlCubit.state.targetDevice?.deviceName ?? '',
|
||||
'app',
|
||||
source: '手动点击',
|
||||
grabControl: true,
|
||||
);
|
||||
} else {
|
||||
debugPrint('❌ [TopStatusBar] targetDevice 为空,无法请求权限');
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
|
||||
// 3. 锁定状态 (对应 SmallFunctionButton)
|
||||
RemoteControlHeartbeatIndicator(
|
||||
heartbeats: _remoteControlCubit.serverHeartbeats,
|
||||
),
|
||||
_buildIconButton(
|
||||
remoteState.isLocked
|
||||
? "assets/svgs/remote_lock.svg"
|
||||
@@ -476,6 +474,7 @@ class TopStatusBar extends StatelessWidget {
|
||||
|
||||
// 🔥 新增:统一的业务逻辑分发方法
|
||||
void _handleSliderAction(String label, String action, BuildContext context) {
|
||||
RemoteControlLinkNotice.showIfDisconnected(context);
|
||||
debugPrint('🎯 [Slider 业务] label: $label, action: $action');
|
||||
|
||||
// 🔥 根据 label 区分不同的设备
|
||||
|
||||
Reference in New Issue
Block a user