USB 摄像头+远程遥控+中英的适配+topic的集成和状态的使用到相应页面
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
import 'package:maibu_satabot_v2/core/di/injection.dart';
|
||||
import 'package:maibu_satabot_v2/features/remote_control/presentation/bloc/remote_control_cubit.dart';
|
||||
|
||||
/// 遥控指令的**传输抽象**(预留扩展)。
|
||||
///
|
||||
/// HUD / 页面只调用这里的「语义方法」,不关心底层是 TCP、蓝牙还是下位机连接:
|
||||
/// 将来新增通信方式时,只需再写一个实现类(如 `BleRobotCommandChannel`),
|
||||
/// 由调用方决定注入哪一个实现,UI 与控制语义代码零改动。
|
||||
///
|
||||
/// 段位值统一沿用远程遥控编码:上=1、中=0、下=2
|
||||
/// (割刀 1 抬 / 2 降、底盘 1 升 / 2 降、点火 1 点火 / 2 熄火,0 都是停止)。
|
||||
abstract interface class PvRobotCommandChannel {
|
||||
/// 前进 / 后退(左摇杆,-100~100,上推为正=前进)。
|
||||
void sendDriveY(int y);
|
||||
|
||||
/// 左转 / 右转(右摇杆,-100~100)。
|
||||
void sendDriveX(int x);
|
||||
|
||||
/// 底盘升降。
|
||||
void sendChassis(int cmd);
|
||||
|
||||
/// 割刀升降。
|
||||
void sendMower(int cmd);
|
||||
|
||||
/// 点火 / 熄火。
|
||||
void sendIgnition(int cmd);
|
||||
|
||||
/// 紧急停止。
|
||||
void sendEmergencyStop(bool on);
|
||||
|
||||
/// 双轴归零(松手即停,安全底线)。
|
||||
Future<void> stopAllMovement();
|
||||
|
||||
/// 进入控制态:查询一次控制权限,并开始持续下发控制帧(默认 100ms 控制循环)。
|
||||
void activate();
|
||||
|
||||
/// 退出控制态:归零、停止控制循环、释放控制权、复位权限。
|
||||
///
|
||||
/// 返回释放接口结果(`true` 成功 / `false` 失败);无目标设备、未发起释放时
|
||||
/// 返回 `null`,供页面决定是否弹出与远程遥控页一致的释放提示。
|
||||
Future<bool?> deactivate();
|
||||
}
|
||||
|
||||
/// 基于 TCP 的实现:委托现有 [RemoteControlCubit] 单例,**不改动远程遥控逻辑**,
|
||||
/// 因此与极简模式的远程遥控页共用同一套协议、权限与控制循环。
|
||||
class RemoteControlRobotChannel implements PvRobotCommandChannel {
|
||||
const RemoteControlRobotChannel();
|
||||
|
||||
RemoteControlCubit get _cubit => sl<RemoteControlCubit>();
|
||||
|
||||
@override
|
||||
void sendDriveY(int y) => _cubit.updateOriginY(y);
|
||||
|
||||
@override
|
||||
void sendDriveX(int x) => _cubit.updateOriginX(x);
|
||||
|
||||
@override
|
||||
void sendChassis(int cmd) => _cubit.sendChassisCommand(cmd);
|
||||
|
||||
@override
|
||||
void sendMower(int cmd) => _cubit.sendMowerCommand(cmd);
|
||||
|
||||
@override
|
||||
void sendIgnition(int cmd) => _cubit.sendFireCommand(cmd);
|
||||
|
||||
@override
|
||||
void sendEmergencyStop(bool on) => _cubit.updateEmergency(on);
|
||||
|
||||
@override
|
||||
Future<void> stopAllMovement() => _cubit.stopAllMovement();
|
||||
|
||||
@override
|
||||
void activate() {
|
||||
final cubit = _cubit;
|
||||
// 与远程遥控页一致:进控制态先「仅查询」一次控制权限(grabControl=false,
|
||||
// 只把接口结果如实同步到 hasPermission,不发 TCP 抢占),再启动 100ms 控制循环。
|
||||
// 无权限时控制循环会自动跳过发送,行为与极简模式完全相同。
|
||||
final deviceName = cubit.state.targetDevice?.deviceName;
|
||||
if (deviceName != null && deviceName.isNotEmpty) {
|
||||
// 与远程遥控页一样不等待回包(fire-and-forget)。
|
||||
cubit.requestControlPermissionS(
|
||||
deviceName,
|
||||
'app',
|
||||
source: '全功能HUD进入',
|
||||
grabControl: false,
|
||||
);
|
||||
}
|
||||
cubit.startControlLoop();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool?> deactivate() async {
|
||||
// 先解除急停,避免 HUD 退出时残留 isEmergency=true,
|
||||
// 让下一次进入(含极简远程遥控页)控制循环被锁住无法运动。
|
||||
_cubit.updateEmergency(false);
|
||||
// 停止指令无视权限强制发送,先归零再停循环,避免残留运动。
|
||||
await _cubit.stopAllMovement();
|
||||
_cubit.stopControlLoop();
|
||||
// 与远程遥控页一致:退出释放远程控制权限(type=2),设备名取当前 targetDevice。
|
||||
final deviceId = _cubit.state.targetDevice?.deviceName;
|
||||
bool? released;
|
||||
if (deviceId != null && deviceId.isNotEmpty) {
|
||||
released = await _cubit.releasePermission(deviceId: deviceId, type: 2);
|
||||
}
|
||||
_cubit.resetPermissionState();
|
||||
// 把释放结果回传给页面,用于弹与远程遥控页一致的成功/失败提示。
|
||||
return released;
|
||||
}
|
||||
}
|
||||
110
lib/features/pv_control/presentation/models/pv_telemetry.dart
Normal file
110
lib/features/pv_control/presentation/models/pv_telemetry.dart
Normal file
@@ -0,0 +1,110 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
/// 光伏巡检机器人实时遥测数据(本批次为 Mock 假数据,后续可替换为 MQTT/TCP 真实来源)
|
||||
///
|
||||
/// 采用不可变对象 + copyWith,便于后续接入真实数据流时局部更新字段。
|
||||
@immutable
|
||||
class PvTelemetry {
|
||||
const PvTelemetry({
|
||||
this.deviceName = '光伏巡检机器人',
|
||||
this.serialNumber = 'PV-RB-001',
|
||||
this.isOnline = true,
|
||||
this.battery,
|
||||
this.isAutoDriving = true,
|
||||
this.taskStatus = '巡检任务进行中',
|
||||
this.speed = 0.3,
|
||||
this.mileage,
|
||||
this.networkNormal = true,
|
||||
this.temperature,
|
||||
this.fixStatus,
|
||||
this.satelliteCount,
|
||||
this.controlMode,
|
||||
this.resolution = '1920 × 1080',
|
||||
this.fps = 30,
|
||||
this.obstacleAlert = false,
|
||||
this.obstacleDistance = 1.2,
|
||||
});
|
||||
|
||||
final String deviceName;
|
||||
final String serialNumber;
|
||||
final bool isOnline;
|
||||
|
||||
/// 电量百分比 0~100;null=未收到实时数据(显示"未知")
|
||||
final double? battery;
|
||||
|
||||
/// true=自动驾驶中,false=手动控制
|
||||
final bool isAutoDriving;
|
||||
final String taskStatus;
|
||||
|
||||
/// 当前速度 m/s
|
||||
final double speed;
|
||||
|
||||
/// 巡检里程(累计作业里程);null=未收到实时数据(显示"未知")
|
||||
final double? mileage;
|
||||
|
||||
/// 网络是否正常
|
||||
final bool networkNormal;
|
||||
|
||||
/// 设备温度(实时主温度)℃;null=未收到实时数据(显示"未知")
|
||||
final double? temperature;
|
||||
|
||||
/// 定位质量枚举值(来自 location/post 的 fix_status:4=RTK固定解);null=未知
|
||||
final int? fixStatus;
|
||||
|
||||
/// 卫星数(realtime/post 尚未推送,目前无数据源);null=未知
|
||||
final int? satelliteCount;
|
||||
|
||||
/// 当前控制模式原始值(host control_mode,拨杆:0无控制/1本地/2蓝牙/3TCP/4其他);null=未知
|
||||
final String? controlMode;
|
||||
|
||||
final String resolution;
|
||||
final int fps;
|
||||
|
||||
/// 是否障碍物预警。
|
||||
/// 由机器推送驱动(真实接入前可用设置面板「模拟障碍物信息」手动触发);
|
||||
/// 为 true 时预警横幅 + AR 障碍框 + 屏幕泛红呼吸同时展示,默认不亮。
|
||||
final bool obstacleAlert;
|
||||
|
||||
/// 前方障碍距离 m
|
||||
final double obstacleDistance;
|
||||
|
||||
PvTelemetry copyWith({
|
||||
String? deviceName,
|
||||
String? serialNumber,
|
||||
bool? isOnline,
|
||||
double? battery,
|
||||
bool? isAutoDriving,
|
||||
String? taskStatus,
|
||||
double? speed,
|
||||
double? mileage,
|
||||
bool? networkNormal,
|
||||
double? temperature,
|
||||
int? fixStatus,
|
||||
int? satelliteCount,
|
||||
String? controlMode,
|
||||
String? resolution,
|
||||
int? fps,
|
||||
bool? obstacleAlert,
|
||||
double? obstacleDistance,
|
||||
}) {
|
||||
return PvTelemetry(
|
||||
deviceName: deviceName ?? this.deviceName,
|
||||
serialNumber: serialNumber ?? this.serialNumber,
|
||||
isOnline: isOnline ?? this.isOnline,
|
||||
battery: battery ?? this.battery,
|
||||
isAutoDriving: isAutoDriving ?? this.isAutoDriving,
|
||||
taskStatus: taskStatus ?? this.taskStatus,
|
||||
speed: speed ?? this.speed,
|
||||
mileage: mileage ?? this.mileage,
|
||||
networkNormal: networkNormal ?? this.networkNormal,
|
||||
temperature: temperature ?? this.temperature,
|
||||
fixStatus: fixStatus ?? this.fixStatus,
|
||||
satelliteCount: satelliteCount ?? this.satelliteCount,
|
||||
controlMode: controlMode ?? this.controlMode,
|
||||
resolution: resolution ?? this.resolution,
|
||||
fps: fps ?? this.fps,
|
||||
obstacleAlert: obstacleAlert ?? this.obstacleAlert,
|
||||
obstacleDistance: obstacleDistance ?? this.obstacleDistance,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/// 视频画面在展示区域内的适配方式(设置面板「视频展示」可切换)。
|
||||
///
|
||||
/// 两种方式是客观取舍,不可能同时满足:
|
||||
/// - [contain] 完整显示:画面一格不裁,比例与窗口不一致时上下 / 左右留黑边;
|
||||
/// - [cover] 铺满屏幕:等比放大到铺满、无黑边,超出窗口的边缘部分被裁掉。
|
||||
enum PvVideoFit {
|
||||
/// 完整显示(默认):不裁任何内容,可能留黑边。
|
||||
contain,
|
||||
|
||||
/// 铺满屏幕:无黑边,等比放大后裁掉超出窗口的边缘。
|
||||
cover,
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/// pv_control 页面支持的视频链路枚举(多源可扩展)。
|
||||
///
|
||||
/// 新增一种链路只需三步:
|
||||
/// ① 在这里加一个枚举值;
|
||||
/// ② 在 pv_control_page 的 `_wrapVideoProvider` 注册对应 cubit(若需要);
|
||||
/// ③ 在 PvVideoArea / PvManualControlView 的视频层加一个渲染分支。
|
||||
///
|
||||
/// 切换 UI 暂不做,由页面字段 `_videoSource` 指定当前链路。
|
||||
enum PvVideoSource {
|
||||
/// 云端 WebRTC 流(原始方案,走 webrtc:// 地址)。
|
||||
webrtc,
|
||||
|
||||
/// 本地以太网 RTSP:ONVIF 自动发现 + ExoPlayer 拉流,卡死自动重拉。
|
||||
localRtsp,
|
||||
|
||||
/// USB 摄像头(UVC 采集卡,PlatformView 低延迟直显)。
|
||||
usbCamera,
|
||||
}
|
||||
801
lib/features/pv_control/presentation/pages/pv_control_page.dart
Normal file
801
lib/features/pv_control/presentation/pages/pv_control_page.dart
Normal file
@@ -0,0 +1,801 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
import 'package:maibu_satabot_v2/core/app/app_user_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/core/consts/tcp_consts.dart';
|
||||
import 'package:maibu_satabot_v2/core/di/injection.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
import 'package:maibu_satabot_v2/features/auth/presentation/bloc/auth_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/presentation/bloc/device_status_bloc.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/presentation/bloc/device_status_state.dart';
|
||||
import 'package:maibu_satabot_v2/features/remote_control/presentation/bloc/remote_control_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/remote_control/presentation/bloc/remote_control_state.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/local_camera/presentation/cubit/local_camera_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/usb_camera/data/uvc_camera_service.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/usb_camera/presentation/cubit/usb_camera_cubit.dart';
|
||||
|
||||
import '../models/pv_telemetry.dart';
|
||||
import '../channel/pv_robot_command_channel.dart';
|
||||
import '../models/pv_video_fit.dart';
|
||||
import '../models/pv_video_source.dart';
|
||||
import '../theme/pv_colors.dart';
|
||||
import '../widgets/pv_control_bar.dart';
|
||||
import '../widgets/pv_info_column.dart';
|
||||
import '../widgets/pv_manual_control_view.dart';
|
||||
import '../widgets/pv_settings_sheet.dart';
|
||||
import '../widgets/pv_video_area.dart';
|
||||
import '../widgets/pv_work_map.dart';
|
||||
|
||||
/// 页面视图模式:普通态 / 手动控制全屏态
|
||||
enum PvViewMode { normal, manualControl }
|
||||
|
||||
/// 光伏电站机器人远程控制(横屏大屏)页面。
|
||||
///
|
||||
/// 布局弹性可变:顶部导航固定,下方第一行(视频 + 右侧列)随空间伸缩,
|
||||
/// 第二行控制栏固定高度。右侧列可在「信息」与「地图」间切换;
|
||||
/// 「手动控制」进入视频铺满全屏 + 摇杆的形态,底部折叠图标返回。
|
||||
class PvControlPage extends StatefulWidget {
|
||||
const PvControlPage({super.key, required this.deviceId, this.deviceName});
|
||||
|
||||
final String deviceId;
|
||||
final String? deviceName;
|
||||
|
||||
@override
|
||||
State<PvControlPage> createState() => _PvControlPageState();
|
||||
}
|
||||
|
||||
class _PvControlPageState extends State<PvControlPage> {
|
||||
/// 截图用的视频区 RepaintBoundary key
|
||||
final GlobalKey _videoKey = GlobalKey();
|
||||
|
||||
/// 本批次使用 Mock 遥测数据
|
||||
final PvTelemetry _telemetry = const PvTelemetry();
|
||||
|
||||
/// 遥控指令传输通道:当前为 TCP 实现(委托 `RemoteControlCubit`),
|
||||
/// 以后接蓝牙 / 下位机只换一个实现类,HUD 与本页面代码零改动。
|
||||
final PvRobotCommandChannel _channel = const RemoteControlRobotChannel();
|
||||
|
||||
/// 控制态是否已激活:进入「手动控制」才 activate,退出 / 页面销毁 deactivate。
|
||||
bool _controlActive = false;
|
||||
|
||||
/// 急停开关态:HUD 急停钮每点一次翻转,经通道下发 updateEmergency。
|
||||
bool _emergencyOn = false;
|
||||
|
||||
/// 远程控制单例(HUD 与原远程遥控页共用它,指令通道内部也委托它)。
|
||||
RemoteControlCubit get _cubit => sl<RemoteControlCubit>();
|
||||
|
||||
/// 「权限交接」监听订阅:监听其它端请求控制权的推送并弹确认框。
|
||||
StreamSubscription? _permissionSubscription;
|
||||
|
||||
/// 防止权限弹窗重复弹出(与远程遥控页一致)。
|
||||
bool _isShowingPermissionDialog = false;
|
||||
|
||||
/// 记录上次弹窗显示态,用于检测 false→true 的上升沿。
|
||||
bool? _lastPermissionDialogState;
|
||||
|
||||
PvViewMode _mode = PvViewMode.normal;
|
||||
|
||||
/// 右侧列是否显示地图(点击「查看地图」切换)
|
||||
bool _showMap = false;
|
||||
|
||||
String _streamUrl = '';
|
||||
|
||||
/// 当前视频链路(多源可扩展):在设置面板「视频源」行切换,
|
||||
/// 切换即重建对应链路 cubit(_wrapVideoProvider 挂了 ValueKey)。
|
||||
PvVideoSource _videoSource = PvVideoSource.usbCamera;
|
||||
|
||||
/// 视频展示方式(设置面板「视频展示」行切换):
|
||||
/// contain 完整显示(可能留黑边)/ cover 等比铺满(裁掉边缘)。
|
||||
PvVideoFit _videoFit = PvVideoFit.contain;
|
||||
|
||||
/// 模拟开关(真实推送未接入前在设置面板手动触发)。
|
||||
bool _simObstacle = false;
|
||||
bool _simReverse = false;
|
||||
|
||||
/// 实际下发的遥测:真实字段来自全局 [DeviceStatusBloc] 的 host 实时数据
|
||||
/// (电量/巡检里程/设备温度),未收到时置 null 由 UI 显示"未知";
|
||||
/// 开启「模拟障碍物信息」相当于收到机器告警推送,叠加 obstacleAlert。
|
||||
PvTelemetry _resolveTelemetry(DeviceStatusState dsState) {
|
||||
double? battery;
|
||||
double? mileage;
|
||||
double? temp;
|
||||
int? fixStatus;
|
||||
int? satelliteCount;
|
||||
String? controlMode;
|
||||
if (dsState is DeviceStatusUpdated) {
|
||||
final s = dsState.status;
|
||||
// 定位质量:来自 location/post 的 fix_status(qual)
|
||||
fixStatus = s.qual;
|
||||
// 控制模式:与“设备数据监控”同一口径,只要收到状态就跟随,不加 host 门控
|
||||
controlMode = s.controlMode;
|
||||
// 卫星数:realtime/post 尚未推送,无数据源时保持 null 显示"未知"
|
||||
if (s.satelliteCnt > 0) satelliteCount = s.satelliteCnt;
|
||||
// 以下三项来自 host 实时话题(device/{sn}/host/realTime/message)
|
||||
if (s.hostDataReceived) {
|
||||
battery = double.tryParse(s.battery);
|
||||
mileage = s.totalWorkDistance;
|
||||
temp = s.chipTemp;
|
||||
}
|
||||
}
|
||||
return _telemetry.copyWith(
|
||||
obstacleAlert: _simObstacle,
|
||||
battery: battery,
|
||||
mileage: mileage,
|
||||
temperature: temp,
|
||||
fixStatus: fixStatus,
|
||||
satelliteCount: satelliteCount,
|
||||
controlMode: controlMode,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_enterLandscape();
|
||||
_initVideoUrl();
|
||||
_ensureRealtimeListening();
|
||||
// 进入安全模式:防止异地登录推送把控制踢下线(与远程遥控页一致)。
|
||||
sl<AuthCubit>().enterSafeMode();
|
||||
// 监听「权限交接」:其它端请求控制权时弹确认框,整页生命周期常驻。
|
||||
_initPermissionHandoverListener();
|
||||
// 进页面即建立控制会话:查询权限 + 启动控制循环(等价远程遥控页进页行为)。
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => _startControl());
|
||||
}
|
||||
|
||||
/// 本页的视频、地图、遥测都是围绕 `deviceId` 这一台设备,所以进页时确保
|
||||
/// MQTT 实时定位/路线订阅就指向它(全局单例 bloc,数据源内部同 SN 去重、
|
||||
/// 自动退旧订新,重复调用无副作用)。退出页面不切回去:语义与设备列表
|
||||
/// 正常切设备一致,切回去反而会让别处(如路径规划)突然断流。
|
||||
void _ensureRealtimeListening() {
|
||||
if (widget.deviceId.isEmpty) return;
|
||||
context.read<DeviceStatusBloc>().startMqttRealtimeListening(
|
||||
widget.deviceId,
|
||||
);
|
||||
}
|
||||
|
||||
/// 进入页面强制横屏
|
||||
void _enterLandscape() {
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
|
||||
SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.landscapeLeft,
|
||||
DeviceOrientation.landscapeRight,
|
||||
]);
|
||||
}
|
||||
|
||||
/// 离开页面恢复竖屏 + 系统栏
|
||||
void _restoreOrientation() {
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||
SystemChrome.setPreferredOrientations(DeviceOrientation.values);
|
||||
}
|
||||
|
||||
void _initVideoUrl() {
|
||||
final userState = context.read<AppUserCubit>().state;
|
||||
final token = userState.user?.token;
|
||||
if (widget.deviceId.isNotEmpty && token != null) {
|
||||
setState(() {
|
||||
_streamUrl =
|
||||
'webrtc://${TCPConsts.TCP_IP}/live/livestream/${widget.deviceId}?token=$token';
|
||||
});
|
||||
} else {
|
||||
debugPrint('❌ [PvControl] 视频URL初始化失败:deviceId 或 token 为空');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// 离开安全模式:启动 90 秒倒计时(与远程遥控页一致)。
|
||||
sl<AuthCubit>().exitSafeMode();
|
||||
// 取消「权限交接」弹窗监听,避免回调打到已销毁的 State。
|
||||
_permissionSubscription?.cancel();
|
||||
_permissionSubscription = null;
|
||||
// 退出控制态:归零、停循环、释放权限(type=2)、解除急停、复位权限态。
|
||||
_stopControl();
|
||||
_restoreOrientation();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
// ===== 交互回调 =====
|
||||
|
||||
void _onViewMap() {
|
||||
setState(() => _showMap = !_showMap);
|
||||
}
|
||||
|
||||
void _onManualControl() {
|
||||
setState(() => _mode = PvViewMode.manualControl);
|
||||
}
|
||||
|
||||
void _onCollapseManual() {
|
||||
setState(() => _mode = PvViewMode.normal);
|
||||
}
|
||||
|
||||
void _onPauseTask() {
|
||||
CapsuleToast.show(
|
||||
AppLocalizations.of(context).translate('pv_control.toast_paused'),
|
||||
showCheck: false,
|
||||
);
|
||||
}
|
||||
|
||||
void _onEmergencyStop() {
|
||||
// HUD 急停钮为“点一下急停 / 再点一下恢复”的切换态(按钮自身不携带 on/off)。
|
||||
_emergencyOn = !_emergencyOn;
|
||||
_channel.sendEmergencyStop(_emergencyOn);
|
||||
final tr = AppLocalizations.of(context);
|
||||
CapsuleToast.show(
|
||||
_emergencyOn
|
||||
? tr.translate('pv_control.toast_emergency_sent')
|
||||
: tr.translate('pv_control.toast_emergency_released'),
|
||||
showCheck: false,
|
||||
);
|
||||
}
|
||||
|
||||
/// 进入控制态:查询权限 + 启动控制循环(与远程遥控页生命周期一致)。
|
||||
void _startControl() {
|
||||
if (_controlActive) return;
|
||||
if (_cubit.state.targetDevice == null) {
|
||||
debugPrint('❌ [PV遥控] targetDevice 为空,跳过控制循环与权限查询');
|
||||
return;
|
||||
}
|
||||
_controlActive = true;
|
||||
// deactivate 会清除急停态,重新进入从“未急停”开始,与通道保持同步。
|
||||
_emergencyOn = false;
|
||||
_channel.activate();
|
||||
}
|
||||
|
||||
/// 退出控制态:归零、停循环、释放权限(通道内部完成,不阻塞 UI)。
|
||||
void _stopControl() {
|
||||
if (!_controlActive) return;
|
||||
_controlActive = false;
|
||||
// dispose 不能 await,fire-and-forget;拿到释放结果后弹与远程遥控页一致的提示
|
||||
//(CapsuleToast 走根 Overlay,页面销毁瞬间也能显示);无设备未发起释放则不弹。
|
||||
_channel.deactivate().then((released) {
|
||||
if (released == null || !mounted) return;
|
||||
final tr = AppLocalizations.of(context);
|
||||
CapsuleToast.show(
|
||||
released
|
||||
? tr.translate('pv_control.toast_permission_released')
|
||||
: tr.translate('pv_control.toast_permission_release_failed'),
|
||||
showCheck: released,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/// 监听「权限交接」:订阅 Cubit 状态流,仅当 `updateType=='permission_dialog'`
|
||||
/// 且 `showPermissionRequestDialog` 由 false→true 的上升沿时弹一次确认框(防重复),
|
||||
/// 逻辑与远程遥控页 `didChangeDependencies` 完全一致。
|
||||
void _initPermissionHandoverListener() {
|
||||
_permissionSubscription = _cubit.stream.listen((state) {
|
||||
// 设备状态更新(500ms)不触发弹窗,只重置记录。
|
||||
if (state.updateType != 'permission_dialog') {
|
||||
if (!state.showPermissionRequestDialog) {
|
||||
_lastPermissionDialogState = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
final wasFalseBefore =
|
||||
_lastPermissionDialogState == null ||
|
||||
_lastPermissionDialogState == false;
|
||||
final shouldShow =
|
||||
state.showPermissionRequestDialog &&
|
||||
!_isShowingPermissionDialog &&
|
||||
wasFalseBefore;
|
||||
if (mounted && shouldShow) {
|
||||
_lastPermissionDialogState = true;
|
||||
_isShowingPermissionDialog = true;
|
||||
debugPrint('🔔 [PV遥控][权限交接] 检测到请求控制权,准备弹窗');
|
||||
Future.microtask(() {
|
||||
_showPermissionDialog(state).then((_) {
|
||||
_isShowingPermissionDialog = false;
|
||||
_lastPermissionDialogState = false;
|
||||
});
|
||||
});
|
||||
} else if (!state.showPermissionRequestDialog) {
|
||||
_lastPermissionDialogState = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// 权限交接弹窗:某端请求控制权 → 同意/拒绝 → `confirmPermissionResponse`
|
||||
/// 发 TCP 响应,关闭前复位 `showPermissionRequestDialog`(与远程遥控页同款)。
|
||||
Future<void> _showPermissionDialog(RemoteControlState state) async {
|
||||
final tr = AppLocalizations.of(context);
|
||||
final requestingDeviceId =
|
||||
state.requestingDeviceId ??
|
||||
tr.translate('pv_control.perm_unknown_device');
|
||||
final requestingPlatform =
|
||||
state.requestingPlatform ??
|
||||
tr.translate('pv_control.perm_unknown_platform');
|
||||
final dialogContent =
|
||||
tr
|
||||
.translate('pv_control.perm_request_body')
|
||||
.replaceAll('{platform}', requestingPlatform)
|
||||
.replaceAll('{deviceId}', requestingDeviceId);
|
||||
final cubit = _cubit;
|
||||
return showDialog<void>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
// 深色遮罩:贴合本页深蓝科技风大屏(不透默认 Material 黑半透)。
|
||||
barrierColor: PvColors.bgDeepest.withValues(alpha: 0.55),
|
||||
builder: (dialogContext) {
|
||||
Future<void> respond(bool agreed) async {
|
||||
final targetDevice = cubit.state.targetDevice;
|
||||
if (targetDevice != null) {
|
||||
await cubit.confirmPermissionResponse(
|
||||
targetDevice.deviceName,
|
||||
'app',
|
||||
agreed,
|
||||
);
|
||||
} else {
|
||||
debugPrint('❌ [PV遥控][权限交接] targetDevice 为空,无法响应');
|
||||
}
|
||||
// 先复位标志位再关闭,避免 pop 后上下文失效。
|
||||
cubit.resetPermissionCoolDown();
|
||||
cubit.togglePermissionDialog(false);
|
||||
if (dialogContext.mounted && Navigator.canPop(dialogContext)) {
|
||||
Navigator.pop(dialogContext);
|
||||
}
|
||||
}
|
||||
|
||||
final title = AppLocalizations.of(
|
||||
dialogContext,
|
||||
).translate('remote_control.permission_request_title');
|
||||
final refuseText = AppLocalizations.of(
|
||||
dialogContext,
|
||||
).translate('remote_control.refuse');
|
||||
final agreeText = AppLocalizations.of(
|
||||
dialogContext,
|
||||
).translate('remote_control.agree');
|
||||
// 样式适配本页大屏:深蓝卡片 + 青色描边 + 科技青主按钮(与远程
|
||||
// 遥控页同一交互/文案,仅视觉风格跟随 pv 主题)。
|
||||
return Dialog(
|
||||
backgroundColor: PvColors.card,
|
||||
surfaceTintColor: Colors.transparent,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
side: const BorderSide(color: PvColors.cardBorder, width: 1),
|
||||
),
|
||||
insetPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 60,
|
||||
vertical: 24,
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(22, 20, 22, 12),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.swap_horiz,
|
||||
color: PvColors.accent,
|
||||
size: 20,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
title,
|
||||
style: PvType.cardTitle.copyWith(fontSize: 16),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
dialogContent,
|
||||
style: PvType.body.copyWith(color: PvColors.textSecondary),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () => respond(false),
|
||||
child: Text(
|
||||
refuseText,
|
||||
style: PvType.body.copyWith(
|
||||
color: PvColors.textSecondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
TextButton(
|
||||
onPressed: () => respond(true),
|
||||
style: TextButton.styleFrom(
|
||||
backgroundColor: PvColors.accent,
|
||||
foregroundColor: PvColors.bgDeepest,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 18),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
agreeText,
|
||||
style: PvType.body.copyWith(
|
||||
color: PvColors.bgDeepest,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// 设置面板(底部弹出,遮罩半透明可透视下方视频边调边看):
|
||||
/// 视频源 / 视频展示 / 模拟障碍物信息 / 倒车影像。
|
||||
void _openSettings() {
|
||||
showModalBottomSheet<void>(
|
||||
context: context,
|
||||
backgroundColor: Colors.transparent,
|
||||
// 面板内部自带 maxHeight + 滚动,这里放开模态默认高度限制
|
||||
isScrollControlled: true,
|
||||
// 薄遮罩:能看见底下视频与告警/倒车效果的变化
|
||||
barrierColor: Colors.black.withValues(alpha: 0.35),
|
||||
builder: (_) {
|
||||
// 模态挂在 Overlay 上,页面 setState 不会刷新它,
|
||||
// 用 StatefulBuilder 让药丸/开关的选中态即时回显。
|
||||
return StatefulBuilder(
|
||||
builder: (sheetCtx, setSheetState) {
|
||||
void update(void Function() fn) {
|
||||
setState(fn); // 页面状态:视频链路 / 成套特效开关立即生效
|
||||
setSheetState(() {}); // 面板选中态回显
|
||||
}
|
||||
|
||||
return PvSettingsSheet(
|
||||
videoSource: _videoSource,
|
||||
videoFit: _videoFit,
|
||||
simObstacle: _simObstacle,
|
||||
simReverse: _simReverse,
|
||||
onVideoSourceChanged: (v) => update(() => _videoSource = v),
|
||||
onVideoFitChanged: (v) => update(() => _videoFit = v),
|
||||
onSimObstacleChanged: (v) => update(() => _simObstacle = v),
|
||||
onSimReverseChanged: (v) => update(() => _simReverse = v),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onScreenshot() async {
|
||||
final bytes = await _captureVideoBytes();
|
||||
if (bytes == null) {
|
||||
if (mounted) {
|
||||
CapsuleToast.show(
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('pv_control.toast_screenshot_failed'),
|
||||
showCheck: false,
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
final path = await _saveToAppDir(bytes);
|
||||
if (!mounted) return;
|
||||
if (path != null) {
|
||||
CapsuleToast.show(
|
||||
AppLocalizations.of(context).translate('pv_control.toast_screenshot_saved'),
|
||||
);
|
||||
}
|
||||
// 截图后弹出预览
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (ctx) => _ScreenshotPreviewDialog(imageBytes: bytes, path: path),
|
||||
);
|
||||
}
|
||||
|
||||
/// 截取视频区像素
|
||||
Future<Uint8List?> _captureVideoBytes() async {
|
||||
try {
|
||||
final boundary =
|
||||
_videoKey.currentContext?.findRenderObject()
|
||||
as RenderRepaintBoundary?;
|
||||
if (boundary == null) return null;
|
||||
final ui.Image image = await boundary.toImage(pixelRatio: 2.0);
|
||||
final ByteData? byteData = await image.toByteData(
|
||||
format: ui.ImageByteFormat.png,
|
||||
);
|
||||
image.dispose();
|
||||
return byteData?.buffer.asUint8List();
|
||||
} catch (e) {
|
||||
debugPrint('❌ [PvControl] 截图异常: $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// 保存到应用文档目录(无需相册权限,稳定可用)
|
||||
Future<String?> _saveToAppDir(Uint8List bytes) async {
|
||||
try {
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
final ts = DateTime.now().millisecondsSinceEpoch;
|
||||
final file = File('${dir.path}/pv_capture_$ts.png');
|
||||
await file.writeAsBytes(bytes);
|
||||
return file.path;
|
||||
} catch (e) {
|
||||
debugPrint('❌ [PvControl] 保存截图失败: $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// 按当前视频链路挂载对应的 cubit:页面级**单实例**,普通态与全屏 HUD 共用
|
||||
/// (RTSP/UVC 都是独占硬件会话,禁止双实例)。新增链路在这里注册一个分支。
|
||||
Widget _wrapVideoProvider(Widget child) {
|
||||
switch (_videoSource) {
|
||||
case PvVideoSource.usbCamera:
|
||||
return BlocProvider(
|
||||
// key:视频源切换时强制重建 cubit(新 UVC 会话 / 重新发现拉流)
|
||||
key: const ValueKey('videoProvider_usbCamera'),
|
||||
create: (_) => UsbCameraCubit(UvcCameraService())..start(),
|
||||
child: child,
|
||||
);
|
||||
case PvVideoSource.localRtsp:
|
||||
return BlocProvider(
|
||||
key: const ValueKey('videoProvider_localRtsp'),
|
||||
// autoPlayFirst=发现后自动拉第一路(不展示步骤),
|
||||
// autoRecover=缓冲卡死(0%)/断流时自动重拉流。
|
||||
create: (_) =>
|
||||
LocalCameraCubit(autoPlayFirst: true, autoRecover: true)..start(),
|
||||
child: child,
|
||||
);
|
||||
case PvVideoSource.webrtc:
|
||||
return child;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: PvColors.bgDeepest,
|
||||
body: DecoratedBox(
|
||||
decoration: const BoxDecoration(gradient: PvColors.pageGradient),
|
||||
child: SafeArea(
|
||||
// 左上只是圆形摄像头挖孔,无实质内容,直接占用:
|
||||
// 去掉左右安全区内边距,内容铺满整宽、在物理屏幕正中,不再被挖孔顶出一段空白。
|
||||
left: false,
|
||||
right: false,
|
||||
child: _wrapVideoProvider(
|
||||
BlocBuilder<DeviceStatusBloc, DeviceStatusState>(
|
||||
builder: (context, dsState) {
|
||||
final telemetry = _resolveTelemetry(dsState);
|
||||
return _mode == PvViewMode.manualControl
|
||||
? PvManualControlView(
|
||||
streamUrl: _streamUrl,
|
||||
telemetry: telemetry,
|
||||
onCollapse: _onCollapseManual,
|
||||
onEmergencyStop: _onEmergencyStop,
|
||||
videoSource: _videoSource,
|
||||
videoFit: _videoFit,
|
||||
simReverse: _simReverse,
|
||||
deviceSn: widget.deviceId,
|
||||
onSettings: _openSettings,
|
||||
channel: _channel,
|
||||
)
|
||||
: _buildNormalLayout(telemetry);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNormalLayout(PvTelemetry telemetry) {
|
||||
// ===== 三行高度比例:顶部导航 : 第一行(视频+右列) : 第二行(控制栏) =====
|
||||
// 三行高度比例:顶部导航 : 第一行 : 第二行。Expanded 的 flex 只能是整数,
|
||||
// 这里写成 2 : 14 : 6(即 1 : 7 : 3)。第二行比 2.5 份再多一点,
|
||||
// 好让较大的急停圆钮 + 文字竖着也能放得下,不再底部溢出。想要更矮就把 6 调回 5。
|
||||
const navFlex = 2;
|
||||
const rowFlex = 14;
|
||||
const barFlex = 6;
|
||||
// =================================================================
|
||||
return Column(
|
||||
children: [
|
||||
// ① 顶部导航
|
||||
Expanded(
|
||||
flex: navFlex,
|
||||
child: _PvTopNav(
|
||||
onBack: () => Navigator.of(context).pop(),
|
||||
onSettings: _openSettings,
|
||||
),
|
||||
),
|
||||
// ② 第一行:实时视频 + 右侧列(信息 / 地图)
|
||||
Expanded(
|
||||
flex: rowFlex,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(14, 6, 14, 6),
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
// 右侧列宽度:约占 34%,并限制在 260~460 之间
|
||||
final rightWidth = (constraints.maxWidth * 0.34).clamp(
|
||||
260.0,
|
||||
460.0,
|
||||
);
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// 第一行左:实时视频(可截图)
|
||||
Expanded(
|
||||
child: RepaintBoundary(
|
||||
key: _videoKey,
|
||||
child: PvVideoArea(
|
||||
streamUrl: _streamUrl,
|
||||
telemetry: telemetry,
|
||||
onScreenshot: _onScreenshot,
|
||||
onFullscreen: _onManualControl,
|
||||
videoSource: _videoSource,
|
||||
videoFit: _videoFit,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
// 第一行右:信息列 / 地图(可切换)
|
||||
SizedBox(
|
||||
width: rightWidth,
|
||||
child: _showMap
|
||||
? PvWorkMap(deviceSn: widget.deviceId)
|
||||
: PvInfoColumn(telemetry: telemetry),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
// ③ 第二行:控制栏
|
||||
Expanded(
|
||||
flex: barFlex,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(14, 6, 14, 10),
|
||||
child: PvControlBar(
|
||||
onManualControl: _onManualControl,
|
||||
onPauseTask: _onPauseTask,
|
||||
onEmergencyStop: _onEmergencyStop,
|
||||
onScreenshot: _onScreenshot,
|
||||
onViewMap: _onViewMap,
|
||||
mapActive: _showMap,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 顶部导航栏:左侧返回、中间标题/副标题、右侧设置与更多
|
||||
class _PvTopNav extends StatelessWidget {
|
||||
const _PvTopNav({required this.onBack, required this.onSettings});
|
||||
final VoidCallback onBack;
|
||||
final VoidCallback onSettings;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// 不再固定高度,随 _buildNormalLayout 中 navFlex 分配到的带状高度自动撑满,
|
||||
// Row 默认垂直居中,内容在带内居中显示。
|
||||
return Row(
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: onBack,
|
||||
visualDensity: VisualDensity.compact,
|
||||
padding: EdgeInsets.zero,
|
||||
constraints: const BoxConstraints(minWidth: 32, minHeight: 32),
|
||||
icon: const Icon(
|
||||
Icons.chevron_left,
|
||||
color: PvColors.textPrimary,
|
||||
size: 26,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('pv_control.realtime_video'),
|
||||
style: PvType.navTitle,
|
||||
),
|
||||
Text(
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('pv_control.pv_robot_remote_control'),
|
||||
style: PvType.navSubtitle,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: onSettings,
|
||||
visualDensity: VisualDensity.compact,
|
||||
padding: EdgeInsets.zero,
|
||||
constraints: const BoxConstraints(minWidth: 32, minHeight: 32),
|
||||
icon: const Icon(
|
||||
Icons.settings,
|
||||
color: PvColors.textSecondary,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {},
|
||||
visualDensity: VisualDensity.compact,
|
||||
padding: EdgeInsets.zero,
|
||||
constraints: const BoxConstraints(minWidth: 32, minHeight: 32),
|
||||
icon: const Icon(
|
||||
Icons.more_horiz,
|
||||
color: PvColors.textSecondary,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 截图预览弹窗
|
||||
class _ScreenshotPreviewDialog extends StatelessWidget {
|
||||
const _ScreenshotPreviewDialog({required this.imageBytes, this.path});
|
||||
final Uint8List imageBytes;
|
||||
final String? path;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Dialog(
|
||||
backgroundColor: PvColors.card,
|
||||
insetPadding: const EdgeInsets.all(40),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Expanded(
|
||||
child: InteractiveViewer(
|
||||
child: Image.memory(imageBytes, fit: BoxFit.contain),
|
||||
),
|
||||
),
|
||||
if (path != null) ...[
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('pv_control.screenshot_saved_path').replaceAll(
|
||||
'{path}',
|
||||
path!,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: PvType.label,
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: Text(
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('pv_control.close'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
168
lib/features/pv_control/presentation/theme/pv_colors.dart
Normal file
168
lib/features/pv_control/presentation/theme/pv_colors.dart
Normal file
@@ -0,0 +1,168 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// 光伏电站机器人远程控制横屏页专用配色(深蓝科技风大屏风格)
|
||||
///
|
||||
/// 该页面是独立的横屏大屏可视化界面,视觉风格与常规浅色/深色 [AppColors]
|
||||
/// 完全不同,因此单独维护一套固定配色,不随系统主题切换。
|
||||
/// 颜色取自设计稿:深蓝渐变底 + 青色描边发光 + 语义状态色。
|
||||
class PvColors {
|
||||
PvColors._();
|
||||
|
||||
// ===== 背景 =====
|
||||
/// 页面底色(最深,接近黑蓝)
|
||||
static const Color bgDeepest = Color(0xFF040A16);
|
||||
|
||||
/// 渐变起始(左上)
|
||||
static const Color bgGradientTop = Color(0xFF0A1A30);
|
||||
|
||||
/// 渐变结束(右下)
|
||||
static const Color bgGradientBottom = Color(0xFF050C1A);
|
||||
|
||||
// ===== 卡片 / 面板 =====
|
||||
/// 卡片填充(半透明蓝)
|
||||
static const Color card = Color(0xE6102338);
|
||||
|
||||
/// 卡片内嵌块填充
|
||||
static const Color cardInner = Color(0x331E3A5F);
|
||||
|
||||
/// 卡片描边(青色微光)
|
||||
static const Color cardBorder = Color(0x662FB6E0);
|
||||
|
||||
// ===== 强调 / 主色 =====
|
||||
/// 科技青主色
|
||||
static const Color accent = Color(0xFF22D3EE);
|
||||
|
||||
/// 亮青(图标高亮)
|
||||
static const Color accentBright = Color(0xFF5FEBFF);
|
||||
|
||||
// ===== 文字 =====
|
||||
static const Color textPrimary = Color(0xFFF2F7FC);
|
||||
static const Color textSecondary = Color(0xFF9DB2C9);
|
||||
static const Color textTertiary = Color(0xFF6A819B);
|
||||
|
||||
// ===== 语义状态色 =====
|
||||
/// 危险 / 紧急停止 / 障碍物预警
|
||||
static const Color danger = Color(0xFFFF3B4E);
|
||||
|
||||
/// 在线 / 成功
|
||||
static const Color online = Color(0xFF22E0A0);
|
||||
|
||||
/// 警告
|
||||
static const Color warning = Color(0xFFFFA940);
|
||||
|
||||
/// 信息蓝(速度、温度等仪表)
|
||||
static const Color info = Color(0xFF3FA9FF);
|
||||
|
||||
/// 页面背景渐变
|
||||
static const LinearGradient pageGradient = LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [bgGradientTop, bgGradientBottom],
|
||||
);
|
||||
|
||||
/// 标准卡片装饰:半透明蓝底 + 青色描边 + 圆角
|
||||
static BoxDecoration panel({
|
||||
double radius = 14,
|
||||
Color? fill,
|
||||
Color? border,
|
||||
bool glow = false,
|
||||
}) {
|
||||
return BoxDecoration(
|
||||
color: fill ?? card,
|
||||
borderRadius: BorderRadius.circular(radius),
|
||||
border: Border.all(color: border ?? cardBorder, width: 1),
|
||||
boxShadow: glow
|
||||
? [
|
||||
BoxShadow(
|
||||
color: accent.withValues(alpha: 0.18),
|
||||
blurRadius: 16,
|
||||
spreadRadius: 1,
|
||||
),
|
||||
]
|
||||
: null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 统一排版规范:收敛字号阶梯与行高,避免各组件各写各的导致视觉不和谐。
|
||||
///
|
||||
/// 所有 pv_control 组件的文本都应引用这里的样式,需要变色时用 `copyWith(color: ...)`。
|
||||
class PvType {
|
||||
PvType._();
|
||||
|
||||
/// 统一行高倍数,让多行文本的纵向节奏一致。
|
||||
static const double lh = 1.2;
|
||||
|
||||
/// 顶部导航主标题
|
||||
static const TextStyle navTitle = TextStyle(
|
||||
color: PvColors.textPrimary,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w800,
|
||||
letterSpacing: 1.5,
|
||||
height: lh,
|
||||
);
|
||||
|
||||
/// 顶部导航副标题
|
||||
static const TextStyle navSubtitle = TextStyle(
|
||||
color: PvColors.textSecondary,
|
||||
fontSize: 10,
|
||||
letterSpacing: 1,
|
||||
height: lh,
|
||||
);
|
||||
|
||||
/// 卡片标题(设备名 / 驾驶模式 / 浮层标题)
|
||||
static const TextStyle cardTitle = TextStyle(
|
||||
color: PvColors.textPrimary,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w700,
|
||||
height: lh,
|
||||
);
|
||||
|
||||
/// 仪表数值(速度 / 里程 / 温度)
|
||||
static const TextStyle metricValue = TextStyle(
|
||||
color: PvColors.textPrimary,
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w800,
|
||||
height: lh,
|
||||
);
|
||||
|
||||
/// 文本型数值(网络“正常”等短词)
|
||||
static const TextStyle metricText = TextStyle(
|
||||
color: PvColors.textPrimary,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w800,
|
||||
height: lh,
|
||||
);
|
||||
|
||||
/// 正文
|
||||
static const TextStyle body = TextStyle(
|
||||
color: PvColors.textPrimary,
|
||||
fontSize: 12,
|
||||
height: lh,
|
||||
);
|
||||
|
||||
/// 次要标签 / 说明
|
||||
static const TextStyle label = TextStyle(
|
||||
color: PvColors.textSecondary,
|
||||
fontSize: 11,
|
||||
height: lh,
|
||||
);
|
||||
|
||||
/// 更小的辅助文字(单位 / 角标 / 徽标)
|
||||
static const TextStyle caption = TextStyle(
|
||||
color: PvColors.textSecondary,
|
||||
fontSize: 10,
|
||||
height: lh,
|
||||
);
|
||||
}
|
||||
|
||||
/// 统一间距刻度,供各组件纵向 / 横向留白引用,保证节奏和谐。
|
||||
class PvGap {
|
||||
PvGap._();
|
||||
|
||||
static const double xs = 4;
|
||||
static const double sm = 6;
|
||||
static const double md = 8;
|
||||
static const double lg = 10;
|
||||
static const double xl = 14;
|
||||
}
|
||||
254
lib/features/pv_control/presentation/widgets/pv_control_bar.dart
Normal file
254
lib/features/pv_control/presentation/widgets/pv_control_bar.dart
Normal file
@@ -0,0 +1,254 @@
|
||||
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,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
372
lib/features/pv_control/presentation/widgets/pv_info_column.dart
Normal file
372
lib/features/pv_control/presentation/widgets/pv_info_column.dart
Normal file
@@ -0,0 +1,372 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
|
||||
import '../models/pv_telemetry.dart';
|
||||
import '../theme/pv_colors.dart';
|
||||
|
||||
/// 第一行右侧信息列:设备概览 / 驾驶模式 / 速度·里程 / 网络·温度。
|
||||
class PvInfoColumn extends StatelessWidget {
|
||||
const PvInfoColumn({
|
||||
super.key,
|
||||
required this.telemetry,
|
||||
this.onSwitchMode,
|
||||
});
|
||||
|
||||
final PvTelemetry telemetry;
|
||||
final VoidCallback? onSwitchMode;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// 收窄上下间距 + 卡片内边距,尽量让全部内容在一屏内可见(不触发滚动);
|
||||
// 仍保留 SingleChildScrollView 作为极小屏的安全兜底。
|
||||
return SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
_RobotHeader(telemetry: telemetry),
|
||||
const SizedBox(height: 6),
|
||||
_DriveModeCard(
|
||||
telemetry: telemetry,
|
||||
onSwitchMode: onSwitchMode,
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(child: _MetricCard.icon(
|
||||
icon: Icons.speed,
|
||||
color: PvColors.info,
|
||||
label: AppLocalizations.of(
|
||||
context,
|
||||
).translate('pv_control.current_speed'),
|
||||
value: telemetry.speed.toStringAsFixed(1),
|
||||
unit: 'm/s',
|
||||
)),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(child: _MetricCard.icon(
|
||||
icon: Icons.timeline,
|
||||
color: PvColors.accent,
|
||||
label: AppLocalizations.of(
|
||||
context,
|
||||
).translate('pv_control.patrol_mileage'),
|
||||
value: telemetry.mileage == null
|
||||
? AppLocalizations.of(context).translate(
|
||||
'pv_control.unknown',
|
||||
)
|
||||
: telemetry.mileage!.toStringAsFixed(1),
|
||||
unit: telemetry.mileage == null ? '' : 'km',
|
||||
)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(child: _MetricCard.icon(
|
||||
icon: Icons.signal_cellular_alt,
|
||||
color: PvColors.online,
|
||||
label: AppLocalizations.of(
|
||||
context,
|
||||
).translate('pv_control.network_status'),
|
||||
value: telemetry.networkNormal
|
||||
? AppLocalizations.of(context).translate(
|
||||
'pv_control.status_normal',
|
||||
)
|
||||
: AppLocalizations.of(context).translate(
|
||||
'pv_control.status_abnormal',
|
||||
),
|
||||
unit: '',
|
||||
valueIsText: true,
|
||||
)),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(child: _MetricCard.icon(
|
||||
icon: Icons.thermostat,
|
||||
color: PvColors.info,
|
||||
label: AppLocalizations.of(
|
||||
context,
|
||||
).translate('pv_control.device_temperature'),
|
||||
value: telemetry.temperature == null
|
||||
? AppLocalizations.of(context).translate(
|
||||
'pv_control.unknown',
|
||||
)
|
||||
: telemetry.temperature!.toStringAsFixed(1),
|
||||
unit: telemetry.temperature == null ? '' : '℃',
|
||||
)),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _RobotHeader extends StatelessWidget {
|
||||
const _RobotHeader({required this.telemetry});
|
||||
final PvTelemetry telemetry;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
decoration: PvColors.panel(),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: PvColors.cardInner,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.smart_toy_outlined,
|
||||
color: PvColors.accentBright,
|
||||
size: 22,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Flexible(
|
||||
child: Text(
|
||||
telemetry.deviceName,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
color: PvColors.textPrimary,
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
_OnlineBadge(isOnline: telemetry.isOnline),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
'SN:${telemetry.serialNumber}',
|
||||
style: const TextStyle(
|
||||
color: PvColors.textSecondary,
|
||||
fontSize: 10,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Icon(
|
||||
Icons.battery_std,
|
||||
size: 12,
|
||||
color: telemetry.battery == null
|
||||
? PvColors.textTertiary
|
||||
: (telemetry.battery! > 20
|
||||
? PvColors.online
|
||||
: PvColors.danger),
|
||||
),
|
||||
Text(
|
||||
telemetry.battery == null
|
||||
? AppLocalizations.of(context).translate(
|
||||
'pv_control.battery_unknown',
|
||||
)
|
||||
: AppLocalizations.of(context).translate(
|
||||
'pv_control.battery_percent',
|
||||
).replaceAll(
|
||||
'{n}',
|
||||
telemetry.battery!.toStringAsFixed(0),
|
||||
),
|
||||
style: const TextStyle(
|
||||
color: PvColors.textSecondary,
|
||||
fontSize: 10,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _OnlineBadge extends StatelessWidget {
|
||||
const _OnlineBadge({required this.isOnline});
|
||||
final bool isOnline;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final color = isOnline ? PvColors.online : PvColors.textTertiary;
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 1),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withValues(alpha: 0.15),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
border: Border.all(color: color.withValues(alpha: 0.6)),
|
||||
),
|
||||
child: Text(
|
||||
isOnline
|
||||
? AppLocalizations.of(context).translate('pv_control.online')
|
||||
: AppLocalizations.of(context).translate('pv_control.offline'),
|
||||
style: TextStyle(color: color, fontSize: 10, fontWeight: FontWeight.w700),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _DriveModeCard extends StatelessWidget {
|
||||
const _DriveModeCard({required this.telemetry, this.onSwitchMode});
|
||||
final PvTelemetry telemetry;
|
||||
final VoidCallback? onSwitchMode;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
decoration: PvColors.panel(),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.local_shipping_outlined,
|
||||
color: PvColors.accent,
|
||||
size: 22,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
telemetry.isAutoDriving
|
||||
? AppLocalizations.of(context).translate(
|
||||
'pv_control.auto_driving',
|
||||
)
|
||||
: AppLocalizations.of(context).translate(
|
||||
'pv_control.manual_controlling',
|
||||
),
|
||||
style: const TextStyle(
|
||||
color: PvColors.textPrimary,
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 1),
|
||||
Text(
|
||||
telemetry.taskStatus,
|
||||
style: const TextStyle(
|
||||
color: PvColors.textSecondary,
|
||||
fontSize: 10,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: onSwitchMode,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
||||
decoration: BoxDecoration(
|
||||
color: PvColors.cardInner,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: PvColors.cardBorder),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
AppLocalizations.of(context).translate(
|
||||
'pv_control.switch_mode',
|
||||
),
|
||||
style: TextStyle(
|
||||
color: PvColors.textPrimary,
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
SizedBox(width: 4),
|
||||
Icon(Icons.swap_horiz, size: 14, color: PvColors.accent),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _MetricCard extends StatelessWidget {
|
||||
const _MetricCard.icon({
|
||||
required this.icon,
|
||||
required this.color,
|
||||
required this.label,
|
||||
required this.value,
|
||||
required this.unit,
|
||||
this.valueIsText = false,
|
||||
});
|
||||
|
||||
final IconData icon;
|
||||
final Color color;
|
||||
final String label;
|
||||
final String value;
|
||||
final String unit;
|
||||
final bool valueIsText;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 5),
|
||||
decoration: PvColors.panel(),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(icon, color: color, size: 18),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
color: PvColors.textSecondary,
|
||||
fontSize: 10,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 1),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.baseline,
|
||||
textBaseline: TextBaseline.alphabetic,
|
||||
children: [
|
||||
Flexible(
|
||||
child: Text(
|
||||
value,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
color: PvColors.textPrimary,
|
||||
fontSize: valueIsText ? 12 : 14,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (unit.isNotEmpty) ...[
|
||||
const SizedBox(width: 3),
|
||||
Text(
|
||||
unit,
|
||||
style: const TextStyle(
|
||||
color: PvColors.textSecondary,
|
||||
fontSize: 10,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:video_player/video_player.dart';
|
||||
|
||||
import 'package:maibu_satabot_v2/features/v2/local_camera/presentation/cubit/local_camera_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/local_camera/presentation/cubit/local_camera_state.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
|
||||
import '../theme/pv_colors.dart';
|
||||
|
||||
/// 本地视频(以太网直连摄像头 RTSP / ExoPlayer)视图。
|
||||
///
|
||||
/// 实验用视频源:复用 [LocalCameraCubit] 的完整链路(网络检查 → ONVIF 发现 →
|
||||
/// 取 RTSP 地址 → video_player 拉流),cubit 需以 `autoPlayFirst + autoRecover`
|
||||
/// 创建 —— 全程**自动获取**,画面出来前只显示一行简短状态,链条步骤不展示;
|
||||
/// 卡顿(缓冲进度 0% 超时)/断流由 cubit 自动重拉流恢复。
|
||||
/// 上层必须已挂好 `BlocProvider<LocalCameraCubit>`(pv_control_page 负责)。
|
||||
class PvLocalRtspVideo extends StatelessWidget {
|
||||
const PvLocalRtspVideo({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<LocalCameraCubit, LocalCameraState>(
|
||||
builder: (context, state) {
|
||||
final controller = context.read<LocalCameraCubit>().videoController;
|
||||
Widget layer;
|
||||
if (controller != null && controller.value.isInitialized) {
|
||||
// 部分摄像头 SDP 不带分辨率,size 为 0×0 时 aspectRatio 会崩成
|
||||
// 纯黑(与本地视频页同款兜底):回退 16:9。
|
||||
final size = controller.value.size;
|
||||
final ratio = size.width > 0 && size.height > 0
|
||||
? size.width / size.height
|
||||
: 16 / 9;
|
||||
layer = Center(
|
||||
child: AspectRatio(
|
||||
aspectRatio: ratio,
|
||||
child: VideoPlayer(controller),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
layer = const ColoredBox(color: Colors.black);
|
||||
}
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
layer,
|
||||
// 非播放态统一盖一层简短状态(不展示链条步骤)
|
||||
if (state.phase != LocalCameraPhase.playing)
|
||||
Positioned.fill(child: _statusLayer(context, state)),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _statusLayer(BuildContext context, LocalCameraState state) {
|
||||
final tr = AppLocalizations.of(context);
|
||||
String text;
|
||||
var busy = true;
|
||||
switch (state.phase) {
|
||||
case LocalCameraPhase.idle:
|
||||
case LocalCameraPhase.searching:
|
||||
text = tr.translate('pv_control.rtsp_searching');
|
||||
break;
|
||||
case LocalCameraPhase.found:
|
||||
case LocalCameraPhase.connecting:
|
||||
text = tr.translate('pv_control.rtsp_connecting');
|
||||
break;
|
||||
case LocalCameraPhase.disconnected:
|
||||
text = tr.translate('pv_control.rtsp_reconnecting');
|
||||
break;
|
||||
case LocalCameraPhase.notFound:
|
||||
text = tr.translate('pv_control.rtsp_not_found');
|
||||
break;
|
||||
case LocalCameraPhase.playFailed:
|
||||
text = tr.translate('pv_control.rtsp_failed');
|
||||
break;
|
||||
case LocalCameraPhase.noNetwork:
|
||||
text = tr.translate('pv_control.rtsp_no_ethernet');
|
||||
busy = false;
|
||||
break;
|
||||
case LocalCameraPhase.playing:
|
||||
text = '';
|
||||
break;
|
||||
}
|
||||
return Container(
|
||||
color: Colors.black.withValues(alpha: busy ? 0.55 : 0.85),
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (busy)
|
||||
const SizedBox(
|
||||
width: 26,
|
||||
height: 26,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2.4,
|
||||
color: PvColors.accentBright,
|
||||
),
|
||||
)
|
||||
else
|
||||
const Icon(Icons.info_outline,
|
||||
color: Colors.white38, size: 26),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
text,
|
||||
style: const TextStyle(color: Colors.white70, fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,114 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:maibu_satabot_v2/features/remote_control/presentation/widgets/webrtc/webrtc_local_player.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
|
||||
import '../theme/pv_colors.dart';
|
||||
|
||||
/// 可复用的「倒车影像 / 后视图」卡片组件。
|
||||
///
|
||||
/// 从遥控 HUD 左栏抽出,纯展示 + 插槽设计,方便多处复用:
|
||||
/// - [streamUrl] 非空时用 [WebRTCLocalPlayer] 播放视频流,空时显示占位图标
|
||||
/// (当前阶段为模块还原,接嵌入式后视流后直接传 url 即可,无需改组件);
|
||||
/// - [overlay] 可叠加任意覆盖层(例如将来把 remote_control 的
|
||||
/// ReverseGuideOverlay 倒车引导线传进来叠在画面上),组件不感知其实现;
|
||||
/// - [scale] 沿用遥控 HUD 的 _sc 缩放体系,手机横屏 / 平板等比自适应;
|
||||
/// - [onExpand] 右上角全屏按钮回调,null 时默认打印占位日志。
|
||||
class PvRearViewCard extends StatelessWidget {
|
||||
const PvRearViewCard({
|
||||
super.key,
|
||||
this.title,
|
||||
this.streamUrl = '',
|
||||
this.scale = 1,
|
||||
this.videoHeight,
|
||||
this.overlay,
|
||||
this.onExpand,
|
||||
});
|
||||
|
||||
/// 卡片标题;为空时根据当前语言回退为「后视图」。
|
||||
final String? title;
|
||||
|
||||
/// 视频流地址;为空时显示无信号占位。
|
||||
final String streamUrl;
|
||||
|
||||
/// 缩放系数(HUD 传入 _sc;独立使用时保持默认 1 即为设计像素)。
|
||||
final double scale;
|
||||
|
||||
/// 画面区高度,默认 70 设计像素 × [scale]。
|
||||
final double? videoHeight;
|
||||
|
||||
/// 叠在画面之上的覆盖层(如倒车引导线动画),不拦截手势。
|
||||
final Widget? overlay;
|
||||
|
||||
/// 右上角全屏按钮回调。
|
||||
final VoidCallback? onExpand;
|
||||
|
||||
double _d(num v) => v * scale;
|
||||
|
||||
TextStyle _s(TextStyle base, double size) => base.copyWith(fontSize: _d(size));
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(_d(6)),
|
||||
decoration: PvColors.panel(radius: _d(12)),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title ??
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('pv_control.rear_view'),
|
||||
style: _s(PvType.label, 12),
|
||||
),
|
||||
SizedBox(height: _d(4)),
|
||||
SizedBox(
|
||||
height: videoHeight ?? _d(70),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(_d(8)),
|
||||
child: Container(
|
||||
color: Colors.black54,
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
// 画面:有流播流,无流占位
|
||||
if (streamUrl.isNotEmpty)
|
||||
WebRTCLocalPlayer(
|
||||
streamUrl: streamUrl,
|
||||
showLeftPip: false,
|
||||
showRightPip: false,
|
||||
mainViewAlignment: Alignment.center,
|
||||
)
|
||||
else
|
||||
const Center(
|
||||
child: Icon(Icons.no_photography,
|
||||
color: Colors.white24, size: 26),
|
||||
),
|
||||
// 覆盖层插槽(倒车引导线等),不吃手势
|
||||
if (overlay != null)
|
||||
Positioned.fill(child: IgnorePointer(child: overlay!)),
|
||||
// 全屏按钮
|
||||
Positioned(
|
||||
right: _d(4),
|
||||
top: _d(4),
|
||||
child: GestureDetector(
|
||||
onTap: onExpand ?? () => debugPrint('[PV遥控] 后视图放大'),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(_d(2)),
|
||||
child: Icon(Icons.fullscreen,
|
||||
color: PvColors.textSecondary, size: _d(16)),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
231
lib/features/pv_control/presentation/widgets/pv_task_dialog.dart
Normal file
231
lib/features/pv_control/presentation/widgets/pv_task_dialog.dart
Normal file
@@ -0,0 +1,231 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import 'package:maibu_satabot_v2/core/di/injection.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/entities/device_task_entity.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/presentation/bloc/device_task_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/presentation/bloc/device_task_state.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
|
||||
import '../theme/pv_colors.dart';
|
||||
|
||||
/// 「当前任务」弹窗:展示路径规划模块正在执行的任务。
|
||||
///
|
||||
/// 入口为遥控 HUD 顶栏右上第一项「任务」。数据源与路径规划作业面板同源——
|
||||
/// 全局单例 [DeviceTaskCubit] 的 currentTask(用 BlocBuilder 实时订阅,
|
||||
/// 任务状态变化自动刷新);接口没给的字段统一显示「无」。
|
||||
class PvTaskDialog {
|
||||
const PvTaskDialog._();
|
||||
|
||||
static Future<void> show(BuildContext context) {
|
||||
return showDialog<void>(
|
||||
context: context,
|
||||
builder: (_) => BlocProvider.value(
|
||||
// 共享全局实例:弹窗只订阅状态,不负责 cubit 生命周期
|
||||
value: sl<DeviceTaskCubit>(),
|
||||
child: const _PvTaskDialogContent(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _PvTaskDialogContent extends StatelessWidget {
|
||||
const _PvTaskDialogContent();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<DeviceTaskCubit, DeviceTaskState>(
|
||||
builder: (context, state) {
|
||||
final task = state.currentTask;
|
||||
return Dialog(
|
||||
backgroundColor: Colors.transparent,
|
||||
insetPadding: const EdgeInsets.symmetric(horizontal: 60),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 12, 14),
|
||||
decoration: PvColors.panel(radius: 14),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 标题行 + 关闭
|
||||
Row(
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.assignment_outlined,
|
||||
color: PvColors.accentBright,
|
||||
size: 20,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('pv_control.task_current'),
|
||||
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(),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (task == null)
|
||||
const _EmptyTask()
|
||||
else
|
||||
_TaskFields(task: task),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 无执行任务:路径规划侧 currentTask 为空(未下发/已完成/被清除)。
|
||||
class _EmptyTask extends StatelessWidget {
|
||||
const _EmptyTask();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 18),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.info_outline,
|
||||
color: PvColors.textTertiary,
|
||||
size: 18,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('pv_control.task_none_running'),
|
||||
style: PvType.body,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 任务数据项:与路径规划作业面板展示的字段对齐
|
||||
/// (任务编号 / 设备 / 状态,另补路线、地块、创建时间),空字段显示「无」。
|
||||
class _TaskFields extends StatelessWidget {
|
||||
const _TaskFields({required this.task});
|
||||
|
||||
final DeviceTaskEntity task;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final tr = AppLocalizations.of(context);
|
||||
final (statusColor, statusText) = _statusOf(context, task);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_row(context, tr.translate('pv_control.task_field_no'), '#${task.id}'),
|
||||
_row(
|
||||
context,
|
||||
tr.translate('pv_control.task_field_device'),
|
||||
task.deviceId,
|
||||
),
|
||||
_row(
|
||||
context,
|
||||
tr.translate('pv_control.task_field_status'),
|
||||
statusText,
|
||||
valueColor: statusColor,
|
||||
),
|
||||
_row(
|
||||
context,
|
||||
tr.translate('pv_control.task_field_route'),
|
||||
task.routeId?.toString(),
|
||||
),
|
||||
_row(
|
||||
context,
|
||||
tr.translate('pv_control.task_field_site'),
|
||||
task.siteId?.toString(),
|
||||
),
|
||||
_row(
|
||||
context,
|
||||
tr.translate('pv_control.task_field_create_time'),
|
||||
task.createTime,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 状态映射与路径规划页一致:NEW 蓝 / EXECUTING 绿 / PAUSE 橙,
|
||||
/// 其余用接口给的翻译文案;颜色换成本模块语义色保持风格统一。
|
||||
(Color, String) _statusOf(BuildContext context, DeviceTaskEntity t) {
|
||||
final tr = AppLocalizations.of(context);
|
||||
final translate = t.taskStatusTranslate.isNotEmpty
|
||||
? t.taskStatusTranslate
|
||||
: t.taskStatus;
|
||||
switch (t.taskStatus) {
|
||||
case 'NEW':
|
||||
return (
|
||||
PvColors.info,
|
||||
translate.isEmpty
|
||||
? tr.translate('pv_control.task_none_value')
|
||||
: tr.translate('pv_control.task_new'),
|
||||
);
|
||||
case 'EXECUTING':
|
||||
return (PvColors.online, tr.translate('pv_control.task_executing'));
|
||||
case 'PAUSE':
|
||||
return (PvColors.warning, tr.translate('pv_control.task_paused'));
|
||||
default:
|
||||
return (
|
||||
PvColors.textSecondary,
|
||||
translate.isEmpty
|
||||
? tr.translate('pv_control.task_none_value')
|
||||
: translate,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Widget _row(
|
||||
BuildContext context,
|
||||
String label,
|
||||
String? value, {
|
||||
Color? valueColor,
|
||||
}) {
|
||||
final text = (value == null || value.isEmpty)
|
||||
? AppLocalizations.of(context).translate('pv_control.task_none_value')
|
||||
: value;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 5),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 76,
|
||||
child: Text(label, style: PvType.label),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
text,
|
||||
style: PvType.body.copyWith(
|
||||
color: valueColor ?? PvColors.textPrimary,
|
||||
fontWeight: valueColor != null
|
||||
? FontWeight.w700
|
||||
: FontWeight.w400,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import 'package:maibu_satabot_v2/features/v2/usb_camera/presentation/cubit/usb_camera_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/usb_camera/presentation/cubit/usb_camera_state.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/usb_camera/presentation/widgets/usb_camera_preview.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/usb_camera/presentation/widgets/usb_camera_status_layer.dart';
|
||||
|
||||
/// USB 摄像头(UVC)链路的视频视图。
|
||||
///
|
||||
/// 复用 usb_camera 模块现成的预览组件与状态层(扫描中 / 多设备选择 /
|
||||
/// 授权失败可重试),行为与「USB 摄像头」独立页一致。
|
||||
///
|
||||
/// 前置条件:上层已挂好 `BlocProvider<UsbCameraCubit>`(由 pv_control_page
|
||||
/// 负责)—— cubit 必须是页面级**单实例**,普通态与全屏 HUD 共用:
|
||||
/// UVC 是独占硬件会话,两处各建一个 cubit 会互相抢占设备。
|
||||
class PvUsbCameraVideo extends StatelessWidget {
|
||||
const PvUsbCameraVideo({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<UsbCameraCubit, UsbCameraState>(
|
||||
builder: (context, state) {
|
||||
final cubit = context.read<UsbCameraCubit>();
|
||||
if (state.showPreview && state.selected != null) {
|
||||
return UsbCameraPreview(
|
||||
device: state.selected!,
|
||||
phase: state.phase,
|
||||
onReconnect: cubit.reconnect,
|
||||
aspectRatio: state.previewAspectRatio,
|
||||
);
|
||||
}
|
||||
return UsbCameraStatusLayer(state: state, cubit: cubit);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
392
lib/features/pv_control/presentation/widgets/pv_video_area.dart
Normal file
392
lib/features/pv_control/presentation/widgets/pv_video_area.dart
Normal file
@@ -0,0 +1,392 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:maibu_satabot_v2/features/remote_control/presentation/widgets/webrtc/webrtc_local_player.dart';
|
||||
|
||||
import '../models/pv_telemetry.dart';
|
||||
import '../models/pv_video_fit.dart';
|
||||
import '../models/pv_video_source.dart';
|
||||
import '../theme/pv_colors.dart';
|
||||
import 'pv_local_rtsp_video.dart';
|
||||
import 'pv_usb_camera_video.dart';
|
||||
import 'pv_video_fit_box.dart';
|
||||
|
||||
/// 实时视频区:底层播放 WebRTC 流,上层叠加设计稿中的信息浮层。
|
||||
///
|
||||
/// 浮层(左上分辨率、顶部障碍预警、右上网络状态、右侧工具按钮、左下罗盘)
|
||||
/// 目前为静态样式还原,障碍物测距等 AR 数据需真实算法接入后驱动。
|
||||
class PvVideoArea extends StatelessWidget {
|
||||
const PvVideoArea({
|
||||
super.key,
|
||||
required this.streamUrl,
|
||||
required this.telemetry,
|
||||
this.onFullscreen,
|
||||
this.onLocate,
|
||||
this.onScreenshot,
|
||||
this.showSideTools = true,
|
||||
this.showCompass = true,
|
||||
this.videoSource = PvVideoSource.webrtc,
|
||||
this.videoFit = PvVideoFit.contain,
|
||||
});
|
||||
|
||||
final String streamUrl;
|
||||
final PvTelemetry telemetry;
|
||||
final VoidCallback? onFullscreen;
|
||||
final VoidCallback? onLocate;
|
||||
final VoidCallback? onScreenshot;
|
||||
|
||||
/// 手动控制全屏态可隐藏右侧工具按钮,避免与摇杆冲突
|
||||
final bool showSideTools;
|
||||
|
||||
/// 隐藏左下罗盘(手动控制全屏态下摇杆占据下角,避免与罗盘重叠)
|
||||
final bool showCompass;
|
||||
|
||||
/// 视频链路(多源可扩展):webrtc=云端流 / localRtsp=以太网 RTSP / usbCamera=USB 采集卡。
|
||||
/// cubit 由页面层按链路单实例提供(pv_control_page._wrapVideoProvider)。
|
||||
final PvVideoSource videoSource;
|
||||
|
||||
/// 视频展示方式(设置面板可改):contain 完整显示(可能留黑边)/ cover 等比铺满(裁边)。
|
||||
final PvVideoFit videoFit;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
clipBehavior: Clip.antiAlias,
|
||||
decoration: PvColors.panel(radius: 16, fill: Colors.black, glow: true),
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
// ① 视频层:按链路枚举分发,再按「视频展示」档位做 contain / cover 适配
|
||||
PvVideoFitBox(
|
||||
fit: videoFit,
|
||||
source: videoSource,
|
||||
child: _buildLayer(),
|
||||
),
|
||||
|
||||
// ② 顶部左侧:实时视频 + 分辨率/帧率
|
||||
Positioned(left: 14, top: 12, child: _buildTopLeftBadge()),
|
||||
|
||||
// ③ 顶部中间:障碍物预警
|
||||
if (telemetry.obstacleAlert)
|
||||
Positioned(left: 0, right: 0, top: 10, child: _buildObstacleBanner()),
|
||||
|
||||
// ④ 顶部右侧:网络状态
|
||||
Positioned(right: 14, top: 12, child: _buildNetworkBadge()),
|
||||
|
||||
// ⑤ 右侧工具按钮列
|
||||
if (showSideTools)
|
||||
Positioned(right: 12, top: 54, child: _buildSideTools()),
|
||||
|
||||
// ⑥ 左下罗盘
|
||||
if (showCompass) Positioned(left: 14, bottom: 14, child: _buildCompass()),
|
||||
|
||||
// ⑦ 圆角描边覆盖层:视频画面会把 Container 边框盖住,
|
||||
// 这里在最上层单独画一圈青色圆角边框,保证四角圆角 + 边框始终可见。
|
||||
Positioned.fill(
|
||||
child: IgnorePointer(
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: PvColors.cardBorder, width: 1.5),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 各链路的原始视频层(组件内部自己等比居中)。
|
||||
Widget _buildLayer() {
|
||||
if (videoSource == PvVideoSource.usbCamera) return const PvUsbCameraVideo();
|
||||
if (videoSource == PvVideoSource.localRtsp) return const PvLocalRtspVideo();
|
||||
if (streamUrl.isNotEmpty) {
|
||||
return WebRTCLocalPlayer(
|
||||
streamUrl: streamUrl,
|
||||
showLeftPip: false,
|
||||
showRightPip: false,
|
||||
mainViewAlignment: Alignment.center,
|
||||
);
|
||||
}
|
||||
return _VideoPlaceholder();
|
||||
}
|
||||
|
||||
Widget _buildTopLeftBadge() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.circle, size: 8, color: PvColors.danger),
|
||||
const SizedBox(width: 5),
|
||||
const Text(
|
||||
'实时视频',
|
||||
style: TextStyle(
|
||||
color: PvColors.textPrimary,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w700,
|
||||
shadows: [Shadow(blurRadius: 6, color: Colors.black)],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
'${telemetry.resolution} | ${telemetry.fps}fps',
|
||||
style: const TextStyle(
|
||||
color: PvColors.textSecondary,
|
||||
fontSize: 9,
|
||||
shadows: [Shadow(blurRadius: 4, color: Colors.black)],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildObstacleBanner() => const _ObstacleBannerPill();
|
||||
|
||||
Widget _buildNetworkBadge() {
|
||||
final ok = telemetry.networkNormal;
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withValues(alpha: 0.35),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(
|
||||
color: (ok ? PvColors.online : PvColors.warning).withValues(alpha: 0.6),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.wifi, size: 14, color: ok ? PvColors.online : PvColors.warning),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
ok ? '网络良好' : '网络异常',
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: ok ? PvColors.online : PvColors.warning,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSideTools() {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_ToolButton(icon: Icons.fullscreen, onTap: onFullscreen),
|
||||
const SizedBox(height: 10),
|
||||
_ToolButton(icon: Icons.person_search, onTap: onLocate),
|
||||
const SizedBox(height: 10),
|
||||
_ToolButton(icon: Icons.photo_camera, onTap: onScreenshot),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCompass() {
|
||||
return SizedBox(
|
||||
width: 80,
|
||||
height: 80,
|
||||
child: CustomPaint(painter: _CompassPainter()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _VideoPlaceholder extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
color: Colors.black87,
|
||||
child: const Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.videocam_off, size: 48, color: Colors.white38),
|
||||
SizedBox(height: 8),
|
||||
Text('视频未加载', style: TextStyle(color: Colors.white54, fontSize: 12)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 障碍物预警横幅:脉动动画(透明度 + 轻微缩放 + 红色辉光呼吸)以引起注意。
|
||||
class _ObstacleBannerPill extends StatefulWidget {
|
||||
const _ObstacleBannerPill();
|
||||
|
||||
@override
|
||||
State<_ObstacleBannerPill> createState() => _ObstacleBannerPillState();
|
||||
}
|
||||
|
||||
class _ObstacleBannerPillState extends State<_ObstacleBannerPill>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final AnimationController _controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 750),
|
||||
)..repeat(reverse: true);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnimatedBuilder(
|
||||
animation: _controller,
|
||||
builder: (context, child) {
|
||||
final t = _controller.value; // 0..1 来回
|
||||
return Center(
|
||||
child: Opacity(
|
||||
opacity: 0.72 + 0.28 * t,
|
||||
child: Transform.scale(
|
||||
scale: 1.0 + 0.07 * t,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 7),
|
||||
decoration: BoxDecoration(
|
||||
gradient: const LinearGradient(
|
||||
colors: [Color(0xFFE01E32), Color(0xFFFF5A4D)],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: PvColors.danger.withValues(alpha: 0.3 + 0.4 * t),
|
||||
blurRadius: 12 + 16 * t,
|
||||
spreadRadius: 1 + 2 * t,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const _Chevron(left: true),
|
||||
const SizedBox(width: 7),
|
||||
const Icon(Icons.warning_rounded, color: Colors.white, size: 16),
|
||||
const SizedBox(width: 5),
|
||||
const Text(
|
||||
'障碍物预警',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w800,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 7),
|
||||
const _Chevron(left: false),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Chevron extends StatelessWidget {
|
||||
const _Chevron({required this.left});
|
||||
final bool left;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Icon(
|
||||
left ? Icons.chevron_left : Icons.chevron_right,
|
||||
color: Colors.white70,
|
||||
size: 18,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ToolButton extends StatelessWidget {
|
||||
const _ToolButton({required this.icon, this.onTap});
|
||||
final IconData icon;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withValues(alpha: 0.45),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(color: PvColors.cardBorder),
|
||||
),
|
||||
child: Icon(icon, color: PvColors.textPrimary, size: 18),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 简易罗盘(N/E/S/W + 中心车辆图标 + 指向扇形)
|
||||
class _CompassPainter extends CustomPainter {
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final center = Offset(size.width / 2, size.height / 2);
|
||||
final r = size.width / 2;
|
||||
|
||||
// 外圈
|
||||
final ring = Paint()
|
||||
..color = PvColors.accent.withValues(alpha: 0.7)
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 1.5;
|
||||
canvas.drawCircle(center, r - 1, ring);
|
||||
|
||||
// 指向扇形(北方向红色)
|
||||
final sector = Paint()
|
||||
..color = PvColors.danger.withValues(alpha: 0.55)
|
||||
..style = PaintingStyle.fill;
|
||||
canvas.drawArc(
|
||||
Rect.fromCircle(center: center, radius: r - 2),
|
||||
-math.pi / 2 - 0.5,
|
||||
1.0,
|
||||
true,
|
||||
sector,
|
||||
);
|
||||
|
||||
const labels = {
|
||||
'N': -math.pi / 2,
|
||||
'E': 0.0,
|
||||
'S': math.pi / 2,
|
||||
'W': math.pi,
|
||||
};
|
||||
for (final e in labels.entries) {
|
||||
final p = Offset(
|
||||
center.dx + math.cos(e.value) * (r - 12),
|
||||
center.dy + math.sin(e.value) * (r - 12),
|
||||
);
|
||||
final tp = TextPainter(
|
||||
text: TextSpan(
|
||||
text: e.key,
|
||||
style: const TextStyle(color: PvColors.textPrimary, fontSize: 11, fontWeight: FontWeight.bold),
|
||||
),
|
||||
textDirection: TextDirection.ltr,
|
||||
)..layout();
|
||||
tp.paint(canvas, p - Offset(tp.width / 2, tp.height / 2));
|
||||
}
|
||||
|
||||
// 中心车辆图标(用简单圆点代替)
|
||||
final dot = Paint()..color = PvColors.accentBright;
|
||||
canvas.drawCircle(center, 4, dot);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import 'package:maibu_satabot_v2/features/v2/local_camera/presentation/cubit/local_camera_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/usb_camera/presentation/cubit/usb_camera_cubit.dart';
|
||||
|
||||
import '../models/pv_video_fit.dart';
|
||||
import '../models/pv_video_source.dart';
|
||||
|
||||
/// 当前视频链路实际画面的宽高比(拿不到尺寸时回退 16:9)。
|
||||
///
|
||||
/// 这里用 [BuildContext.watch]:流刚拉起时比例往往是空 / 0,真实分辨率到达后
|
||||
/// 调用方会重建,裁切尺寸随之重算,不会一直停在 16:9 的兜底值上
|
||||
/// (BlocProvider 在每次状态发射时都会通知 watch 的依赖方)。
|
||||
/// (USB / RTSP 的 cubit 必须已由页面层挂好。)
|
||||
double pvFrameRatioOf(BuildContext context, PvVideoSource source) {
|
||||
switch (source) {
|
||||
case PvVideoSource.usbCamera:
|
||||
final r = context
|
||||
.watch<UsbCameraCubit>()
|
||||
.state
|
||||
.previewAspectRatio ??
|
||||
0.0;
|
||||
return r > 0 ? r : 16 / 9;
|
||||
case PvVideoSource.localRtsp:
|
||||
// 画面尺寸在 controller 里、不在 state 里:watch 一次,出图后重新取值
|
||||
context.watch<LocalCameraCubit>();
|
||||
final c = context.read<LocalCameraCubit>().videoController;
|
||||
final r =
|
||||
(c != null && c.value.isInitialized) ? c.value.aspectRatio : 0.0;
|
||||
return r > 0 ? r : 16 / 9;
|
||||
case PvVideoSource.webrtc:
|
||||
// WebRTC 侧未对外暴露 renderer 尺寸,沿用播放器内部的 16:9 主视口。
|
||||
return 16 / 9;
|
||||
}
|
||||
}
|
||||
|
||||
/// 按 [PvVideoFit] 把视频层铺进展示区域。
|
||||
///
|
||||
/// 各链路的视频组件内部都是「等比 + 居中」(contain):窗口比例和画面比例不一致时
|
||||
/// 会留黑边。这里不改那些组件(USB / 本地视频是独立模块,尽量零侵入),
|
||||
/// 而是给它套一个**比例正好等于画面比例**的盒子:
|
||||
/// - [PvVideoFit.contain]:原样返回,窗口多大就在中间显示多大(留黑边);
|
||||
/// - [PvVideoFit.cover]:用 OverflowBox 把子层放到 `max(窗宽, 窗高×比例) × max(窗高, 窗宽÷比例)`
|
||||
/// 的盒子里 —— 该盒子比例与画面完全一致,子层的 contain 适配于是变成「刚好铺满」,
|
||||
/// 再由外层 ClipRect 裁掉超出窗口的部分:等比、无黑边、只裁边缘,画面不扭曲。
|
||||
class PvVideoFitBox extends StatelessWidget {
|
||||
const PvVideoFitBox({
|
||||
super.key,
|
||||
required this.fit,
|
||||
required this.source,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
final PvVideoFit fit;
|
||||
|
||||
/// 视频链路:用于查实际画面比例。
|
||||
final PvVideoSource source;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (fit == PvVideoFit.contain) return child;
|
||||
final ratio = pvFrameRatioOf(context, source);
|
||||
return LayoutBuilder(
|
||||
builder: (context, c) {
|
||||
final w = c.maxWidth;
|
||||
final h = c.maxHeight;
|
||||
// 约束不收敛时无法算裁切尺寸,直接原样显示
|
||||
if (!w.isFinite || !h.isFinite) return child;
|
||||
final boxW = math.max(w, h * ratio);
|
||||
final boxH = math.max(h, w / ratio);
|
||||
return ClipRect(
|
||||
child: OverflowBox(
|
||||
maxWidth: boxW,
|
||||
maxHeight: boxH,
|
||||
alignment: Alignment.center,
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
374
lib/features/pv_control/presentation/widgets/pv_work_map.dart
Normal file
374
lib/features/pv_control/presentation/widgets/pv_work_map.dart
Normal file
@@ -0,0 +1,374 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
|
||||
import 'package:maibu_satabot_v2/core/di/injection.dart';
|
||||
import 'package:maibu_satabot_v2/core/network/mqtt/domain/entities/route_status_entity.dart';
|
||||
import 'package:maibu_satabot_v2/core/network/mqtt/domain/repositories/mower_realtime_repository.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/presentation/bloc/device_status_bloc.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/presentation/bloc/device_status_state.dart';
|
||||
import 'package:maibu_satabot_v2/features/home/presentation/widgets/map/HeadingPointer.dart';
|
||||
import 'package:maibu_satabot_v2/features/home/presentation/widgets/map/geoserver_suzhou_layer.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/site/presentation/cubit/site_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
|
||||
import '../theme/pv_colors.dart';
|
||||
|
||||
/// HUD 作业地图:与「路径规划」同源、同图层、同样式的**只读**实时地图。
|
||||
///
|
||||
/// 图层顺序与配色完全照抄路径规划(testmap_pages._buildMap),只保留展示所需的部分:
|
||||
/// ① ESRI 卫星底图 ② 场站无人机高清叠加层 ③ 规划路线(金黄) ④ 已走轨迹(绿) ⑤ 机器指针。
|
||||
/// 打点、障碍物、保存、开始作业等交互一概不做;路径规划的文件零改动。
|
||||
///
|
||||
/// 数据全部来自 MQTT(TCP 链路已停用):
|
||||
/// - 机器位置/航向:全局单例 [DeviceStatusBloc] 的 `DeviceStatusUpdated`
|
||||
/// (mower/{sn}/property/location/post,bloc 内 500ms 节流),与路径规划同一条流;
|
||||
/// - 规划路线:`MowerRealtimeRepository.routeStatusStream`(device/{sn}/route/post,
|
||||
/// 广播流,这里只是多一个订阅者,不会影响路径规划页的订阅)。
|
||||
///
|
||||
/// 与路径规划的唯一行为差异(按需求新增):机器**始终显示在正中间**。用户手拖/缩放
|
||||
/// 会暂停跟随,右下角「定位」按钮恢复。
|
||||
class PvWorkMap extends StatefulWidget {
|
||||
const PvWorkMap({
|
||||
super.key,
|
||||
this.deviceSn = '',
|
||||
this.interactive = true,
|
||||
this.scale = 1,
|
||||
});
|
||||
|
||||
/// 设备 SN:用于过滤路线推送(deviceId 不匹配的消息直接丢弃)。
|
||||
/// 订阅本身由页面层 `startMqttRealtimeListening` 保证,这里不重复切换全局设备。
|
||||
final String deviceSn;
|
||||
|
||||
/// 是否允许拖动/缩放:左栏小卡传 false(避免与列表滚动、摇杆抢手势),
|
||||
/// 放大到屏幕中央的大卡传 true。
|
||||
final bool interactive;
|
||||
|
||||
/// HUD 的缩放系数(与 pv_manual_control_view 的 _sc 一致),只影响两个浮动按钮大小。
|
||||
final double scale;
|
||||
|
||||
@override
|
||||
State<PvWorkMap> createState() => _PvWorkMapState();
|
||||
}
|
||||
|
||||
class _PvWorkMapState extends State<PvWorkMap> {
|
||||
// ===== 与路径规划一致的常量 =====
|
||||
static const _esriUrl =
|
||||
'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}';
|
||||
static const _centerZoom = 18.0; // 路径规划回中/跟随都用 18 级
|
||||
static const _maxTrace = 600; // 绿线最多保留的点数(约 5 分钟推送)
|
||||
static const _minTraceStep = 0.3; // 米:小于此间距的点丢弃(抖动过滤)
|
||||
|
||||
final MapController _map = MapController();
|
||||
final Distance _dist = const Distance();
|
||||
|
||||
StreamSubscription<RouteStatusEntity>? _routeSub;
|
||||
|
||||
/// 场站高清叠加层:默认用内置常量,GetCapabilities 回来后换成动态范围
|
||||
List<TileLayer> _stationLayers = kAllStationTileLayers;
|
||||
bool _showStation = true;
|
||||
|
||||
bool _ready = false; // 地图未 ready 前不能用 controller,否则断言
|
||||
bool _follow = true; // 机器居中跟随中(用户手势会关掉)
|
||||
bool _moveScheduled = false;
|
||||
|
||||
List<LatLng> _route = const [];
|
||||
final List<LatLng> _trace = [];
|
||||
int _routeTaskId = -1;
|
||||
LatLng? _pos;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// 图层范围仓库:与路径规划同一套用法(动态刷新 + 变更通知,失败自动回退内置兜底)
|
||||
StationLayerRepo.instance.addListener(_onStationLayersUpdated);
|
||||
StationLayerRepo.instance.refresh();
|
||||
_stationLayers = StationLayerRepo.instance.buildLayers();
|
||||
_routeSub = sl<MowerRealtimeRepository>().routeStatusStream.listen(
|
||||
_onRouteMessage,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant PvWorkMap oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
// 换设备:上一台的路线与轨迹都没有意义,清空重来
|
||||
if (oldWidget.deviceSn != widget.deviceSn) {
|
||||
_route = const [];
|
||||
_routeTaskId = -1;
|
||||
_trace.clear();
|
||||
_pos = null;
|
||||
_follow = true;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
StationLayerRepo.instance.removeListener(_onStationLayersUpdated);
|
||||
_routeSub?.cancel();
|
||||
_map.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onStationLayersUpdated() {
|
||||
if (!mounted) return;
|
||||
setState(() => _stationLayers = StationLayerRepo.instance.buildLayers());
|
||||
}
|
||||
|
||||
/// 规划路线(金黄线):后端在任务执行时推送整条覆盖清扫路线
|
||||
void _onRouteMessage(RouteStatusEntity msg) {
|
||||
if (widget.deviceSn.isNotEmpty &&
|
||||
msg.deviceId.isNotEmpty &&
|
||||
msg.deviceId != widget.deviceSn) {
|
||||
return; // 别的设备的路线不画
|
||||
}
|
||||
if (msg.data.isEmpty || !mounted) return;
|
||||
setState(() {
|
||||
// 新任务 = 上一段的行走轨迹作废(路径规划选中任务时同样会 reset 轨迹)
|
||||
if (msg.taskId != _routeTaskId) {
|
||||
_routeTaskId = msg.taskId;
|
||||
_trace.clear();
|
||||
}
|
||||
_route = [for (final p in msg.data) LatLng(p.lat, p.lng)];
|
||||
});
|
||||
}
|
||||
|
||||
/// 定位推送来了:攒轨迹 + 按需把机器移到正中间
|
||||
void _onLocation(DeviceStatusUpdated state) {
|
||||
final p = _validLatLng(state.status.latitude, state.status.longitude);
|
||||
if (p == null) return; // 无效坐标不画点、不追(与路径规划一致)
|
||||
if (p == _pos) return;
|
||||
_pos = p;
|
||||
_appendTrace(p);
|
||||
if (_follow) _scheduleMove(p);
|
||||
}
|
||||
|
||||
void _appendTrace(LatLng p) {
|
||||
final last = _trace.isEmpty ? null : _trace.last;
|
||||
if (last != null && _dist(last, p) < _minTraceStep) return;
|
||||
_trace.add(p);
|
||||
if (_trace.length > _maxTrace) {
|
||||
_trace.removeRange(0, _trace.length - _maxTrace);
|
||||
}
|
||||
}
|
||||
|
||||
/// 移动地图必须在帧结束后做:在 build / listener 里直接 move 会撞上
|
||||
/// “setState during build” 断言。一帧内多次推送只排一次。
|
||||
void _scheduleMove(LatLng p) {
|
||||
if (_moveScheduled) return;
|
||||
_moveScheduled = true;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_moveScheduled = false;
|
||||
if (!mounted || !_ready) return;
|
||||
_map.move(p, _centerZoom);
|
||||
});
|
||||
}
|
||||
|
||||
/// 用户自己的手势 → 暂停跟随,让他能看全局;点「定位」再恢复
|
||||
void _onMapEvent(MapEvent event) {
|
||||
if (!_follow) return;
|
||||
switch (event.source) {
|
||||
case MapEventSource.onDrag:
|
||||
case MapEventSource.dragEnd:
|
||||
case MapEventSource.onMultiFinger:
|
||||
case MapEventSource.multiFingerEnd:
|
||||
case MapEventSource.flingAnimationController:
|
||||
case MapEventSource.scrollWheel:
|
||||
case MapEventSource.doubleTapZoomAnimationController:
|
||||
setState(() => _follow = false);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void _recenter() {
|
||||
final p = _pos ?? _fallbackCenter();
|
||||
_follow = true;
|
||||
if (_ready) _map.move(p, _centerZoom);
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
/// 进场中心:优先当前选中场站高清图层中心,无有效场站兜底到苏州地块(同路径规划)
|
||||
LatLng _fallbackCenter() =>
|
||||
stationLayerCenter(sl<SiteCubit>().state.selectedSite?.siteMapName) ??
|
||||
const LatLng(31.083296, 120.840355);
|
||||
|
||||
LatLng? _validLatLng(double lat, double lng) {
|
||||
if (lat == 0 || lng == 0) return null; // 排除赤道 0,0
|
||||
if (lat < -90 || lat > 90 || lng < -180 || lng > 180) return null;
|
||||
return LatLng(lat, lng);
|
||||
}
|
||||
|
||||
double ds(num v) => v * widget.scale;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocListener<DeviceStatusBloc, DeviceStatusState>(
|
||||
listenWhen: (prev, cur) => cur is DeviceStatusUpdated,
|
||||
listener: (context, state) => _onLocation(state as DeviceStatusUpdated),
|
||||
child: BlocBuilder<DeviceStatusBloc, DeviceStatusState>(
|
||||
buildWhen: (prev, cur) => cur is DeviceStatusUpdated,
|
||||
builder: (context, state) {
|
||||
final status = state is DeviceStatusUpdated ? state.status : null;
|
||||
final marker = status == null
|
||||
? null
|
||||
: _validLatLng(status.latitude, status.longitude);
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
FlutterMap(
|
||||
mapController: _map,
|
||||
options: MapOptions(
|
||||
initialCenter: _pos ?? _fallbackCenter(),
|
||||
initialZoom: _centerZoom,
|
||||
maxZoom: 22,
|
||||
minZoom: 3,
|
||||
// 小卡完全禁手势;大卡禁旋转(与路径规划一致:all & ~rotate)
|
||||
interactionOptions: InteractionOptions(
|
||||
flags: widget.interactive
|
||||
? InteractiveFlag.all & ~InteractiveFlag.rotate
|
||||
: InteractiveFlag.none,
|
||||
),
|
||||
onMapReady: () => _ready = true,
|
||||
onMapEvent: _onMapEvent,
|
||||
onTap: (_, _) {}, // 空实现:地图本身不响应点击
|
||||
),
|
||||
children: [
|
||||
/// ESRI World Imagery(WGS84,全球高清卫星图,无需坐标转换)
|
||||
TileLayer(
|
||||
urlTemplate: _esriUrl,
|
||||
userAgentPackageName: 'com.example.app',
|
||||
minZoom: 0,
|
||||
maxZoom: 19,
|
||||
),
|
||||
|
||||
/// 场站无人机高清影像:滑到哪个场站区域(zoom>=16)就叠哪个
|
||||
if (_showStation) ..._stationLayers,
|
||||
|
||||
/// 规划路线(金黄 + 白描边),参数与路径规划完全相同
|
||||
if (_route.isNotEmpty)
|
||||
PolylineLayer(
|
||||
polylines: [
|
||||
Polyline(
|
||||
points: _route,
|
||||
color: const Color.fromARGB(255, 255, 204, 0),
|
||||
strokeWidth: 1.0,
|
||||
borderColor: Colors.white,
|
||||
borderStrokeWidth: 1,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
/// 已走轨迹(绿色实线,本地按定位推送累积)
|
||||
if (_trace.length >= 2)
|
||||
PolylineLayer(
|
||||
key: const ValueKey('pv_trace'),
|
||||
polylines: [
|
||||
Polyline(
|
||||
points: List.of(_trace),
|
||||
color: const Color(0xFF00B42A),
|
||||
strokeWidth: 4,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
/// 机器指针(同一个 HeadingMarkerPainter:绿圆 + 白描边 + 航向箭头)
|
||||
if (marker != null)
|
||||
MarkerLayer(
|
||||
markers: [
|
||||
Marker(
|
||||
point: marker,
|
||||
width: 40,
|
||||
height: 40,
|
||||
child: CustomPaint(
|
||||
size: const Size(40, 40),
|
||||
painter: HeadingMarkerPainter(
|
||||
headingAngle: status?.yaw ?? 0,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
// 还没收到定位推送时的提示(此时图面停在场站中心,机器不出现)
|
||||
if (marker == null)
|
||||
Positioned(
|
||||
left: ds(6),
|
||||
top: ds(6),
|
||||
child: _badge(
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('pv_control.map_waiting_push'),
|
||||
),
|
||||
),
|
||||
// 高清图层开关
|
||||
Positioned(
|
||||
right: ds(4),
|
||||
top: ds(4),
|
||||
child: _floatButton(
|
||||
Icons.layers,
|
||||
active: _showStation,
|
||||
onTap: () => setState(() => _showStation = !_showStation),
|
||||
),
|
||||
),
|
||||
// 恢复跟随并回中
|
||||
Positioned(
|
||||
right: ds(4),
|
||||
bottom: ds(4),
|
||||
child: _floatButton(
|
||||
Icons.my_location,
|
||||
active: _follow,
|
||||
onTap: _recenter,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _badge(String text) {
|
||||
return Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: ds(6), vertical: ds(2)),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withValues(alpha: 0.5),
|
||||
borderRadius: BorderRadius.circular(ds(4)),
|
||||
),
|
||||
child: Text(
|
||||
text,
|
||||
style: TextStyle(fontSize: ds(10), color: PvColors.textSecondary),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _floatButton(
|
||||
IconData icon, {
|
||||
required bool active,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
width: ds(28),
|
||||
height: ds(28),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withValues(alpha: 0.5),
|
||||
borderRadius: BorderRadius.circular(ds(7)),
|
||||
border: Border.all(color: PvColors.cardBorder),
|
||||
),
|
||||
child: Icon(
|
||||
icon,
|
||||
color: active
|
||||
? PvColors.accentBright
|
||||
: PvColors.textTertiary, // 关掉的图层用灰图标,一眼能分辨
|
||||
size: ds(16),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user