1优化改动设备栏中全部标签栏的设备列表中数据的整合,又数据合并解耦成使用已有组件各自维护,使其样式和逻辑一致。
2接入了无人机机场的实时信息和无人机的实时信息,并创建了对应的组件,并测试。 3.实现了机器人的详情页的视频显示的逻辑为当机器人在线,就在下方同步出来机器人的各个方位视频,并且支持切换。 4.实现了全部设备中对类型的区分和实现了点击进入对应的详情页。 5.修复了部分bug,优化了代码结构,提高了代码的可读性和可维护性。 6更改了机器人列表项中的信息展示为机器序列号和别名和id(优先展示别名) 7.更改了无人机场的信息展示上位 无人机及序列号下位机场序列号。 8优化了无人机机场信息只能是的为明文展示。便于观看理解。
This commit is contained in:
@@ -0,0 +1,543 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../../../core/di/injection.dart';
|
||||
import '../../../../../core/network/mqtt/data/datasources/drone_osd_datasource.dart';
|
||||
import '../../../../../core/network/mqtt/domain/entities/drone_osd_entity.dart';
|
||||
|
||||
/// 无人机 OSD 实时数据卡片(网格布局展示所有数据)
|
||||
class DroneOsdCard extends StatefulWidget {
|
||||
final String deviceSn;
|
||||
final String gatewaySn;
|
||||
final bool isDroneOnline;
|
||||
|
||||
const DroneOsdCard({
|
||||
super.key,
|
||||
required this.deviceSn,
|
||||
required this.gatewaySn,
|
||||
required this.isDroneOnline,
|
||||
});
|
||||
|
||||
@override
|
||||
State<DroneOsdCard> createState() => _DroneOsdCardState();
|
||||
}
|
||||
|
||||
class _DroneOsdCardState extends State<DroneOsdCard> {
|
||||
late DroneOsdDataSource _dataSource;
|
||||
StreamSubscription<DroneOsdEntity>? _subscription;
|
||||
DroneOsdEntity? _currentOsd;
|
||||
|
||||
// OSD 数据字段列表
|
||||
List<Map<String, dynamic>> _osdFields = [];
|
||||
|
||||
// 缓存上次的有效值,避免闪烁
|
||||
Map<String, String> _cachedValues = {};
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_dataSource = sl<DroneOsdDataSource>();
|
||||
_startListening();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(DroneOsdCard oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.deviceSn != widget.deviceSn ||
|
||||
oldWidget.gatewaySn != widget.gatewaySn ||
|
||||
oldWidget.isDroneOnline != widget.isDroneOnline) {
|
||||
_stopListening();
|
||||
_startListening();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_stopListening();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _startListening() {
|
||||
if (!widget.isDroneOnline) return;
|
||||
if (widget.deviceSn.isEmpty) return;
|
||||
|
||||
debugPrint('🔊 [DroneOsdCard] 开始监听无人机 OSD: ${widget.deviceSn}');
|
||||
|
||||
_dataSource.startListening(
|
||||
deviceSn: widget.deviceSn,
|
||||
gatewaySn: widget.gatewaySn,
|
||||
);
|
||||
|
||||
_subscription = _dataSource.droneOsdStream.listen((osd) {
|
||||
if (!mounted) return;
|
||||
|
||||
debugPrint('📥 [DroneOsdCard] 收到无人机 OSD 数据');
|
||||
|
||||
setState(() {
|
||||
_currentOsd = osd;
|
||||
_parseOsdFields(osd);
|
||||
});
|
||||
|
||||
debugPrint('✅ [DroneOsdCard] UI 已更新,字段数: ${_osdFields.length}');
|
||||
});
|
||||
}
|
||||
|
||||
void _stopListening() {
|
||||
_subscription?.cancel();
|
||||
_subscription = null;
|
||||
_dataSource.stopListening();
|
||||
debugPrint('⏹️ [DroneOsdCard] 停止监听无人机 OSD');
|
||||
}
|
||||
|
||||
/// 解析无人机 OSD 数据为可展示的字段列表
|
||||
void _parseOsdFields(DroneOsdEntity osd) {
|
||||
final data = osd.rawData;
|
||||
|
||||
// 解析嵌套的 JSON 结构
|
||||
final droneData = data['data'] is Map
|
||||
? (data['data'] as Map)['drone']
|
||||
: null;
|
||||
if (droneData == null || droneData is! Map) {
|
||||
debugPrint('⚠️ [DroneOsdCard] 无法解析 drone 数据');
|
||||
return;
|
||||
}
|
||||
|
||||
debugPrint('📊 [DroneOsdCard] drone 数据键: ${droneData.keys.toList()}');
|
||||
|
||||
// ========== 1. 基础飞行信息 ==========
|
||||
// 无人机高度(height)
|
||||
double? height = (droneData['height'] as num?)?.toDouble();
|
||||
|
||||
// 飞行速度(ground_speed)
|
||||
double? groundSpeed = (droneData['ground_speed'] as num?)?.toDouble();
|
||||
|
||||
// 飞行距离(flight_distance)
|
||||
double? flightDistance = (droneData['flight_distance'] as num?)?.toDouble();
|
||||
|
||||
// 飞行时间(flight_time)
|
||||
int? flightTime = droneData['flight_time'] as int?;
|
||||
|
||||
// ========== 2. 电池信息 ==========
|
||||
// 电量百分比(battery_percent)
|
||||
int? batteryPercent = droneData['battery_percent'] as int?;
|
||||
|
||||
// 电池电压(battery_voltage)
|
||||
double? batteryVoltage = (droneData['battery_voltage'] as num?)?.toDouble();
|
||||
|
||||
// 电池电流(battery_current)
|
||||
double? batteryCurrent = (droneData['battery_current'] as num?)?.toDouble();
|
||||
|
||||
// 电池温度(battery_temperature)
|
||||
double? batteryTemp = (droneData['battery_temperature'] as num?)
|
||||
?.toDouble();
|
||||
|
||||
// ========== 3. 位置与姿态 ==========
|
||||
// 纬度(latitude)
|
||||
double? latitude = (droneData['latitude'] as num?)?.toDouble();
|
||||
|
||||
// 经度(longitude)
|
||||
double? longitude = (droneData['longitude'] as num?)?.toDouble();
|
||||
|
||||
// 航向角(heading)
|
||||
double? heading = (droneData['heading'] as num?)?.toDouble();
|
||||
|
||||
// 俯仰角(pitch)
|
||||
double? pitch = (droneData['pitch'] as num?)?.toDouble();
|
||||
|
||||
// 横滚角(roll)
|
||||
double? roll = (droneData['roll'] as num?)?.toDouble();
|
||||
|
||||
// ========== 4. GPS 状态 ==========
|
||||
// GPS卫星数(gps_satellites)
|
||||
int? gpsSatellites = droneData['gps_satellites'] as int?;
|
||||
|
||||
// GPS信号质量(gps_quality)
|
||||
int? gpsQuality = droneData['gps_quality'] as int?;
|
||||
|
||||
// ========== 5. 遥控信号 ==========
|
||||
// 遥控信号强度(rc_signal_strength)
|
||||
int? rcSignal = droneData['rc_signal_strength'] as int?;
|
||||
|
||||
// 图传信号强度(video_signal_strength)
|
||||
int? videoSignal = droneData['video_signal_strength'] as int?;
|
||||
|
||||
// ========== 6. 飞行模式 ==========
|
||||
// 飞行模式(flight_mode)
|
||||
String? flightMode = droneData['flight_mode'] as String?;
|
||||
|
||||
// ========== 7. 电机状态 ==========
|
||||
// 电机状态(motor_status)
|
||||
int? motorStatus = droneData['motor_status'] as int?;
|
||||
|
||||
// ========== 8. 任务状态 ==========
|
||||
// 任务进度(mission_progress)
|
||||
int? missionProgress = droneData['mission_progress'] as int?;
|
||||
|
||||
// 航点数量(waypoint_count)
|
||||
int? waypointCount = droneData['waypoint_count'] as int?;
|
||||
|
||||
// 当前航点(current_waypoint)
|
||||
int? currentWaypoint = droneData['current_waypoint'] as int?;
|
||||
|
||||
// 剩余航点(remaining_waypoints)
|
||||
int? remainingWaypoints = droneData['remaining_waypoints'] as int?;
|
||||
|
||||
debugPrint('✅ [DroneOsdCard] 解析结果:');
|
||||
debugPrint(' 高度: $height m');
|
||||
debugPrint(' 速度: $groundSpeed m/s');
|
||||
debugPrint(' 距离: $flightDistance m');
|
||||
debugPrint(' 时间: $flightTime s');
|
||||
debugPrint(' 电量: $batteryPercent%');
|
||||
debugPrint(' 电压: $batteryVoltage V');
|
||||
debugPrint(' GPS: $gpsSatellites 颗卫星');
|
||||
debugPrint(' 航向: $heading°');
|
||||
debugPrint(' 飞行模式: $flightMode');
|
||||
|
||||
// 构建展示字段列表(精选重要字段)
|
||||
_osdFields = [
|
||||
{
|
||||
'icon': Icons.height,
|
||||
'label': '飞行高度',
|
||||
'key': 'height',
|
||||
'newValue': height != null ? '${height.toStringAsFixed(1)}m' : null,
|
||||
'color': const Color(0xFF165DFF),
|
||||
},
|
||||
{
|
||||
'icon': Icons.speed,
|
||||
'label': '飞行速度',
|
||||
'key': 'speed',
|
||||
'newValue': groundSpeed != null
|
||||
? '${groundSpeed.toStringAsFixed(1)}m/s'
|
||||
: null,
|
||||
'color': const Color(0xFF722ED1),
|
||||
},
|
||||
{
|
||||
'icon': Icons.route,
|
||||
'label': '飞行距离',
|
||||
'key': 'distance',
|
||||
'newValue': flightDistance != null
|
||||
? '${flightDistance.toStringAsFixed(0)}m'
|
||||
: null,
|
||||
'color': const Color(0xFF00B42A),
|
||||
},
|
||||
{
|
||||
'icon': Icons.timer,
|
||||
'label': '飞行时间',
|
||||
'key': 'time',
|
||||
'newValue': flightTime != null
|
||||
? '${(flightTime / 60).toStringAsFixed(1)}min'
|
||||
: null,
|
||||
'color': const Color(0xFF86909C),
|
||||
},
|
||||
{
|
||||
'icon': Icons.battery_full_rounded,
|
||||
'label': '电量',
|
||||
'key': 'battery',
|
||||
'newValue': batteryPercent != null ? '$batteryPercent%' : null,
|
||||
'color': _getBatteryColor(batteryPercent),
|
||||
},
|
||||
{
|
||||
'icon': Icons.bolt,
|
||||
'label': '电池电压',
|
||||
'key': 'voltage',
|
||||
'newValue': batteryVoltage != null
|
||||
? '${batteryVoltage.toStringAsFixed(1)}V'
|
||||
: null,
|
||||
'color': const Color(0xFF00B42A),
|
||||
},
|
||||
{
|
||||
'icon': Icons.thermostat,
|
||||
'label': '电池温度',
|
||||
'key': 'batteryTemp',
|
||||
'newValue': batteryTemp != null
|
||||
? '${batteryTemp.toStringAsFixed(0)}°C'
|
||||
: null,
|
||||
'color': batteryTemp != null && batteryTemp > 50
|
||||
? const Color(0xFFF53F3F)
|
||||
: const Color(0xFF165DFF),
|
||||
},
|
||||
{
|
||||
'icon': Icons.navigation,
|
||||
'label': '航向角',
|
||||
'key': 'heading',
|
||||
'newValue': heading != null ? '${heading.toStringAsFixed(0)}°' : null,
|
||||
'color': const Color(0xFF165DFF),
|
||||
},
|
||||
{
|
||||
'icon': Icons.rotate_90_degrees_cw,
|
||||
'label': '俯仰角',
|
||||
'key': 'pitch',
|
||||
'newValue': pitch != null ? '${pitch.toStringAsFixed(1)}°' : null,
|
||||
'color': const Color(0xFF722ED1),
|
||||
},
|
||||
{
|
||||
'icon': Icons.rotate_right,
|
||||
'label': '横滚角',
|
||||
'key': 'roll',
|
||||
'newValue': roll != null ? '${roll.toStringAsFixed(1)}°' : null,
|
||||
'color': const Color(0xFF722ED1),
|
||||
},
|
||||
{
|
||||
'icon': Icons.satellite,
|
||||
'label': 'GPS卫星',
|
||||
'key': 'gps',
|
||||
'newValue': gpsSatellites != null ? '$gpsSatellites颗' : null,
|
||||
'color': gpsSatellites != null && gpsSatellites >= 6
|
||||
? const Color(0xFF00B42A)
|
||||
: const Color(0xFFFF7D00),
|
||||
},
|
||||
{
|
||||
'icon': Icons.signal_cellular_alt,
|
||||
'label': '遥控信号',
|
||||
'key': 'rcSignal',
|
||||
'newValue': rcSignal != null ? '$rcSignal%' : null,
|
||||
'color': rcSignal != null && rcSignal > 80
|
||||
? const Color(0xFF00B42A)
|
||||
: rcSignal != null && rcSignal > 50
|
||||
? const Color(0xFFFF7D00)
|
||||
: const Color(0xFFF53F3F),
|
||||
},
|
||||
{
|
||||
'icon': Icons.video_label,
|
||||
'label': '图传信号',
|
||||
'key': 'videoSignal',
|
||||
'newValue': videoSignal != null ? '$videoSignal%' : null,
|
||||
'color': videoSignal != null && videoSignal > 80
|
||||
? const Color(0xFF00B42A)
|
||||
: videoSignal != null && videoSignal > 50
|
||||
? const Color(0xFFFF7D00)
|
||||
: const Color(0xFFF53F3F),
|
||||
},
|
||||
{
|
||||
'icon': Icons.flight,
|
||||
'label': '飞行模式',
|
||||
'key': 'flightMode',
|
||||
'newValue': flightMode,
|
||||
'color': const Color(0xFF165DFF),
|
||||
},
|
||||
{
|
||||
'icon': Icons.radio_button_checked,
|
||||
'label': '任务进度',
|
||||
'key': 'mission',
|
||||
'newValue': missionProgress != null ? '$missionProgress%' : null,
|
||||
'color': const Color(0xFF00B42A),
|
||||
},
|
||||
{
|
||||
'icon': Icons.map,
|
||||
'label': '航点',
|
||||
'key': 'waypoint',
|
||||
'newValue': (currentWaypoint != null && waypointCount != null)
|
||||
? '$currentWaypoint/$waypointCount'
|
||||
: null,
|
||||
'color': const Color(0xFF722ED1),
|
||||
},
|
||||
];
|
||||
|
||||
// 应用缓存逻辑:有新值则更新缓存,否则使用旧值
|
||||
for (var field in _osdFields) {
|
||||
final key = field['key'] as String;
|
||||
final newValue = field['newValue'] as String?;
|
||||
|
||||
if (newValue != null && newValue != '未知' && newValue.isNotEmpty) {
|
||||
_cachedValues[key] = newValue;
|
||||
field['value'] = newValue;
|
||||
} else {
|
||||
field['value'] = _cachedValues[key] ?? '未知';
|
||||
}
|
||||
}
|
||||
|
||||
debugPrint('✅ [DroneOsdCard] 共解析 ${_osdFields.length} 个字段');
|
||||
}
|
||||
|
||||
Color _getBatteryColor(dynamic battery) {
|
||||
if (battery == null) return const Color(0xFF86909C);
|
||||
|
||||
final value = battery is num ? battery.toDouble() : 0.0;
|
||||
if (value > 50) return const Color(0xFF00B42A);
|
||||
if (value > 20) return const Color(0xFFFF7D00);
|
||||
return const Color(0xFFF53F3F);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!widget.isDroneOnline) {
|
||||
return _buildOfflineCard();
|
||||
}
|
||||
|
||||
if (_osdFields.isEmpty) {
|
||||
return _buildLoadingCard();
|
||||
}
|
||||
|
||||
return _buildOsdGridCard();
|
||||
}
|
||||
|
||||
/// 离线状态卡片
|
||||
Widget _buildOfflineCard() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: const [
|
||||
BoxShadow(
|
||||
color: Color(0x0D000000),
|
||||
blurRadius: 8,
|
||||
offset: Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.flight_land, size: 48, color: const Color(0xFF86909C)),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: const [
|
||||
Text(
|
||||
'无人机离线',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF1D2129),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 4),
|
||||
Text(
|
||||
'无人机实时数据不可用',
|
||||
style: TextStyle(fontSize: 12, color: Color(0xFF86909C)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 加载中卡片
|
||||
Widget _buildLoadingCard() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: const [
|
||||
BoxShadow(
|
||||
color: Color(0x0D000000),
|
||||
blurRadius: 8,
|
||||
offset: Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Center(
|
||||
child: CircularProgressIndicator(color: Color(0xFF165DFF)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// OSD 网格布局卡片(核心功能)
|
||||
Widget _buildOsdGridCard() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: const [
|
||||
BoxShadow(
|
||||
color: Color(0x0D000000),
|
||||
blurRadius: 8,
|
||||
offset: Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 标题
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.flight, size: 20, color: const Color(0xFF165DFF)),
|
||||
const SizedBox(width: 8),
|
||||
const Text(
|
||||
'无人机实时信息',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF1D2129),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
// 网格布局展示所有字段
|
||||
GridView.builder(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 3,
|
||||
crossAxisSpacing: 12,
|
||||
mainAxisSpacing: 12,
|
||||
childAspectRatio: 0.85,
|
||||
),
|
||||
itemCount: _osdFields.length,
|
||||
itemBuilder: (context, index) {
|
||||
final field = _osdFields[index];
|
||||
return _buildOsdGridItem(field);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// OSD 网格项
|
||||
Widget _buildOsdGridItem(Map<String, dynamic> field) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: (field['color'] as Color).withOpacity(0.08),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(
|
||||
color: (field['color'] as Color).withOpacity(0.2),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
// 图标
|
||||
Icon(
|
||||
field['icon'] as IconData,
|
||||
color: field['color'] as Color,
|
||||
size: 24,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// 标签
|
||||
Text(
|
||||
field['label'] as String,
|
||||
style: const TextStyle(fontSize: 11, color: Color(0xFF86909C)),
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
|
||||
// 数值
|
||||
Text(
|
||||
field['value'] as String,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: field['color'] as Color,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -114,13 +114,13 @@ class DroneStationItemCard extends StatelessWidget {
|
||||
children: [
|
||||
_buildInfoRowWithIcon(
|
||||
Icons.tag_rounded,
|
||||
'机场序列号',
|
||||
'无人机序列号',
|
||||
station.deviceSn,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_buildInfoRowWithIcon(
|
||||
Icons.router_rounded,
|
||||
'网关序列号',
|
||||
'机场序列号',
|
||||
station.gatewaySn,
|
||||
),
|
||||
// if (station.latitude != null || station.longitude != null) ...[
|
||||
|
||||
@@ -0,0 +1,569 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../../../core/di/injection.dart';
|
||||
import '../../../../../core/network/mqtt/data/datasources/drone_osd_datasource.dart';
|
||||
import '../../../../../core/network/mqtt/domain/entities/drone_osd_entity.dart';
|
||||
|
||||
/// 无人机机场 OSD 实时数据卡片(网格布局展示所有数据)
|
||||
class DroneStationOsdCard extends StatefulWidget {
|
||||
final String gatewaySn;
|
||||
final bool isOnline;
|
||||
|
||||
const DroneStationOsdCard({
|
||||
super.key,
|
||||
required this.gatewaySn,
|
||||
required this.isOnline,
|
||||
});
|
||||
|
||||
@override
|
||||
State<DroneStationOsdCard> createState() => _DroneStationOsdCardState();
|
||||
}
|
||||
|
||||
class _DroneStationOsdCardState extends State<DroneStationOsdCard> {
|
||||
late DroneOsdDataSource _dataSource;
|
||||
StreamSubscription<DroneOsdEntity>? _subscription;
|
||||
DroneOsdEntity? _currentOsd;
|
||||
|
||||
// OSD 数据字段列表
|
||||
List<Map<String, dynamic>> _osdFields = [];
|
||||
|
||||
// 🔥 缓存上次的有效值,避免闪烁
|
||||
Map<String, String> _cachedValues = {};
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_dataSource = sl<DroneOsdDataSource>();
|
||||
_startListening();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(DroneStationOsdCard oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.gatewaySn != widget.gatewaySn ||
|
||||
oldWidget.isOnline != widget.isOnline) {
|
||||
_stopListening();
|
||||
_startListening();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_stopListening();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _startListening() {
|
||||
if (!widget.isOnline) return;
|
||||
|
||||
//debugPrint('🔊 [DroneStationOsdCard] 开始监听机场 OSD: ${widget.gatewaySn}');
|
||||
|
||||
_dataSource.startListening(
|
||||
deviceSn: '', // 机场不需要 deviceSn
|
||||
gatewaySn: widget.gatewaySn,
|
||||
);
|
||||
|
||||
_subscription = _dataSource.stationOsdStream.listen((osd) {
|
||||
if (!mounted) return;
|
||||
|
||||
//debugPrint('📥 [DroneStationOsdCard] 收到机场 OSD 原始数据');
|
||||
|
||||
setState(() {
|
||||
_currentOsd = osd;
|
||||
_parseOsdFields(osd);
|
||||
});
|
||||
|
||||
// debugPrint('✅ [DroneStationOsdCard] UI 已更新,字段数: ${_osdFields.length}');
|
||||
});
|
||||
}
|
||||
|
||||
void _stopListening() {
|
||||
_subscription?.cancel();
|
||||
_subscription = null;
|
||||
_dataSource.stopListening();
|
||||
debugPrint('⏹️ [DroneStationOsdCard] 停止监听机场 OSD');
|
||||
}
|
||||
|
||||
/// 解析 OSD 数据为可展示的字段列表
|
||||
void _parseOsdFields(DroneOsdEntity osd) {
|
||||
final data = osd.rawData;
|
||||
|
||||
// 解析嵌套的 JSON 结构
|
||||
final hostData = data['data'] is Map ? (data['data'] as Map)['host'] : null;
|
||||
if (hostData == null || hostData is! Map) {
|
||||
debugPrint('⚠️ [DroneStationOsdCard] 无法解析 host 数据');
|
||||
return;
|
||||
}
|
||||
|
||||
// debugPrint('📊 [DroneStationOsdCard] 开始解析 OSD 数据...');
|
||||
//debugPrint('📊 [DroneStationOsdCard] host 数据键: ${hostData.keys.toList()}');
|
||||
|
||||
// ========== 1. 电池相关 ==========
|
||||
// 提取无人机电量(从 drone_battery_maintenance_info.batteries[0].capacity_percent)
|
||||
double? batteryPercent;
|
||||
final batteryInfo = hostData['drone_battery_maintenance_info'];
|
||||
if (batteryInfo is Map && batteryInfo['batteries'] is List) {
|
||||
final batteries = batteryInfo['batteries'] as List;
|
||||
if (batteries.isNotEmpty && batteries[0] is Map) {
|
||||
batteryPercent = (batteries[0]['capacity_percent'] as num?)?.toDouble();
|
||||
}
|
||||
}
|
||||
|
||||
// 提取备用电池温度(从 backup_battery.temperature)
|
||||
double? backupBatteryTemp;
|
||||
final backupBattery = hostData['backup_battery'];
|
||||
if (backupBattery is Map) {
|
||||
backupBatteryTemp = (backupBattery['temperature'] as num?)?.toDouble();
|
||||
}
|
||||
|
||||
// 提取备用电池电压(从 backup_battery.voltage)
|
||||
int? backupBatteryVoltage;
|
||||
if (backupBattery is Map) {
|
||||
backupBatteryVoltage = backupBattery['voltage'] as int?;
|
||||
}
|
||||
|
||||
// 提取备用电池开关状态(从 backup_battery.switch)
|
||||
int? backupBatterySwitch;
|
||||
if (backupBattery is Map) {
|
||||
backupBatterySwitch = backupBattery['switch'] as int?;
|
||||
}
|
||||
|
||||
// ========== 2. 电源相关 ==========
|
||||
// 提取交流输入功率(acdc_power_input)
|
||||
double? acdcPower = (hostData['acdc_power_input'] as num?)?.toDouble();
|
||||
|
||||
// 提取供电电压(electric_supply_voltage)
|
||||
int? supplyVoltage = hostData['electric_supply_voltage'] as int?;
|
||||
|
||||
// 提取 PoE 链路状态(poe_link_status)
|
||||
int? poeLinkStatus = hostData['poe_link_status'] as int?;
|
||||
|
||||
// 提取 PoE 输出功率(poe_power_output)
|
||||
double? poePowerOutput = (hostData['poe_power_output'] as num?)?.toDouble();
|
||||
|
||||
// ========== 3. 部署与维护 ==========
|
||||
// 提取部署模式(deployment_mode)
|
||||
int? deploymentMode = hostData['deployment_mode'] as int?;
|
||||
|
||||
// 提取作业编号(job_number)
|
||||
int? jobNumber = hostData['job_number'] as int?;
|
||||
|
||||
// 提取云台 holder 状态(gimbal_holder_state)
|
||||
int? gimbalHolderState = hostData['gimbal_holder_state'] as int?;
|
||||
|
||||
// 提取维护状态(maintain_status)
|
||||
String maintainStatus = '未知';
|
||||
final maintainStatusData = hostData['maintain_status'];
|
||||
if (maintainStatusData is Map && maintainStatusData['maintain_status_array'] is List) {
|
||||
final statusArray = maintainStatusData['maintain_status_array'] as List;
|
||||
if (statusArray.isNotEmpty && statusArray[0] is Map) {
|
||||
final firstStatus = statusArray[0] as Map;
|
||||
final state = firstStatus['state'];
|
||||
final maintainType = firstStatus['last_maintain_type'];
|
||||
maintainStatus = '状态:$state 类型:$maintainType';
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 4. 位置与坐标 ==========
|
||||
// 提取相对备降点信息(relative_alternate_land_point)
|
||||
String landPointInfo = '未知';
|
||||
final landPointData = hostData['relative_alternate_land_point'];
|
||||
if (landPointData is Map) {
|
||||
final lat = landPointData['latitude'];
|
||||
final lon = landPointData['longitude'];
|
||||
final safeHeight = landPointData['safe_land_height'];
|
||||
final status = landPointData['status'];
|
||||
landPointInfo = 'LAT:${lat?.toStringAsFixed(4)} LON:${lon?.toStringAsFixed(4)} H:${safeHeight}m S:$status';
|
||||
}
|
||||
|
||||
// 提取自收敛坐标(self_converge_coordinate)
|
||||
String convergeCoord = '未知';
|
||||
final convergeData = hostData['self_converge_coordinate'];
|
||||
if (convergeData is Map) {
|
||||
final height = convergeData['height'];
|
||||
convergeCoord = 'H:${height}m';
|
||||
}
|
||||
|
||||
// ========== 5. 网络与通信 ==========
|
||||
// 提取 SDR 上行质量(sdr.up_quality)
|
||||
int? sdrUpQuality;
|
||||
final sdrData = hostData['sdr'];
|
||||
if (sdrData is Map) {
|
||||
sdrUpQuality = sdrData['up_quality'] as int?;
|
||||
}
|
||||
|
||||
// 提取 SDR 下行质量(sdr.down_quality)
|
||||
int? sdrDownQuality;
|
||||
if (sdrData is Map) {
|
||||
sdrDownQuality = sdrData['down_quality'] as int?;
|
||||
}
|
||||
|
||||
// 提取 SDR 频段(sdr.frequency_band)
|
||||
double? sdrFreqBand;
|
||||
if (sdrData is Map) {
|
||||
sdrFreqBand = (sdrData['frequency_band'] as num?)?.toDouble();
|
||||
}
|
||||
|
||||
// ========== 6. 其他关键指标 ==========
|
||||
// 提取累计时间(acc_time)
|
||||
int? accTime = hostData['acc_time'] as int?;
|
||||
|
||||
// 提取激活时间(activation_time)
|
||||
int? activationTime = hostData['activation_time'] as int?;
|
||||
|
||||
// 提取倾斜角度(tilt_angle.value)
|
||||
double? tiltAngle;
|
||||
final tiltAngleData = hostData['tilt_angle'];
|
||||
if (tiltAngleData is Map && tiltAngleData['valid'] == 1) {
|
||||
tiltAngle = (tiltAngleData['value'] as num?)?.toDouble();
|
||||
}
|
||||
|
||||
/*debugPrint('✅ [DroneStationOsdCard] 解析结果:');
|
||||
debugPrint(' 无人机电量: $batteryPercent%');
|
||||
debugPrint(' 备用电池: ${backupBatteryTemp}°C / ${backupBatteryVoltage}mV / 开关:$backupBatterySwitch');
|
||||
debugPrint(' 交流功率: $acdcPower W');
|
||||
debugPrint(' 供电电压: $supplyVoltage V');
|
||||
debugPrint(' PoE状态: $poeLinkStatus / 功率: $poePowerOutput W');
|
||||
debugPrint(' 部署模式: $deploymentMode / 作业号: $jobNumber');
|
||||
debugPrint(' 云台状态: $gimbalHolderState');
|
||||
debugPrint(' 维护状态: $maintainStatus');
|
||||
debugPrint(' 备降点: $landPointInfo');
|
||||
debugPrint(' SDR上行: $sdrUpQuality% / 下行: $sdrDownQuality% / 频段: $sdrFreqBand GHz');
|
||||
debugPrint(' 倾斜角度: $tiltAngle°');
|
||||
debugPrint(' 累计时间: $accTime s');*/
|
||||
|
||||
// 构建展示字段列表(精选重要字段)
|
||||
// 🔥 使用缓存机制:有值则更新并缓存,无值则使用上次缓存的值
|
||||
_osdFields = [
|
||||
{
|
||||
'icon': Icons.battery_full_rounded,
|
||||
'label': '无人机电量',
|
||||
'key': 'battery',
|
||||
'newValue': batteryPercent != null ? '${batteryPercent.toInt()}%' : null,
|
||||
'color': _getBatteryColor(batteryPercent),
|
||||
},
|
||||
{
|
||||
'icon': Icons.thermostat_rounded,
|
||||
'label': '备用电池温度',
|
||||
'key': 'backupTemp',
|
||||
'newValue': backupBatteryTemp != null ? '${backupBatteryTemp.toStringAsFixed(1)}°C' : null,
|
||||
'color': const Color(0xFF165DFF),
|
||||
},
|
||||
{
|
||||
'icon': Icons.bolt_rounded,
|
||||
'label': '备用电池电压',
|
||||
'key': 'backupVoltage',
|
||||
'newValue': backupBatteryVoltage != null ? '${(backupBatteryVoltage / 1000).toStringAsFixed(2)}V' : null,
|
||||
'color': const Color(0xFF722ED1),
|
||||
},
|
||||
{
|
||||
'icon': Icons.power_rounded,
|
||||
'label': '交流输入功率',
|
||||
'key': 'acdcPower',
|
||||
'newValue': acdcPower != null ? '${acdcPower.toStringAsFixed(1)} W' : null,
|
||||
'color': const Color(0xFFFF7D00),
|
||||
},
|
||||
{
|
||||
'icon': Icons.electrical_services_rounded,
|
||||
'label': '供电电压',
|
||||
'key': 'supplyVoltage',
|
||||
'newValue': supplyVoltage != null ? '$supplyVoltage V' : null,
|
||||
'color': const Color(0xFF00B42A),
|
||||
},
|
||||
{
|
||||
'icon': Icons.network_check_rounded,
|
||||
'label': 'PoE链路',
|
||||
'key': 'poeLink',
|
||||
'newValue': poeLinkStatus != null ? (poeLinkStatus == 1 ? '已连接' : '未连接') : null,
|
||||
'color': poeLinkStatus == 1 ? const Color(0xFF00B42A) : const Color(0xFF86909C),
|
||||
},
|
||||
{
|
||||
'icon': Icons.settings_rounded,
|
||||
'label': '部署模式',
|
||||
'key': 'deployMode',
|
||||
'newValue': deploymentMode != null ? '模式$deploymentMode' : null,
|
||||
'color': const Color(0xFF165DFF),
|
||||
},
|
||||
{
|
||||
'icon': Icons.work_outline_rounded,
|
||||
'label': '作业编号',
|
||||
'key': 'jobNumber',
|
||||
'newValue': jobNumber != null ? '#$jobNumber' : null,
|
||||
'color': const Color(0xFF00B42A),
|
||||
},
|
||||
{
|
||||
'icon': Icons.camera_roll_rounded,
|
||||
'label': '云台状态',
|
||||
'key': 'gimbalState',
|
||||
'newValue': gimbalHolderState != null ? (gimbalHolderState == 1 ? '已锁定' : '未锁定') : null,
|
||||
'color': gimbalHolderState == 1 ? const Color(0xFF00B42A) : const Color(0xFFF53F3F),
|
||||
},
|
||||
{
|
||||
'icon': Icons.rotate_right_rounded,
|
||||
'label': '倾斜角度',
|
||||
'key': 'tiltAngle',
|
||||
'newValue': tiltAngle != null ? '${tiltAngle.toStringAsFixed(2)}°' : null,
|
||||
'color': const Color(0xFF722ED1),
|
||||
},
|
||||
{
|
||||
'icon': Icons.signal_cellular_alt_rounded,
|
||||
'label': 'SDR上行质量',
|
||||
'key': 'sdrUp',
|
||||
'newValue': sdrUpQuality != null ? '$sdrUpQuality%' : null,
|
||||
'color': sdrUpQuality != null && sdrUpQuality > 80
|
||||
? const Color(0xFF00B42A)
|
||||
: sdrUpQuality != null && sdrUpQuality > 50
|
||||
? const Color(0xFFFF7D00)
|
||||
: const Color(0xFFF53F3F),
|
||||
},
|
||||
{
|
||||
'icon': Icons.wifi_tethering_rounded,
|
||||
'label': 'SDR下行质量',
|
||||
'key': 'sdrDown',
|
||||
'newValue': sdrDownQuality != null ? '$sdrDownQuality%' : null,
|
||||
'color': sdrDownQuality != null && sdrDownQuality > 80
|
||||
? const Color(0xFF00B42A)
|
||||
: sdrDownQuality != null && sdrDownQuality > 50
|
||||
? const Color(0xFFFF7D00)
|
||||
: const Color(0xFFF53F3F),
|
||||
},
|
||||
{
|
||||
'icon': Icons.access_time_rounded,
|
||||
'label': '累计时间',
|
||||
'key': 'accTime',
|
||||
'newValue': accTime != null ? '${(accTime / 3600).toStringAsFixed(1)}h' : null,
|
||||
'color': const Color(0xFF86909C),
|
||||
},
|
||||
{
|
||||
'icon': Icons.calendar_today_rounded,
|
||||
'label': '激活时间',
|
||||
'key': 'activationTime',
|
||||
'newValue': activationTime != null ? _formatTimestamp(activationTime) : null,
|
||||
'color': const Color(0xFF86909C),
|
||||
},
|
||||
];
|
||||
|
||||
// 🔥 应用缓存逻辑:有新值则更新缓存,否则使用旧值
|
||||
for (var field in _osdFields) {
|
||||
final key = field['key'] as String;
|
||||
final newValue = field['newValue'] as String?;
|
||||
|
||||
if (newValue != null && newValue != '未知') {
|
||||
// 有新值,更新缓存
|
||||
_cachedValues[key] = newValue;
|
||||
field['value'] = newValue;
|
||||
} else {
|
||||
// 无新值,使用缓存值或默认"未知"
|
||||
field['value'] = _cachedValues[key] ?? '未知';
|
||||
}
|
||||
}
|
||||
|
||||
//debugPrint('✅ [DroneStationOsdCard] 共解析 ${_osdFields.length} 个字段');
|
||||
}
|
||||
|
||||
Color _getBatteryColor(dynamic battery) {
|
||||
if (battery == null) return const Color(0xFF86909C);
|
||||
|
||||
final value = battery is num ? battery.toDouble() : 0.0;
|
||||
if (value > 50) return const Color(0xFF00B42A);
|
||||
if (value > 20) return const Color(0xFFFF7D00);
|
||||
return const Color(0xFFF53F3F);
|
||||
}
|
||||
|
||||
/// 格式化 Unix 时间戳(秒)为日期字符串
|
||||
String _formatTimestamp(int timestamp) {
|
||||
try {
|
||||
final dateTime = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000);
|
||||
return '${dateTime.year}-${dateTime.month.toString().padLeft(2, '0')}-${dateTime.day.toString().padLeft(2, '0')}';
|
||||
} catch (e) {
|
||||
return '未知';
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!widget.isOnline) {
|
||||
return _buildOfflineCard();
|
||||
}
|
||||
|
||||
if (_osdFields.isEmpty) {
|
||||
return _buildLoadingCard();
|
||||
}
|
||||
|
||||
return _buildOsdGridCard();
|
||||
}
|
||||
|
||||
/// 离线状态卡片
|
||||
Widget _buildOfflineCard() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: const [
|
||||
BoxShadow(
|
||||
color: Color(0x0D000000),
|
||||
blurRadius: 8,
|
||||
offset: Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.cloud_off_rounded, size: 48, color: const Color(0xFF86909C)),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: const [
|
||||
Text(
|
||||
'机场离线',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF1D2129),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 4),
|
||||
Text(
|
||||
'暂无实时数据',
|
||||
style: TextStyle(fontSize: 12, color: Color(0xFF86909C)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 加载中卡片
|
||||
Widget _buildLoadingCard() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: const [
|
||||
BoxShadow(
|
||||
color: Color(0x0D000000),
|
||||
blurRadius: 8,
|
||||
offset: Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Center(
|
||||
child: CircularProgressIndicator(color: Color(0xFF165DFF)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// OSD 网格布局卡片(核心功能)
|
||||
Widget _buildOsdGridCard() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: const [
|
||||
BoxShadow(
|
||||
color: Color(0x0D000000),
|
||||
blurRadius: 8,
|
||||
offset: Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 标题
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.analytics_rounded, size: 20, color: const Color(0xFF165DFF)),
|
||||
const SizedBox(width: 8),
|
||||
const Text(
|
||||
'实时数据',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF1D2129),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
// 网格布局展示所有字段
|
||||
GridView.builder(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 3,
|
||||
crossAxisSpacing: 12,
|
||||
mainAxisSpacing: 12,
|
||||
childAspectRatio: 0.85,
|
||||
),
|
||||
itemCount: _osdFields.length,
|
||||
itemBuilder: (context, index) {
|
||||
final field = _osdFields[index];
|
||||
return _buildOsdGridItem(field);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// OSD 网格项
|
||||
Widget _buildOsdGridItem(Map<String, dynamic> field) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: (field['color'] as Color).withOpacity(0.08),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(
|
||||
color: (field['color'] as Color).withOpacity(0.2),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
// 图标
|
||||
Icon(
|
||||
field['icon'] as IconData,
|
||||
color: field['color'] as Color,
|
||||
size: 24,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// 标签
|
||||
Text(
|
||||
field['label'] as String,
|
||||
style: const TextStyle(
|
||||
fontSize: 11,
|
||||
color: Color(0xFF86909C),
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
|
||||
// 数值
|
||||
Text(
|
||||
field['value'] as String,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: field['color'] as Color,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,61 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.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/features/remote_control/presentation/widgets/webrtc/webrtc_local_player.dart';
|
||||
|
||||
/// 机器人顶部信息卡片
|
||||
class RobotHeaderCard extends StatelessWidget {
|
||||
class RobotHeaderCard extends StatefulWidget {
|
||||
final Map<String, dynamic> robot;
|
||||
|
||||
const RobotHeaderCard({super.key, required this.robot});
|
||||
|
||||
@override
|
||||
State<RobotHeaderCard> createState() => _RobotHeaderCardState();
|
||||
}
|
||||
|
||||
class _RobotHeaderCardState extends State<RobotHeaderCard> {
|
||||
String _videoStreamUrl = '';
|
||||
int _currentViewIndex = 0; // 0=前, 1=后, 2=左, 3=右, 4=上
|
||||
|
||||
// 视角配置
|
||||
final List<Map<String, dynamic>> _viewConfigs = [
|
||||
{'name': '前视', 'alignment': Alignment.topLeft, 'icon': Icons.arrow_upward},
|
||||
{'name': '后视', 'alignment': Alignment.topRight, 'icon': Icons.arrow_downward},
|
||||
{'name': '左视', 'alignment': Alignment.bottomLeft, 'icon': Icons.arrow_back},
|
||||
{'name': '右视', 'alignment': Alignment.bottomRight, 'icon': Icons.arrow_forward},
|
||||
{'name': '俯视', 'alignment': Alignment.center, 'icon': Icons.view_agenda},
|
||||
];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_initVideoUrl();
|
||||
}
|
||||
|
||||
/// 初始化视频流 URL
|
||||
void _initVideoUrl() {
|
||||
final userState = context.read<AppUserCubit>().state;
|
||||
final deviceId = widget.robot['id'] as String?;
|
||||
|
||||
debugPrint(' [RobotHeaderCard] 开始初始化视频URL');
|
||||
debugPrint('🎬 [RobotHeaderCard] deviceId: $deviceId');
|
||||
debugPrint('🎬 [RobotHeaderCard] user: ${userState.user}');
|
||||
debugPrint('🎬 [RobotHeaderCard] token: ${userState.user?.token}');
|
||||
|
||||
if (deviceId != null && deviceId.isNotEmpty && userState.user != null && userState.user!.token != null) {
|
||||
setState(() {
|
||||
_videoStreamUrl = "webrtc://${TCPConsts.TCP_IP}/live/livestream/$deviceId?token=${userState.user!.token}";
|
||||
});
|
||||
debugPrint('✅ [RobotHeaderCard] 视频URL初始化成功: $_videoStreamUrl');
|
||||
} else {
|
||||
debugPrint('❌ [RobotHeaderCard] 视频URL初始化失败');
|
||||
debugPrint(' - deviceId.isEmpty: ${deviceId == null || deviceId.isEmpty}');
|
||||
debugPrint(' - user == null: ${userState.user == null}');
|
||||
debugPrint(' - token == null: ${userState.user?.token == null}');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
@@ -31,7 +81,7 @@ class RobotHeaderCard extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
robot['name'] as String,
|
||||
widget.robot['name'] as String,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
@@ -40,7 +90,7 @@ class RobotHeaderCard extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'ID: ${robot['id']}',
|
||||
'ID: ${widget.robot['id']}',
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Color(0xFF86909C),
|
||||
@@ -92,14 +142,81 @@ class RobotHeaderCard extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
// 机器人图片
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Image.asset(
|
||||
'assets/images/xunjian.png',
|
||||
height: 180,
|
||||
width: double.infinity,
|
||||
fit: BoxFit.cover,
|
||||
// 🔥 视频展示区域(替换原来的静态图片)
|
||||
AspectRatio(
|
||||
aspectRatio: 16 / 9,
|
||||
child: Container(
|
||||
color: Colors.black, // 🔥 强制整个视频区域为黑色背景
|
||||
child: _videoStreamUrl.isNotEmpty
|
||||
? WebRTCLocalPlayer(
|
||||
streamUrl: _videoStreamUrl,
|
||||
showLeftPip: false, // 不显示悬浮小窗
|
||||
showRightPip: false,
|
||||
isFrontMain: _currentViewIndex == 0, // 根据当前视角决定主画面
|
||||
)
|
||||
: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.videocam_off, size: 48, color: Colors.white54),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'无视频信号',
|
||||
style: TextStyle(color: Colors.white70, fontSize: 14, fontWeight: FontWeight.w500),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// 🔥 视角切换按钮
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(0, 12, 0, 0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: _viewConfigs.asMap().entries.map((entry) {
|
||||
final index = entry.key;
|
||||
final config = entry.value;
|
||||
final isSelected = _currentViewIndex == index;
|
||||
|
||||
return Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 2),
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_currentViewIndex = index;
|
||||
});
|
||||
debugPrint('🎬 [RobotHeaderCard] 切换视角: ${config['name']}');
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: isSelected ? const Color(0xFF165DFF) : Colors.grey[200],
|
||||
foregroundColor: isSelected ? Colors.white : Colors.grey[700],
|
||||
elevation: 0,
|
||||
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 4),
|
||||
minimumSize: const Size(0, 36),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(config['icon'] as IconData, size: 16),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
config['name'] as String,
|
||||
style: const TextStyle(fontSize: 10),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
||||
class RobotItemCard extends StatelessWidget {
|
||||
final String name;
|
||||
final String id;
|
||||
final String? alias; // 设备别名
|
||||
final String type; // 机器人类型:巡检机器人、清洗机器人、除草机器人
|
||||
final String status;
|
||||
final double battery;
|
||||
@@ -14,6 +15,7 @@ class RobotItemCard extends StatelessWidget {
|
||||
super.key,
|
||||
required this.name,
|
||||
required this.id,
|
||||
this.alias,
|
||||
required this.type,
|
||||
required this.status,
|
||||
required this.battery,
|
||||
@@ -81,7 +83,7 @@ class RobotItemCard extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'ID: $id',
|
||||
alias != null && alias!.isNotEmpty ? '别名: $alias' : 'ID: $id',
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Color(0xFF86909C),
|
||||
|
||||
Reference in New Issue
Block a user