USB 摄像头+远程遥控+中英的适配+topic的集成和状态的使用到相应页面

This commit is contained in:
2026-10-20 17:03:37 +08:00
parent 178cd2533c
commit 582242e9aa
144 changed files with 15759 additions and 406 deletions

View File

@@ -0,0 +1,252 @@
import 'package:flutter/material.dart';
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
import '../models/pv_video_fit.dart';
import '../models/pv_video_source.dart';
import '../theme/pv_colors.dart';
/// 页面设置面板(底部弹出,遮罩半透明可透视下方视频,边调边看效果)。
///
/// 纯展示 + 回调:所有设置状态由 PvControlPage 持有。当前四项:
/// - 视频源:以太网 RTSP / HDMI(USB 采集卡) / WebRTC,切换即重建对应链路 cubit;
/// - 视频展示:完整显示(不裁画面、可能留黑边)/ 铺满屏幕(无黑边、裁掉边缘);
/// - 模拟障碍物信息:真实推送未接入前手动触发,开启 = 相当于收到机器告警推送,
/// 预警横幅 + AR 障碍框 + 屏幕四周泛红**同时**显示;
/// - 倒车影像:开启后左栏后视卡叠加倒车引导线效果(模拟倒车挡)。
class PvSettingsSheet extends StatelessWidget {
const PvSettingsSheet({
super.key,
required this.videoSource,
required this.videoFit,
required this.simObstacle,
required this.simReverse,
required this.onVideoSourceChanged,
required this.onVideoFitChanged,
required this.onSimObstacleChanged,
required this.onSimReverseChanged,
});
final PvVideoSource videoSource;
final PvVideoFit videoFit;
final bool simObstacle;
final bool simReverse;
final ValueChanged<PvVideoSource> onVideoSourceChanged;
final ValueChanged<PvVideoFit> onVideoFitChanged;
final ValueChanged<bool> onSimObstacleChanged;
final ValueChanged<bool> onSimReverseChanged;
/// 视频源选项:顺序与文案按需求固定(以太网 RTSP 源、HDMI、WebRTC)。
static const List<(PvVideoSource, String)> _sources = [
(PvVideoSource.localRtsp, 'pv_control.set_source_rtsp'),
(PvVideoSource.usbCamera, 'pv_control.set_source_hdmi'),
(PvVideoSource.webrtc, 'pv_control.set_source_webrtc'),
];
/// 视频展示选项:文案说清“取舍”以免用户选完还是困惑。
static const List<(PvVideoFit, String)> _fits = [
(PvVideoFit.contain, 'pv_control.set_fit_contain'),
(PvVideoFit.cover, 'pv_control.set_fit_cover'),
];
@override
Widget build(BuildContext context) {
final tr = AppLocalizations.of(context);
// 横屏可用高度有限:最大高度限幅 + 可滚动防底部裁切;
// 视频源行用 Wrap,窄屏 / 大字体下药丸自动换行不溢出。
final maxH = MediaQuery.sizeOf(context).height * 0.72;
return ConstrainedBox(
constraints: BoxConstraints(maxHeight: maxH),
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.fromLTRB(18, 0, 18, 12),
child: Container(
padding: const EdgeInsets.fromLTRB(14, 4, 10, 8),
decoration: BoxDecoration(
color: PvColors.card,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: PvColors.cardBorder),
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 标题行 + 关闭
Row(
children: [
const Icon(
Icons.settings_outlined,
color: PvColors.accentBright,
size: 18,
),
const SizedBox(width: 8),
Text(
tr.translate('pv_control.nav_settings'),
style: PvType.cardTitle,
),
const Spacer(),
IconButton(
icon: const Icon(
Icons.close,
color: PvColors.textSecondary,
size: 20,
),
visualDensity: VisualDensity.compact,
padding: EdgeInsets.zero,
constraints:
const BoxConstraints(minWidth: 32, minHeight: 32),
onPressed: () => Navigator.of(context).pop(),
),
],
),
// 视频源(Wrap:空间不够自动换第二行)
Wrap(
spacing: 8,
runSpacing: 2,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
Text(
tr.translate('pv_control.set_video_source'),
style: PvType.label,
),
for (final (src, label) in _sources)
_pill(
label: tr.translate(label),
selected: src == videoSource,
onTap: () => onVideoSourceChanged(src),
),
],
),
// 视频展示(适配方式)+ 一句取舍说明
const SizedBox(height: 6),
Wrap(
spacing: 8,
runSpacing: 2,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
Text(
tr.translate('pv_control.set_video_fit'),
style: PvType.label,
),
for (final (fitMode, label) in _fits)
_pill(
label: tr.translate(label),
selected: fitMode == videoFit,
onTap: () => onVideoFitChanged(fitMode),
),
Text(
videoFit == PvVideoFit.contain
? tr.translate('pv_control.set_fit_contain_hint')
: tr.translate('pv_control.set_fit_cover_hint'),
style: PvType.caption.copyWith(
color: PvColors.textTertiary,
),
),
],
),
const SizedBox(height: 4),
_switchTile(
icon: Icons.warning_amber_rounded,
iconColor:
simObstacle ? PvColors.danger : PvColors.textTertiary,
title: tr.translate('pv_control.set_sim_obstacle'),
subtitle: tr.translate('pv_control.set_sim_obstacle_sub'),
value: simObstacle,
onChanged: onSimObstacleChanged,
),
_switchTile(
icon: Icons.directions_car,
iconColor:
simReverse ? PvColors.accentBright : PvColors.textTertiary,
title: tr.translate('pv_control.set_sim_reverse'),
subtitle: tr.translate('pv_control.set_sim_reverse_sub'),
value: simReverse,
onChanged: onSimReverseChanged,
),
],
),
),
),
),
);
}
/// 药丸选项:选中态青色描边 + 填充,与 HUD 预设档位风格一致(视频源 / 视频展示共用)。
/// 左右间距由外层 Wrap 的 spacing 提供,此处只留纵向呼吸。
Widget _pill({
required String label,
required bool selected,
required VoidCallback onTap,
}) {
return GestureDetector(
onTap: onTap,
behavior: HitTestBehavior.opaque,
child: AnimatedContainer(
duration: const Duration(milliseconds: 180),
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
decoration: BoxDecoration(
color: selected
? PvColors.accent.withValues(alpha: 0.20)
: PvColors.cardInner,
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: selected ? PvColors.accent : PvColors.cardBorder,
),
),
child: Text(
label,
style: PvType.body.copyWith(
color: selected
? PvColors.accentBright
: PvColors.textSecondary,
fontWeight: selected ? FontWeight.w700 : FontWeight.w400,
),
),
),
);
}
/// 开关行:图标 + 标题/说明 + Switch(整行可点按切换,热区更大)。
Widget _switchTile({
required IconData icon,
required Color iconColor,
required String title,
required String subtitle,
required bool value,
required ValueChanged<bool> onChanged,
}) {
return InkWell(
onTap: () => onChanged(!value),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 4),
child: Row(
children: [
Icon(icon, size: 20, color: iconColor),
const SizedBox(width: 10),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(title, style: PvType.cardTitle),
Text(
subtitle,
style: PvType.caption.copyWith(height: 1.3),
),
],
),
),
// Switch 自身禁用手势,统一走整行 onTap,避免两套状态
IgnorePointer(
child: Switch(
value: value,
onChanged: (_) {},
activeThumbColor: PvColors.accentBright,
activeTrackColor: PvColors.accent.withValues(alpha: 0.35),
),
),
],
),
),
);
}
}