255 lines
7.4 KiB
Dart
255 lines
7.4 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||
|
||
import '../theme/pv_colors.dart';
|
||
|
||
/// 第二行控制栏:手动控制 / 暂停任务 / 紧急停止 / 截图 / 查看地图。
|
||
///
|
||
/// 中间「紧急停止」为主操作,尺寸更大、红色发光;其余为普通圆形按钮。
|
||
class PvControlBar extends StatelessWidget {
|
||
const PvControlBar({
|
||
super.key,
|
||
required this.onManualControl,
|
||
required this.onPauseTask,
|
||
required this.onEmergencyStop,
|
||
required this.onScreenshot,
|
||
required this.onViewMap,
|
||
this.mapActive = false,
|
||
});
|
||
|
||
final VoidCallback onManualControl;
|
||
final VoidCallback onPauseTask;
|
||
final VoidCallback onEmergencyStop;
|
||
final VoidCallback onScreenshot;
|
||
final VoidCallback onViewMap;
|
||
|
||
/// 「查看地图」处于激活态时高亮该按钮
|
||
final bool mapActive;
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final tr = AppLocalizations.of(context);
|
||
return Container(
|
||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
||
decoration: PvColors.panel(radius: 18, border: PvColors.cardBorder),
|
||
child: Row(
|
||
children: [
|
||
Expanded(
|
||
child: _ControlButton(
|
||
icon: Icons.adjust,
|
||
label: tr.translate('pv_control.manual_control'),
|
||
onTap: onManualControl,
|
||
),
|
||
),
|
||
Expanded(
|
||
child: _ControlButton(
|
||
icon: Icons.pause,
|
||
label: tr.translate('pv_control.pause_task'),
|
||
onTap: onPauseTask,
|
||
),
|
||
),
|
||
Expanded(
|
||
child: PvEmergencyStopButton(onTap: onEmergencyStop),
|
||
),
|
||
Expanded(
|
||
child: _ControlButton(
|
||
icon: Icons.videocam,
|
||
label: tr.translate('pv_control.screenshot'),
|
||
onTap: onScreenshot,
|
||
),
|
||
),
|
||
Expanded(
|
||
child: _ControlButton(
|
||
icon: Icons.place,
|
||
label: tr.translate('pv_control.view_map'),
|
||
onTap: onViewMap,
|
||
active: mapActive,
|
||
),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
}
|
||
|
||
class _ControlButton extends StatelessWidget {
|
||
const _ControlButton({
|
||
required this.icon,
|
||
required this.label,
|
||
required this.onTap,
|
||
this.active = false,
|
||
});
|
||
|
||
final IconData icon;
|
||
final String label;
|
||
final VoidCallback onTap;
|
||
final bool active;
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final color = active ? PvColors.accentBright : PvColors.textPrimary;
|
||
return GestureDetector(
|
||
onTap: onTap,
|
||
behavior: HitTestBehavior.opaque,
|
||
child: Column(
|
||
mainAxisSize: MainAxisSize.min,
|
||
children: [
|
||
Container(
|
||
width: 36,
|
||
height: 36,
|
||
decoration: BoxDecoration(
|
||
shape: BoxShape.circle,
|
||
color: active
|
||
? PvColors.accent.withValues(alpha: 0.18)
|
||
: PvColors.cardInner,
|
||
border: Border.all(
|
||
color: active ? PvColors.accent : PvColors.cardBorder,
|
||
width: active ? 2 : 1,
|
||
),
|
||
),
|
||
child: Icon(icon, color: color, size: 18),
|
||
),
|
||
const SizedBox(height: 2),
|
||
Padding(
|
||
padding: const EdgeInsets.symmetric(horizontal: 2),
|
||
child: FittedBox(
|
||
fit: BoxFit.scaleDown,
|
||
child: Text(
|
||
label,
|
||
maxLines: 1,
|
||
textAlign: TextAlign.center,
|
||
style: TextStyle(
|
||
color: active
|
||
? PvColors.accentBright
|
||
: PvColors.textSecondary,
|
||
fontSize: 10,
|
||
fontWeight: active ? FontWeight.w700 : FontWeight.w500,
|
||
),
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
}
|
||
|
||
/// 紧急停止圆形按钮:红色发光 + 图标 + 下方文字。
|
||
///
|
||
/// 默认尺寸用于第二行控制栏;手动控制全屏态可传入更大的 [size] 复用同一个按钮。
|
||
class PvEmergencyStopButton extends StatefulWidget {
|
||
const PvEmergencyStopButton({
|
||
super.key,
|
||
required this.onTap,
|
||
this.size = 46,
|
||
this.iconSize = 26,
|
||
this.gap = 2,
|
||
this.labelSize = 10,
|
||
});
|
||
final VoidCallback onTap;
|
||
final double size;
|
||
final double iconSize;
|
||
final double gap;
|
||
final double labelSize;
|
||
|
||
@override
|
||
State<PvEmergencyStopButton> createState() => _PvEmergencyStopButtonState();
|
||
}
|
||
|
||
class _PvEmergencyStopButtonState extends State<PvEmergencyStopButton>
|
||
with SingleTickerProviderStateMixin {
|
||
late final AnimationController _controller;
|
||
|
||
/// 是否处于「急停中」:默认 false(正常态、不呼吸)。
|
||
/// 点击一次进入急停(呼吸 + 「急停中」提示),再点一次解除恢复正常。
|
||
bool _active = false;
|
||
|
||
@override
|
||
void initState() {
|
||
super.initState();
|
||
_controller = AnimationController(
|
||
vsync: this,
|
||
duration: const Duration(milliseconds: 1100),
|
||
);
|
||
}
|
||
|
||
@override
|
||
void dispose() {
|
||
_controller.dispose();
|
||
super.dispose();
|
||
}
|
||
|
||
void _handleTap() {
|
||
setState(() => _active = !_active);
|
||
if (_active) {
|
||
_controller.repeat(reverse: true);
|
||
} else {
|
||
_controller.stop();
|
||
_controller.value = 0;
|
||
}
|
||
widget.onTap();
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return AnimatedBuilder(
|
||
animation: _controller,
|
||
builder: (context, child) {
|
||
final t = _active ? _controller.value : 0.0;
|
||
return GestureDetector(
|
||
onTap: _handleTap,
|
||
behavior: HitTestBehavior.opaque,
|
||
child: Column(
|
||
mainAxisSize: MainAxisSize.min,
|
||
children: [
|
||
Transform.scale(
|
||
scale: 1.0 + 0.08 * t,
|
||
child: Container(
|
||
width: widget.size,
|
||
height: widget.size,
|
||
decoration: BoxDecoration(
|
||
shape: BoxShape.circle,
|
||
gradient: const RadialGradient(
|
||
colors: [Color(0xFFFF5A4D), Color(0xFFD6000F)],
|
||
),
|
||
boxShadow: [
|
||
BoxShadow(
|
||
color: PvColors.danger.withValues(alpha: 0.5 + 0.35 * t),
|
||
blurRadius: 18 + 12 * t,
|
||
spreadRadius: 2 + 3 * t,
|
||
),
|
||
],
|
||
),
|
||
child: Icon(
|
||
Icons.stop_circle_outlined,
|
||
color: Colors.white,
|
||
size: widget.iconSize,
|
||
),
|
||
),
|
||
),
|
||
SizedBox(height: widget.gap),
|
||
FittedBox(
|
||
fit: BoxFit.scaleDown,
|
||
child: Text(
|
||
AppLocalizations.of(context).translate(
|
||
_active
|
||
? 'pv_control.emergency_stopping'
|
||
: 'pv_control.emergency_stop',
|
||
),
|
||
maxLines: 1,
|
||
textAlign: TextAlign.center,
|
||
style: TextStyle(
|
||
color: _active ? PvColors.danger : PvColors.textPrimary,
|
||
fontSize: widget.labelSize,
|
||
fontWeight: FontWeight.w700,
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
},
|
||
);
|
||
}
|
||
}
|