完善遥控权限、控制发送和急停反馈

This commit is contained in:
2026-11-21 14:37:46 +08:00
parent c284aefc7d
commit 9a8a42a0a1
55 changed files with 5009 additions and 1308 deletions

View File

@@ -1,5 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
import '../../../remote_control/presentation/bloc/remote_control_cubit.dart';
import '../../../device_control_mode/presentation/widgets/mode_independent_control.dart';
import '../theme/pv_colors.dart';
@@ -48,9 +51,7 @@ class PvControlBar extends StatelessWidget {
onTap: onPauseTask,
),
),
Expanded(
child: PvEmergencyStopButton(onTap: onEmergencyStop),
),
Expanded(child: PvEmergencyStopButton(onTap: onEmergencyStop)),
Expanded(
child: _ControlButton(
icon: Icons.videocam,
@@ -160,9 +161,9 @@ class _PvEmergencyStopButtonState extends State<PvEmergencyStopButton>
with SingleTickerProviderStateMixin {
late final AnimationController _controller;
/// 是否处于「急停中」:默认 false(正常态、不呼吸)。
/// 点击一次进入急停(呼吸 + 「急停中」提示),再点一次解除恢复正常。
bool _active = false;
bool get _active =>
context.read<RemoteControlCubit>().state.isEmergency &&
context.read<RemoteControlCubit>().state.hasEmergencyStatus;
@override
void initState() {
@@ -179,19 +180,30 @@ class _PvEmergencyStopButtonState extends State<PvEmergencyStopButton>
super.dispose();
}
void _handleTap() {
setState(() => _active = !_active);
if (_active) {
@override
void didChangeDependencies() {
super.didChangeDependencies();
final state = context.watch<RemoteControlCubit>().state;
final active = state.isEmergency && state.hasEmergencyStatus;
if (active && !_controller.isAnimating) {
_controller.repeat(reverse: true);
} else {
} else if (!active && _controller.isAnimating) {
_controller.stop();
_controller.value = 0;
}
}
void _handleTap() {
if (context.read<RemoteControlCubit>().state.isEmergencyRequestPending)
return;
widget.onTap();
}
@override
Widget build(BuildContext context) {
Widget build(BuildContext context) =>
ModeIndependentControl(child: _buildButton(context));
Widget _buildButton(BuildContext context) {
return AnimatedBuilder(
animation: _controller,
builder: (context, child) {
@@ -214,7 +226,9 @@ class _PvEmergencyStopButtonState extends State<PvEmergencyStopButton>
),
boxShadow: [
BoxShadow(
color: PvColors.danger.withValues(alpha: 0.5 + 0.35 * t),
color: PvColors.danger.withValues(
alpha: 0.5 + 0.35 * t,
),
blurRadius: 18 + 12 * t,
spreadRadius: 2 + 3 * t,
),
@@ -232,9 +246,11 @@ class _PvEmergencyStopButtonState extends State<PvEmergencyStopButton>
fit: BoxFit.scaleDown,
child: Text(
AppLocalizations.of(context).translate(
_active
? 'pv_control.emergency_stopping'
: 'pv_control.emergency_stop',
!context.read<RemoteControlCubit>().state.hasEmergencyStatus
? 'remote_control.emergency_unknown'
: _active
? 'remote_control.emergency_stopping'
: 'remote_control.emergency_inactive',
),
maxLines: 1,
textAlign: TextAlign.center,