对接路径规划的列表(根据场站的下的)
优化无人机机场的监控视频的显示视频流畅度提升80% 添加首页tcp指示灯的机器状态信息展示功能。(暂不支持在此页面上设备的切换显示)
This commit is contained in:
@@ -4,10 +4,12 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../../../../core/di/injection.dart';
|
||||
import '../../../../../core/app/app_user_cubit.dart';
|
||||
import '../../../../../components/tcp_status_indicator.dart';
|
||||
import '../../../../../components/device_status_modal.dart';
|
||||
import '../../../../v2/site/presentation/cubit/site_cubit.dart';
|
||||
import '../bloc/device_status_bloc.dart';
|
||||
import '../bloc/device_status_event.dart';
|
||||
import '../bloc/device_status_state.dart';
|
||||
import '../bloc/device_status_bloc.dart' as DeviceListBloc;
|
||||
import '../bloc/device_status_event.dart' as DeviceListEvent;
|
||||
import '../bloc/device_status_state.dart' as DeviceListState;
|
||||
import 'package:maibu_satabot_v2/features/devices/presentation/bloc/device_status_bloc.dart';
|
||||
import '../bloc/drone_station_bloc.dart';
|
||||
import '../bloc/drone_station_event.dart';
|
||||
import '../bloc/drone_station_state.dart';
|
||||
@@ -27,7 +29,8 @@ class DeviceStatusPage extends StatelessWidget {
|
||||
|
||||
return BlocProvider(
|
||||
create: (_) =>
|
||||
sl<DeviceStatusBloc>()..add(DeviceStatusLoadData(siteId: siteId)),
|
||||
sl<DeviceListBloc.DeviceStatusBloc>()
|
||||
..add(DeviceListEvent.DeviceStatusLoadData(siteId: siteId)),
|
||||
child: const DeviceStatusView(),
|
||||
);
|
||||
}
|
||||
@@ -47,24 +50,28 @@ class DeviceStatusView extends StatelessWidget {
|
||||
child: Scaffold(
|
||||
backgroundColor: const Color(0xFFF7F7F7),
|
||||
body: SafeArea(
|
||||
child: BlocBuilder<DeviceStatusBloc, DeviceStatusState>(
|
||||
builder: (context, state) {
|
||||
return Column(
|
||||
children: [
|
||||
_buildAppBar(),
|
||||
_buildSearchBar(context),
|
||||
_buildTypeFilterBar(context),
|
||||
Expanded(child: _buildContent(context, state)),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
child:
|
||||
BlocBuilder<
|
||||
DeviceListBloc.DeviceStatusBloc,
|
||||
DeviceListState.DeviceStatusState
|
||||
>(
|
||||
builder: (context, state) {
|
||||
return Column(
|
||||
children: [
|
||||
_buildAppBar(context),
|
||||
_buildSearchBar(context),
|
||||
_buildTypeFilterBar(context),
|
||||
Expanded(child: _buildContent(context, state)),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAppBar() {
|
||||
Widget _buildAppBar(BuildContext context) {
|
||||
return Container(
|
||||
height: 44.0,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
@@ -92,7 +99,10 @@ class DeviceStatusView extends StatelessWidget {
|
||||
shape: BoxShape.circle,
|
||||
color: Colors.blue.withOpacity(0.1),
|
||||
),
|
||||
child: const TcpStatusIndicator(size: 12),
|
||||
child: TcpStatusIndicator(
|
||||
size: 12,
|
||||
onTap: () => _showDeviceStatusModal(context),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -148,7 +158,9 @@ class DeviceStatusView extends StatelessWidget {
|
||||
style: const TextStyle(fontSize: 14, color: Color(0xFF1D2129)),
|
||||
onSubmitted: (value) {
|
||||
// 🔥 点击键盘确定键时触发搜索
|
||||
context.read<DeviceStatusBloc>().add(DeviceStatusSearch(value));
|
||||
context.read<DeviceListBloc.DeviceStatusBloc>().add(
|
||||
DeviceListEvent.DeviceStatusSearch(value),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
@@ -157,10 +169,13 @@ class DeviceStatusView extends StatelessWidget {
|
||||
Widget _buildTypeFilterBar(BuildContext context) {
|
||||
final types = ['全部', '机器人', '无人机机场', '逆变器', '汇流箱', '组件', '监控'];
|
||||
|
||||
return BlocBuilder<DeviceStatusBloc, DeviceStatusState>(
|
||||
return BlocBuilder<
|
||||
DeviceListBloc.DeviceStatusBloc,
|
||||
DeviceListState.DeviceStatusState
|
||||
>(
|
||||
builder: (context, state) {
|
||||
String selectedType = '全部';
|
||||
if (state is DeviceStatusLoaded) {
|
||||
if (state is DeviceListState.DeviceStatusLoaded) {
|
||||
selectedType = state.selectedType;
|
||||
}
|
||||
|
||||
@@ -178,8 +193,8 @@ class DeviceStatusView extends StatelessWidget {
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
context.read<DeviceStatusBloc>().add(
|
||||
DeviceStatusChangeType(type),
|
||||
context.read<DeviceListBloc.DeviceStatusBloc>().add(
|
||||
DeviceListEvent.DeviceStatusChangeType(type),
|
||||
);
|
||||
},
|
||||
child: Column(
|
||||
@@ -219,14 +234,19 @@ class DeviceStatusView extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildContent(BuildContext context, DeviceStatusState state) {
|
||||
Widget _buildContent(
|
||||
BuildContext context,
|
||||
DeviceListState.DeviceStatusState state,
|
||||
) {
|
||||
// 如果选择的是"机器人",显示机器人专属页面
|
||||
if (state is DeviceStatusLoaded && state.selectedType == '机器人') {
|
||||
if (state is DeviceListState.DeviceStatusLoaded &&
|
||||
state.selectedType == '机器人') {
|
||||
return const RobotListPage();
|
||||
}
|
||||
|
||||
// 如果选择的是"无人机机场",显示机场列表
|
||||
if (state is DeviceStatusLoaded && state.selectedType == '无人机机场') {
|
||||
if (state is DeviceListState.DeviceStatusLoaded &&
|
||||
state.selectedType == '无人机机场') {
|
||||
return _buildDroneStationList(context);
|
||||
}
|
||||
|
||||
@@ -234,14 +254,17 @@ class DeviceStatusView extends StatelessWidget {
|
||||
return _buildDeviceList(context, state);
|
||||
}
|
||||
|
||||
Widget _buildDeviceList(BuildContext context, DeviceStatusState state) {
|
||||
if (state is DeviceStatusLoading) {
|
||||
Widget _buildDeviceList(
|
||||
BuildContext context,
|
||||
DeviceListState.DeviceStatusState state,
|
||||
) {
|
||||
if (state is DeviceListState.DeviceStatusLoading) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(color: Color(0xFF165DFF)),
|
||||
);
|
||||
}
|
||||
|
||||
if (state is DeviceStatusError) {
|
||||
if (state is DeviceListState.DeviceStatusError) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
@@ -255,8 +278,8 @@ class DeviceStatusView extends StatelessWidget {
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
context.read<DeviceStatusBloc>().add(
|
||||
const DeviceStatusLoadData(),
|
||||
context.read<DeviceListBloc.DeviceStatusBloc>().add(
|
||||
const DeviceListEvent.DeviceStatusLoadData(),
|
||||
);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
@@ -270,7 +293,7 @@ class DeviceStatusView extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
if (state is DeviceStatusLoaded) {
|
||||
if (state is DeviceListState.DeviceStatusLoaded) {
|
||||
// 🔥 先根据类型过滤
|
||||
List filteredByType = state.devices;
|
||||
if (state.selectedType != '全部') {
|
||||
@@ -292,7 +315,9 @@ class DeviceStatusView extends StatelessWidget {
|
||||
|
||||
return RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
context.read<DeviceStatusBloc>().add(const DeviceStatusRefresh());
|
||||
context.read<DeviceListBloc.DeviceStatusBloc>().add(
|
||||
const DeviceListEvent.DeviceStatusRefresh(),
|
||||
);
|
||||
},
|
||||
color: const Color(0xFF165DFF),
|
||||
child: ListView(
|
||||
@@ -441,7 +466,7 @@ class DeviceStatusView extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatusCard(DeviceStatusLoaded state) {
|
||||
Widget _buildStatusCard(DeviceListState.DeviceStatusLoaded state) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
@@ -533,4 +558,25 @@ class DeviceStatusView extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 显示设备状态模态框 - 从底部滑出
|
||||
void _showDeviceStatusModal(BuildContext context) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(16),
|
||||
topRight: Radius.circular(16),
|
||||
),
|
||||
),
|
||||
builder: (BuildContext context) {
|
||||
return BlocProvider.value(
|
||||
value: context.read<DeviceStatusBloc>(),
|
||||
child: const DeviceStatusModal(),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,26 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../domain/entities/flight_task_entity.dart';
|
||||
|
||||
/// 无人机任务与航线控制页面
|
||||
class DroneMissionControlPage extends StatelessWidget {
|
||||
const DroneMissionControlPage({super.key});
|
||||
class DroneMissionControlPage extends StatefulWidget {
|
||||
final List<FlightTaskEntity>? selectedTasks;
|
||||
|
||||
const DroneMissionControlPage({super.key, this.selectedTasks});
|
||||
|
||||
@override
|
||||
State<DroneMissionControlPage> createState() => _DroneMissionControlPageState();
|
||||
}
|
||||
|
||||
class _DroneMissionControlPageState extends State<DroneMissionControlPage> {
|
||||
FlightTaskEntity? _currentTask;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (widget.selectedTasks != null && widget.selectedTasks!.isNotEmpty) {
|
||||
_currentTask = widget.selectedTasks!.first;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -78,44 +96,104 @@ class DroneMissionControlPage extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildInfoRow('任务名称', '逆变器区巡检任务'),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
_buildInfoColumn('任务编号', 'UAV-2025052001'),
|
||||
const Spacer(),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF165DFF).withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: const Text(
|
||||
'进行中',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Color(0xFF165DFF),
|
||||
fontWeight: FontWeight.w500,
|
||||
if (_currentTask != null) ...[
|
||||
_buildInfoRow('任务名称', _currentTask!.name),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
_buildInfoColumn('任务ID', _currentTask!.uuid.substring(0, 8)),
|
||||
const Spacer(),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: _getStatusColor(_currentTask!.status).withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
_currentTask!.status,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: _getStatusColor(_currentTask!.status),
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoRow('巡检区域', '逆变器区A区'),
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoRow('飞行高度', '80 m'),
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoRow('飞行速度', '8.0 m/s'),
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoRow('预计时长', '26 min'),
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoRow('电量预估', '68% (可飞行 22 min)'),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoRow('设备序列号', _currentTask!.sn),
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoRow('任务类型', _currentTask!.taskType),
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoRow('开始时间', _formatDateTime(_currentTask!.beginAt)),
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoRow('结束时间', _formatDateTime(_currentTask!.endAt)),
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoRow('航点数量', '${_currentTask!.totalWaypoints}'),
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoRow('媒体上传', _currentTask!.mediaUploadStatus),
|
||||
] else ...[
|
||||
_buildInfoRow('任务名称', '逆变器区巡检任务'),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
_buildInfoColumn('任务编号', 'UAV-2025052001'),
|
||||
const Spacer(),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF165DFF).withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: const Text(
|
||||
'进行中',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Color(0xFF165DFF),
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoRow('巡检区域', '逆变器区A区'),
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoRow('飞行高度', '80 m'),
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoRow('飞行速度', '8.0 m/s'),
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoRow('预计时长', '26 min'),
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoRow('电量预估', '68% (可飞行 22 min)'),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Color _getStatusColor(String status) {
|
||||
switch (status.toLowerCase()) {
|
||||
case 'success':
|
||||
return const Color(0xFF00B42A);
|
||||
case 'failed':
|
||||
return const Color(0xFFF53F3F);
|
||||
case 'running':
|
||||
return const Color(0xFF165DFF);
|
||||
default:
|
||||
return const Color(0xFF86909C);
|
||||
}
|
||||
}
|
||||
|
||||
String _formatDateTime(String dateTimeStr) {
|
||||
try {
|
||||
final dateTime = DateTime.parse(dateTimeStr);
|
||||
return '${dateTime.year}-${dateTime.month.toString().padLeft(2, '0')}-${dateTime.day.toString().padLeft(2, '0')} ${dateTime.hour.toString().padLeft(2, '0')}:${dateTime.minute.toString().padLeft(2, '0')}';
|
||||
} catch (e) {
|
||||
return dateTimeStr;
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildRouteMap() {
|
||||
return Container(
|
||||
height: 200,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,4 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:volc_engine_rtc/volc_engine_rtc.dart' as volc;
|
||||
@@ -11,6 +12,7 @@ import '../bloc/drone_station_state.dart';
|
||||
import 'drone_video_control_page.dart';
|
||||
import 'drone_mission_control_page.dart';
|
||||
import 'drone_monitor_page.dart';
|
||||
import '../widgets/flight_task_selector_modal.dart';
|
||||
|
||||
// SDK 类型枚举
|
||||
enum RtcSdkType { volcengine, agora }
|
||||
@@ -47,6 +49,10 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
// Agora RTC
|
||||
agora.RtcEngine? _floatingAgoraEngine;
|
||||
|
||||
// 加载超时计时器
|
||||
Timer? _floatingLoadingTimer;
|
||||
static const _floatingLoadingTimeout = Duration(seconds: 15);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -63,6 +69,7 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
void dispose() {
|
||||
_bloc.close();
|
||||
_destroyFloatingRtcEngine();
|
||||
_floatingLoadingTimer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -125,11 +132,13 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
listener: (context, state) {
|
||||
// 监听视频流加载状态
|
||||
if (state is VideoStreamLoaded) {
|
||||
_floatingLoadingTimer?.cancel();
|
||||
setState(() {
|
||||
_floatingVideoStream = state.videoStream;
|
||||
});
|
||||
_initFloatingRtcEngine();
|
||||
} else if (state is VideoStreamError) {
|
||||
_floatingLoadingTimer?.cancel();
|
||||
setState(() {
|
||||
_floatingErrorMessage = state.message;
|
||||
_isFloatingLoading = false;
|
||||
@@ -518,12 +527,7 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
label: '任务下发',
|
||||
color: const Color(0xFF165DFF),
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const DroneMissionControlPage(),
|
||||
),
|
||||
);
|
||||
_showFlightTaskSelector();
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -535,6 +539,16 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
}
|
||||
|
||||
void _goToMonitor() {
|
||||
// 从当前状态中获取摄像头索引
|
||||
final currentState = _bloc.state;
|
||||
String cameraIndex = '165-0-7'; // 默认值
|
||||
|
||||
if (currentState is UAVDetailLoaded &&
|
||||
currentState.detail.gatewayCameraList != null &&
|
||||
currentState.detail.gatewayCameraList!.isNotEmpty) {
|
||||
cameraIndex = currentState.detail.gatewayCameraList!.first.cameraIndex;
|
||||
}
|
||||
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
shape: const RoundedRectangleBorder(
|
||||
@@ -559,7 +573,7 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
MaterialPageRoute(
|
||||
builder: (context) => DroneMonitorPage(
|
||||
gatewaySn: widget.station.gatewaySn,
|
||||
cameraIndex: '165-0-7',
|
||||
cameraIndex: cameraIndex,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -589,36 +603,37 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
_loadFloatingVideoStream();
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF2F3F5),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: const Row(
|
||||
children: [
|
||||
Icon(Icons.picture_in_picture, color: Color(0xFF165DFF)),
|
||||
SizedBox(width: 16),
|
||||
Text(
|
||||
'悬浮观看',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: Color(0xFF1D2129),
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
Spacer(),
|
||||
Icon(Icons.arrow_forward_ios, color: Color(0xFF86909C)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// 悬浮观看功能已禁用
|
||||
// GestureDetector(
|
||||
// onTap: () {
|
||||
// Navigator.pop(context);
|
||||
// _loadFloatingVideoStream();
|
||||
// },
|
||||
// child: Container(
|
||||
// padding: const EdgeInsets.all(16),
|
||||
// decoration: BoxDecoration(
|
||||
// color: const Color(0xFFF2F3F5),
|
||||
// borderRadius: BorderRadius.circular(12),
|
||||
// ),
|
||||
// child: const Row(
|
||||
// children: [
|
||||
// Icon(Icons.picture_in_picture, color: Color(0xFF165DFF)),
|
||||
// SizedBox(width: 16),
|
||||
// Text(
|
||||
// '悬浮观看',
|
||||
// style: TextStyle(
|
||||
// fontSize: 16,
|
||||
// color: Color(0xFF1D2129),
|
||||
// fontWeight: FontWeight.w500,
|
||||
// ),
|
||||
// ),
|
||||
// Spacer(),
|
||||
// Icon(Icons.arrow_forward_ios, color: Color(0xFF86909C)),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// const SizedBox(height: 16),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -626,6 +641,46 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
);
|
||||
}
|
||||
|
||||
// 显示飞行任务选择器
|
||||
void _showFlightTaskSelector() {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (context) {
|
||||
return DraggableScrollableSheet(
|
||||
expand: false,
|
||||
initialChildSize: 0.7,
|
||||
minChildSize: 0.5,
|
||||
maxChildSize: 0.95,
|
||||
builder: (context, scrollController) {
|
||||
return Container(
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
|
||||
),
|
||||
child: FlightTaskSelectorModal(
|
||||
currentGatewaySn: widget.station.gatewaySn,
|
||||
onTaskSelected: (tasks) {
|
||||
if (tasks.isNotEmpty) {
|
||||
Navigator.pop(context);
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
DroneMissionControlPage(selectedTasks: tasks),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// 悬浮视频监控组件
|
||||
Widget _buildFloatingMonitor() {
|
||||
if (!showFloatingMonitor) return const SizedBox();
|
||||
@@ -858,6 +913,18 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
|
||||
// 加载悬浮视频流
|
||||
void _loadFloatingVideoStream() {
|
||||
_floatingLoadingTimer?.cancel();
|
||||
|
||||
// 从当前状态中获取摄像头索引
|
||||
final currentState = _bloc.state;
|
||||
String cameraIndex = '165-0-7'; // 默认值
|
||||
|
||||
if (currentState is UAVDetailLoaded &&
|
||||
currentState.detail.gatewayCameraList != null &&
|
||||
currentState.detail.gatewayCameraList!.isNotEmpty) {
|
||||
cameraIndex = currentState.detail.gatewayCameraList!.first.cameraIndex;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isFloatingLoading = true;
|
||||
_floatingErrorMessage = null;
|
||||
@@ -866,10 +933,22 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
|
||||
_destroyFloatingRtcEngine();
|
||||
|
||||
// 设置加载超时计时器
|
||||
_floatingLoadingTimer = Timer(_floatingLoadingTimeout, () {
|
||||
if (!mounted) return;
|
||||
if (_isFloatingLoading) {
|
||||
debugPrint('⚠️ 悬浮窗视频加载超时');
|
||||
setState(() {
|
||||
_isFloatingLoading = false;
|
||||
_floatingErrorMessage = '视频加载超时,请检查网络连接或点击刷新重试';
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
_bloc.add(
|
||||
VideoStreamLoad(
|
||||
sn: widget.station.gatewaySn,
|
||||
cameraIndex: '165-0-7',
|
||||
cameraIndex: cameraIndex,
|
||||
cameraPosition: isFloatingIndoor ? 'indoor' : 'outdoor',
|
||||
),
|
||||
);
|
||||
@@ -1007,6 +1086,11 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
_isFloatingLoading = false;
|
||||
});
|
||||
},
|
||||
onConnectionStateChanged: (state, reason) {
|
||||
debugPrint(
|
||||
'Volc 悬浮窗 Connection State Changed: $state, reason: $reason',
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
_floatingRtcEngine = await volc.RTCEngine.createRTCEngine(
|
||||
|
||||
@@ -0,0 +1,318 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import '../../../../../core/consts/http_api_consts.dart';
|
||||
import '../../domain/entities/flight_task_entity.dart';
|
||||
|
||||
class FlightTaskSelectorModal extends StatefulWidget {
|
||||
final String currentGatewaySn;
|
||||
final Function(List<FlightTaskEntity>) onTaskSelected;
|
||||
|
||||
const FlightTaskSelectorModal({
|
||||
super.key,
|
||||
required this.currentGatewaySn,
|
||||
required this.onTaskSelected,
|
||||
});
|
||||
|
||||
@override
|
||||
State<FlightTaskSelectorModal> createState() => _FlightTaskSelectorModalState();
|
||||
}
|
||||
|
||||
class _FlightTaskSelectorModalState extends State<FlightTaskSelectorModal> {
|
||||
DateTimeRange? _selectedDateRange;
|
||||
String? _selectedDeviceSn;
|
||||
Map<String, List<FlightTaskEntity>?> _taskData = {};
|
||||
bool _isLoading = false;
|
||||
String? _errorMessage;
|
||||
final Dio _dio = Dio();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_selectedDeviceSn = widget.currentGatewaySn;
|
||||
_setDefaultDateRange();
|
||||
}
|
||||
|
||||
void _setDefaultDateRange() {
|
||||
final now = DateTime.now();
|
||||
final todayStart = DateTime(now.year, now.month, now.day);
|
||||
final todayEnd = DateTime(now.year, now.month, now.day, 23, 59, 59);
|
||||
_selectedDateRange = DateTimeRange(start: todayStart, end: todayEnd);
|
||||
}
|
||||
|
||||
Future<void> _selectDateRange(BuildContext context) async {
|
||||
final picked = await showDateRangePicker(
|
||||
context: context,
|
||||
firstDate: DateTime(2020),
|
||||
lastDate: DateTime(2030),
|
||||
initialDateRange: _selectedDateRange,
|
||||
);
|
||||
if (picked != null) {
|
||||
setState(() {
|
||||
_selectedDateRange = picked;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadTasks() async {
|
||||
if (_selectedDateRange == null || _selectedDeviceSn == null) {
|
||||
setState(() {
|
||||
_errorMessage = '请选择时间和设备';
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
_errorMessage = null;
|
||||
});
|
||||
|
||||
try {
|
||||
final beginAt = _selectedDateRange!.start.millisecondsSinceEpoch ~/ 1000;
|
||||
final endAt = _selectedDateRange!.end.millisecondsSinceEpoch ~/ 1000;
|
||||
|
||||
final response = await _dio.post(
|
||||
HttpApiConsts.getFlightTask,
|
||||
data: {
|
||||
'sns': [_selectedDeviceSn!],
|
||||
'beginAt': beginAt,
|
||||
'endAt': endAt,
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('网络请求失败');
|
||||
}
|
||||
|
||||
final responseData = response.data;
|
||||
|
||||
if (responseData['code'] != 200) {
|
||||
throw Exception(responseData['msg'] ?? '业务异常');
|
||||
}
|
||||
|
||||
final data = responseData['data'] as Map<String, dynamic>;
|
||||
final result = <String, List<FlightTaskEntity>?>{};
|
||||
|
||||
data.forEach((sn, value) {
|
||||
if (value != null && value['list'] != null) {
|
||||
final list = value['list'] as List<dynamic>;
|
||||
result[sn] = list.map((item) => FlightTaskEntity.fromJson(item)).toList();
|
||||
} else {
|
||||
result[sn] = null;
|
||||
}
|
||||
});
|
||||
|
||||
setState(() {
|
||||
_taskData = result;
|
||||
_isLoading = false;
|
||||
});
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
_errorMessage = '加载失败: $e';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text(
|
||||
'选择飞行任务',
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
_buildTimeSelector(),
|
||||
const SizedBox(height: 12),
|
||||
_buildDeviceSelector(),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: _isLoading ? null : _loadTasks,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF165DFF),
|
||||
minimumSize: const Size(double.infinity, 48),
|
||||
),
|
||||
child: _isLoading
|
||||
? const CircularProgressIndicator(color: Colors.white)
|
||||
: const Text('查询任务'),
|
||||
),
|
||||
if (_errorMessage != null) ...[
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
_errorMessage!,
|
||||
style: const TextStyle(color: Color(0xFFF53F3F)),
|
||||
),
|
||||
],
|
||||
if (_taskData.isNotEmpty) ...[
|
||||
const SizedBox(height: 16),
|
||||
Flexible(
|
||||
child: _buildTaskList(),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTimeSelector() {
|
||||
return GestureDetector(
|
||||
onTap: () => _selectDateRange(context),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF2F3F5),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.calendar_today, color: Color(0xFF86909C)),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
_selectedDateRange != null
|
||||
? '${_formatDate(_selectedDateRange!.start)} - ${_formatDate(_selectedDateRange!.end)}'
|
||||
: '选择时间范围',
|
||||
style: const TextStyle(fontSize: 14),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDeviceSelector() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF2F3F5),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.devices, color: Color(0xFF86909C)),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
_selectedDeviceSn ?? '未知设备',
|
||||
style: const TextStyle(fontSize: 14),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTaskList() {
|
||||
final tasks = _taskData[_selectedDeviceSn];
|
||||
|
||||
if (tasks == null || tasks.isEmpty) {
|
||||
return const Center(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(32),
|
||||
child: Text('暂无任务数据'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: tasks.length,
|
||||
itemBuilder: (context, index) {
|
||||
final task = tasks[index];
|
||||
return _buildTaskItem(task);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTaskItem(FlightTaskEntity task) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
widget.onTaskSelected([task]);
|
||||
},
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(bottom: 8),
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: const Color(0xFFE5E6EB)),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
task.name,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
'类型: ${task.taskType}',
|
||||
style: const TextStyle(fontSize: 12, color: Color(0xFF86909C)),
|
||||
),
|
||||
const Spacer(),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: _getStatusColor(task.status).withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
task.status,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: _getStatusColor(task.status),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'开始: ${_formatDateTime(task.beginAt)}',
|
||||
style: const TextStyle(fontSize: 12, color: Color(0xFF86909C)),
|
||||
),
|
||||
Text(
|
||||
'结束: ${_formatDateTime(task.endAt)}',
|
||||
style: const TextStyle(fontSize: 12, color: Color(0xFF86909C)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Color _getStatusColor(String status) {
|
||||
switch (status.toLowerCase()) {
|
||||
case 'success':
|
||||
return const Color(0xFF00B42A);
|
||||
case 'failed':
|
||||
return const Color(0xFFF53F3F);
|
||||
case 'running':
|
||||
return const Color(0xFF165DFF);
|
||||
default:
|
||||
return const Color(0xFF86909C);
|
||||
}
|
||||
}
|
||||
|
||||
String _formatDate(DateTime date) {
|
||||
return '${date.year}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')}';
|
||||
}
|
||||
|
||||
String _formatDateTime(String dateTimeStr) {
|
||||
try {
|
||||
final dateTime = DateTime.parse(dateTimeStr);
|
||||
return '${dateTime.year}-${dateTime.month.toString().padLeft(2, '0')}-${dateTime.day.toString().padLeft(2, '0')} ${dateTime.hour.toString().padLeft(2, '0')}:${dateTime.minute.toString().padLeft(2, '0')}';
|
||||
} catch (e) {
|
||||
return dateTimeStr;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user