1优化改动设备栏中全部标签栏的设备列表中数据的整合,又数据合并解耦成使用已有组件各自维护,使其样式和逻辑一致。
2接入了无人机机场的实时信息和无人机的实时信息,并创建了对应的组件,并测试。 3.实现了机器人的详情页的视频显示的逻辑为当机器人在线,就在下方同步出来机器人的各个方位视频,并且支持切换。 4.实现了全部设备中对类型的区分和实现了点击进入对应的详情页。 5.修复了部分bug,优化了代码结构,提高了代码的可读性和可维护性。 6更改了机器人列表项中的信息展示为机器序列号和别名和id(优先展示别名) 7.更改了无人机场的信息展示上位 无人机及序列号下位机场序列号。 8优化了无人机机场信息只能是的为明文展示。便于观看理解。
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:maibu_satabot_v2/core/app/app_user_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
import 'package:maibu_satabot_v2/core/consts/tcp_consts.dart';
|
||||
import 'package:maibu_satabot_v2/core/router/route_paths.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/entities/device_entity.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/presentation/bloc/devices_cubit.dart';
|
||||
@@ -11,6 +12,7 @@ import 'package:maibu_satabot_v2/features/devices/presentation/bloc/devices_stat
|
||||
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'; // 🔥 添加 RemoteControlCubit
|
||||
import 'package:maibu_satabot_v2/features/remote_control/presentation/widgets/webrtc/webrtc_local_player.dart';
|
||||
|
||||
class MachineDetailsPage extends StatefulWidget {
|
||||
final DeviceEntity? device;
|
||||
@@ -34,6 +36,19 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
// 🔥 保存 stream 引用,避免每次 rebuild 都重新获取
|
||||
late Stream<DeviceStatusState> _deviceStatusStream;
|
||||
late DeviceStatusState _initialState;
|
||||
|
||||
// 🔥 新增:视频相关状态
|
||||
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() {
|
||||
@@ -47,6 +62,30 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
_deviceStatusStream = bloc.stream;
|
||||
_initialState = bloc.state;
|
||||
debugPrint('📦 [MachineDetails] initState - 初始状态: ${_initialState.runtimeType}');
|
||||
|
||||
// 🔥 初始化视频 URL
|
||||
_initVideoUrl();
|
||||
}
|
||||
|
||||
/// 🔥 初始化视频流 URL
|
||||
void _initVideoUrl() {
|
||||
final userState = context.read<AppUserCubit>().state;
|
||||
debugPrint('🎬 [MachineDetails] 开始初始化视频URL');
|
||||
debugPrint('🎬 [MachineDetails] deviceId: $_deviceId');
|
||||
debugPrint('🎬 [MachineDetails] user: ${userState.user}');
|
||||
debugPrint('🎬 [MachineDetails] token: ${userState.user?.token}');
|
||||
|
||||
if (_deviceId.isNotEmpty && userState.user != null && userState.user!.token != null) {
|
||||
setState(() {
|
||||
_videoStreamUrl = "webrtc://${TCPConsts.TCP_IP}/live/livestream/$_deviceId?token=${userState.user!.token}";
|
||||
});
|
||||
debugPrint('✅ [MachineDetails] 视频URL初始化成功: $_videoStreamUrl');
|
||||
} else {
|
||||
debugPrint('❌ [MachineDetails] 视频URL初始化失败');
|
||||
debugPrint(' - deviceId.isEmpty: ${_deviceId.isEmpty}');
|
||||
debugPrint(' - user == null: ${userState.user == null}');
|
||||
debugPrint(' - token == null: ${userState.user?.token == null}');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -292,10 +331,9 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
);
|
||||
}
|
||||
|
||||
/// 设备状态卡片(保持不变)
|
||||
/// 设备状态卡片(🔥 修改为视频展示 + 视角切换)
|
||||
Widget _buildDeviceStatusCard(DeviceEntity device) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(24),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
@@ -303,24 +341,112 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Image.asset(
|
||||
'assets/images/car.png',
|
||||
width: 300,
|
||||
fit: BoxFit.contain,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return const Icon(Icons.device_hub, size: 100, color: Colors.grey);
|
||||
},
|
||||
// 🔥 视频展示区域
|
||||
AspectRatio(
|
||||
aspectRatio: 16 / 9,
|
||||
child: _videoStreamUrl.isNotEmpty
|
||||
? WebRTCLocalPlayer(
|
||||
streamUrl: _videoStreamUrl,
|
||||
showLeftPip: false, // 不显示悬浮小窗
|
||||
showRightPip: false,
|
||||
isFrontMain: _currentViewIndex == 0, // 根据当前视角决定主画面
|
||||
)
|
||||
: Container(
|
||||
color: Colors.black87,
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.videocam_off, size: 64, color: Colors.white54),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'视频未加载',
|
||||
style: TextStyle(color: Colors.white70, fontSize: 16, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'deviceId: $_deviceId',
|
||||
style: TextStyle(color: Colors.white54, fontSize: 12),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'URL: ${_videoStreamUrl.isEmpty ? "空" : "已设置"}',
|
||||
style: TextStyle(color: Colors.white54, fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: device.isOnline ? const Color(0xFF00C853).withOpacity(0.1) : const Color(0xFF999999).withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
|
||||
// 🔥 在线状态标签
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: device.isOnline ? const Color(0xFF00C853).withOpacity(0.1) : const Color(0xFF999999).withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
device.isOnline ? AppLocalizations.of(context).translate('home.device_online') : AppLocalizations.of(context).translate('home.device_offline'),
|
||||
style: TextStyle(fontSize: 14, color: device.isOnline ? const Color(0xFF00C853) : const Color(0xFF999999)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Text(
|
||||
device.isOnline ? AppLocalizations.of(context).translate('home.device_online') : AppLocalizations.of(context).translate('home.device_offline'),
|
||||
style: TextStyle(fontSize: 14, color: device.isOnline ? const Color(0xFF00C853) : const Color(0xFF999999)),
|
||||
),
|
||||
|
||||
// 🔥 视角切换按钮
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(12, 0, 12, 12),
|
||||
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('🎬 [MachineDetails] 切换视角: ${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(),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user