一次大的提交
This commit is contained in:
@@ -0,0 +1,429 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:maibu_satabot_v2/core/di/injection.dart';
|
||||
|
||||
import '../cubit/bind_device_cubit.dart';
|
||||
import '../cubit/bind_device_state.dart';
|
||||
|
||||
class BindDevicePage extends StatefulWidget {
|
||||
final String scanResult;
|
||||
|
||||
const BindDevicePage({super.key, required this.scanResult});
|
||||
|
||||
@override
|
||||
State<BindDevicePage> createState() => _BindDevicePageState();
|
||||
}
|
||||
|
||||
class _BindDevicePageState extends State<BindDevicePage> {
|
||||
late final BindDeviceCubit _cubit;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_cubit = sl<BindDeviceCubit>();
|
||||
_cubit.init();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (_) => _cubit,
|
||||
child: BlocListener<BindDeviceCubit, BindDeviceState>(
|
||||
listener: (context, state) {
|
||||
if (state.errorMessage != null && state.errorMessage!.isNotEmpty) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(state.errorMessage!)));
|
||||
}
|
||||
if (state.isSuccess) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('绑定成功')));
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
backgroundColor: const Color(0xFFF5F6F8),
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
leading: IconButton(
|
||||
icon: const Icon(
|
||||
Icons.arrow_back_ios,
|
||||
color: Color(0xFF1D2129),
|
||||
size: 20,
|
||||
),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
title: const Text(
|
||||
'绑定智能装备',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF1D2129),
|
||||
),
|
||||
),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: BlocBuilder<BindDeviceCubit, BindDeviceState>(
|
||||
builder: (context, state) {
|
||||
if (state.isLoading) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(color: Color(0xFF165DFF)),
|
||||
);
|
||||
}
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: const [
|
||||
BoxShadow(
|
||||
color: Color(0x0D000000),
|
||||
blurRadius: 8,
|
||||
offset: Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildRequiredField(
|
||||
label: '已选装备 ID',
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
vertical: 14,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF7F8FA),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(
|
||||
color: const Color(0xFFE5E6EB),
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
widget.scanResult,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: Color(0xFF1D2129),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildRequiredField(
|
||||
label: '所属组织',
|
||||
child: _buildOrgDropdown(state),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildField(
|
||||
label: '所属场站',
|
||||
child: _buildSiteDropdown(state),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildField(
|
||||
label: '负责人',
|
||||
child: _buildUserDropdown(state),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: SizedBox(
|
||||
height: 44,
|
||||
child: OutlinedButton(
|
||||
onPressed: state.isSubmitting
|
||||
? null
|
||||
: () => Navigator.of(context).pop(),
|
||||
style: OutlinedButton.styleFrom(
|
||||
side: const BorderSide(
|
||||
color: Color(0xFFE5E6EB),
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: const Text(
|
||||
'取消',
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
color: Color(0xFF4E5969),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: SizedBox(
|
||||
height: 44,
|
||||
child: ElevatedButton(
|
||||
onPressed: state.isSubmitting
|
||||
? null
|
||||
: _handleSubmit,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF165DFF),
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: state.isSubmitting
|
||||
? const SizedBox(
|
||||
height: 20,
|
||||
width: 20,
|
||||
child: CircularProgressIndicator(
|
||||
color: Colors.white,
|
||||
strokeWidth: 2,
|
||||
),
|
||||
)
|
||||
: const Text(
|
||||
'确定',
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildOrgDropdown(BindDeviceState state) {
|
||||
final enabled = _cubit.isOrgEnabled;
|
||||
final selectedName = state.selectedOrgId != null
|
||||
? state.orgList
|
||||
.where((org) => org.id == state.selectedOrgId)
|
||||
.fold<String?>(null, (_, org) => org.name)
|
||||
: null;
|
||||
|
||||
if (!enabled && selectedName != null) {
|
||||
return _buildReadonlyField(selectedName);
|
||||
}
|
||||
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: enabled ? Colors.white : const Color(0xFFF7F8FA),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: const Color(0xFFE5E6EB)),
|
||||
),
|
||||
child: DropdownButtonFormField<int>(
|
||||
value: state.selectedOrgId,
|
||||
decoration: _dropdownDecoration(enabled),
|
||||
icon: Icon(
|
||||
Icons.expand_more,
|
||||
color: enabled ? const Color(0xFF86909C) : const Color(0xFFC9CDD4),
|
||||
),
|
||||
items: state.orgList.map((org) {
|
||||
return DropdownMenuItem<int>(
|
||||
value: org.id,
|
||||
child: Text(
|
||||
org.name,
|
||||
style: const TextStyle(fontSize: 14, color: Color(0xFF1D2129)),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: enabled
|
||||
? (v) {
|
||||
if (v != null) _cubit.onOrgChanged(v);
|
||||
}
|
||||
: null,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSiteDropdown(BindDeviceState state) {
|
||||
final enabled = _cubit.isSiteEnabled && state.selectedOrgId != null;
|
||||
final selectedName = state.selectedSiteId != null
|
||||
? state.siteList
|
||||
.where((site) => site.id == state.selectedSiteId)
|
||||
.fold<String?>(null, (_, site) => site.name)
|
||||
: null;
|
||||
|
||||
if (!enabled && selectedName != null) {
|
||||
return _buildReadonlyField(selectedName);
|
||||
}
|
||||
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: enabled ? Colors.white : const Color(0xFFF7F8FA),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: const Color(0xFFE5E6EB)),
|
||||
),
|
||||
child: DropdownButtonFormField<int>(
|
||||
value: state.selectedSiteId,
|
||||
decoration: _dropdownDecoration(enabled),
|
||||
icon: Icon(
|
||||
Icons.expand_more,
|
||||
color: enabled ? const Color(0xFF86909C) : const Color(0xFFC9CDD4),
|
||||
),
|
||||
items: state.siteList.map((site) {
|
||||
return DropdownMenuItem<int>(
|
||||
value: site.id,
|
||||
child: Text(
|
||||
site.name,
|
||||
style: const TextStyle(fontSize: 14, color: Color(0xFF1D2129)),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: enabled
|
||||
? (v) {
|
||||
if (v != null) _cubit.onSiteChanged(v);
|
||||
}
|
||||
: null,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildUserDropdown(BindDeviceState state) {
|
||||
final enabled = _cubit.isUserEnabled && state.selectedSiteId != null;
|
||||
final selectedName = state.selectedUserId != null
|
||||
? state.userList
|
||||
.where((user) => user.id == state.selectedUserId)
|
||||
.fold<String?>(null, (_, user) => user.name)
|
||||
: null;
|
||||
|
||||
if (!enabled && selectedName != null) {
|
||||
return _buildReadonlyField(selectedName);
|
||||
}
|
||||
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: enabled ? Colors.white : const Color(0xFFF7F8FA),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: const Color(0xFFE5E6EB)),
|
||||
),
|
||||
child: DropdownButtonFormField<int>(
|
||||
value: state.selectedUserId,
|
||||
decoration: _dropdownDecoration(enabled),
|
||||
icon: Icon(
|
||||
Icons.expand_more,
|
||||
color: enabled ? const Color(0xFF86909C) : const Color(0xFFC9CDD4),
|
||||
),
|
||||
items: state.userList.map((user) {
|
||||
return DropdownMenuItem<int>(
|
||||
value: user.id,
|
||||
child: Text(
|
||||
user.name,
|
||||
style: const TextStyle(fontSize: 14, color: Color(0xFF1D2129)),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: enabled
|
||||
? (v) {
|
||||
_cubit.onUserChanged(v);
|
||||
}
|
||||
: null,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildReadonlyField(String text) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF7F8FA),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: const Color(0xFFE5E6EB)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
text,
|
||||
style: const TextStyle(fontSize: 14, color: Color(0xFF1D2129)),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const Icon(Icons.lock, size: 16, color: Color(0xFFC9CDD4)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
InputDecoration _dropdownDecoration(bool enabled) {
|
||||
return InputDecoration(
|
||||
isDense: true,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
|
||||
border: InputBorder.none,
|
||||
enabledBorder: InputBorder.none,
|
||||
focusedBorder: InputBorder.none,
|
||||
hintText: enabled ? '请选择' : '请选择',
|
||||
hintStyle: const TextStyle(color: Color(0xFF86909C), fontSize: 14),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildRequiredField({required String label, required Widget child}) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
children: [
|
||||
const TextSpan(
|
||||
text: '* ',
|
||||
style: TextStyle(
|
||||
color: Color(0xFFF53F3F),
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
TextSpan(
|
||||
text: label,
|
||||
style: const TextStyle(
|
||||
color: Color(0xFF1D2129),
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
child,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildField({required String label, required Widget child}) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
color: Color(0xFF1D2129),
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
child,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void _handleSubmit() {
|
||||
_cubit.submitBind(widget.scanResult);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,6 +2,7 @@ import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import '../../../../../core/consts/http_api_consts.dart';
|
||||
import '../../../../../core/managers/drone_task_state_manager.dart';
|
||||
|
||||
class CreateTaskPage extends StatefulWidget {
|
||||
final String sn;
|
||||
@@ -430,6 +431,9 @@ class _CreateTaskPageState extends State<CreateTaskPage> {
|
||||
final taskUuid = jsonData['data']['task_uuid'];
|
||||
print('✅ [CreateTask] 任务创建成功, task_uuid: $taskUuid');
|
||||
|
||||
// 🔥 任务下发成功,开始监测无人机实时推送与视频流
|
||||
droneTaskStateManager.markTaskIssued();
|
||||
|
||||
Navigator.pop(context);
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
@@ -570,8 +574,8 @@ class _CreateTaskPageState extends State<CreateTaskPage> {
|
||||
wayline['waylineUuid'] ??
|
||||
wayline['id'] ??
|
||||
'';
|
||||
// print('🔍 [CreateTask] 航线数据: $wayline');
|
||||
// print('🔍 [CreateTask] 解析的UUID: $waylineUuid');
|
||||
// print('🔍 [CreateTask] 航线数据: $wayline');
|
||||
// print('🔍 [CreateTask] 解析的UUID: $waylineUuid');
|
||||
return ListTile(
|
||||
title: Text(waylineName),
|
||||
subtitle: waylineUuid.isNotEmpty
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
import '../../../../../core/di/injection.dart';
|
||||
import '../../../../../core/app/app_user_cubit.dart';
|
||||
import '../../../../../core/bluetooth/ble_manager.dart';
|
||||
import '../../../../../components/tcp_status_indicator.dart';
|
||||
import '../../../../../components/device_status_modal.dart';
|
||||
import '../../../../v2/site/presentation/cubit/site_cubit.dart';
|
||||
import '../../../site/presentation/widgets/site_selector_widget.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;
|
||||
@@ -20,11 +23,16 @@ import '../bloc/robot_list_state.dart'; // 🔥 添加 RobotListState 导入
|
||||
import '../widgets/device_item_widget.dart';
|
||||
import '../widgets/drone_station_item_card.dart';
|
||||
import '../widgets/robot_item_card.dart'; // 🔥 添加 RobotItemCard 导入
|
||||
import '../widgets/bluetooth_scan_modal.dart';
|
||||
import '../../domain/entities/drone_station_entity.dart'; // 🔥 添加 DroneStationEntity 导入
|
||||
import 'robot_list_page.dart';
|
||||
import 'robot_control_page.dart';
|
||||
import 'drone_station_detail_page.dart';
|
||||
import 'qr_scanner_page.dart';
|
||||
import 'bind_device_page.dart';
|
||||
import '../../../../remote_control/presentation/bloc/remote_control_cubit.dart';
|
||||
import '../../../../devices/domain/entities/device_entity.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
|
||||
/// 设备状态页面 - 使用 BLoC 模式
|
||||
class DeviceStatusPage extends StatelessWidget {
|
||||
@@ -45,9 +53,70 @@ class DeviceStatusPage extends StatelessWidget {
|
||||
}
|
||||
|
||||
/// 设备状态视图
|
||||
class DeviceStatusView extends StatelessWidget {
|
||||
class DeviceStatusView extends StatefulWidget {
|
||||
const DeviceStatusView({super.key});
|
||||
|
||||
@override
|
||||
State<DeviceStatusView> createState() => _DeviceStatusViewState();
|
||||
}
|
||||
|
||||
class _DeviceStatusViewState extends State<DeviceStatusView> {
|
||||
final _searchController = TextEditingController();
|
||||
|
||||
/// 🔥 监听电站切换:只要电站发生变化,就根据当前选中的标签栏自动刷新对应接口
|
||||
StreamSubscription<SiteState>? _siteSub;
|
||||
|
||||
/// 当前缓存的 siteId,用于判断是否真的发生了变化
|
||||
int? _currentSiteId;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_currentSiteId = sl<SiteCubit>().state.selectedSite?.id;
|
||||
_siteSub = sl<SiteCubit>().stream.listen((siteState) {
|
||||
if (!mounted) return;
|
||||
final newSiteId = siteState.selectedSite?.id;
|
||||
// 只有 siteId 真正变化时才刷新(避免无意义的重复请求)
|
||||
if (newSiteId != _currentSiteId) {
|
||||
_currentSiteId = newSiteId;
|
||||
_refreshCurrentTabForSiteChange(newSiteId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_siteSub?.cancel();
|
||||
_searchController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/// 🔥 电站切换后,根据当前选中的标签栏自动刷新对应接口
|
||||
void _refreshCurrentTabForSiteChange(int? newSiteId) {
|
||||
final bloc = context.read<DeviceListBloc.DeviceStatusBloc>();
|
||||
final state = bloc.state;
|
||||
// 取出当前选中的标签类型;若 BLoC 还未加载完成则默认 'all'
|
||||
final selectedType = (state is DeviceListState.DeviceStatusLoaded)
|
||||
? state.selectedType
|
||||
: 'all';
|
||||
|
||||
debugPrint(
|
||||
'🔄 [DeviceStatus] 电站切换 → siteId=$newSiteId, 当前标签=$selectedType, 自动刷新',
|
||||
);
|
||||
|
||||
// 1. 主设备列表(all / inverter / combiner_box / module / monitor 共用 DeviceStatusBloc)
|
||||
// 直接派发 Refresh 事件并带上新 siteId
|
||||
bloc.add(DeviceListEvent.DeviceStatusRefresh(siteId: newSiteId));
|
||||
|
||||
// 2. robot / drone_station 由各自 BlocProvider 创建,通过 setState + ValueKey 重建子树
|
||||
// 使其用新 siteId 重新加载数据
|
||||
if (selectedType == 'robot' ||
|
||||
selectedType == 'drone_station' ||
|
||||
selectedType == 'all') {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
/// 🔥 机器人设备名称前缀,用于从通用设备列表中过滤掉机器人
|
||||
static const _robotPrefixes = [
|
||||
'RCHETD-CN',
|
||||
@@ -109,31 +178,63 @@ class DeviceStatusView extends StatelessWidget {
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
AppLocalizations.of(context).translate('device_list_v2.title'),
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF1D2129),
|
||||
Expanded(
|
||||
child: Row(
|
||||
children: [
|
||||
const Flexible(child: SiteSelectorWidget(compact: true)),
|
||||
const SizedBox(width: 8),
|
||||
Container(width: 1, height: 20, color: const Color(0xFFE5E6EB)),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('device_list_v2.title'),
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Color(0xFF86909C),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
Row(
|
||||
children: [
|
||||
const Text(
|
||||
'TCP',
|
||||
style: TextStyle(fontSize: 12, color: Color(0xFF86909C)),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(4),
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: Colors.blue.withOpacity(0.1),
|
||||
),
|
||||
child: TcpStatusIndicator(
|
||||
size: 12,
|
||||
onTap: () => _showDeviceStatusModal(context),
|
||||
// 🔥 注释掉原有的 TCP 指示灯
|
||||
// const Text(
|
||||
// 'TCP',
|
||||
// style: TextStyle(fontSize: 12, color: Color(0xFF86909C)),
|
||||
// ),
|
||||
// const SizedBox(width: 4),
|
||||
// Container(
|
||||
// padding: const EdgeInsets.all(4),
|
||||
// decoration: BoxDecoration(
|
||||
// shape: BoxShape.circle,
|
||||
// color: Colors.blue.withOpacity(0.1),
|
||||
// ),
|
||||
// child: TcpStatusIndicator(
|
||||
// size: 12,
|
||||
// onTap: () => _showDeviceStatusModal(context),
|
||||
// ),
|
||||
// ),
|
||||
GestureDetector(
|
||||
onTap: () => _showAddMenu(context),
|
||||
child: Container(
|
||||
width: 30,
|
||||
height: 30,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: const Color(0xFFE5E6EB),
|
||||
width: 1,
|
||||
),
|
||||
color: Colors.white,
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.add,
|
||||
color: Color(0xFF4E5969),
|
||||
size: 18,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -146,56 +247,107 @@ class DeviceStatusView extends StatelessWidget {
|
||||
Widget _buildSearchBar(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16.0, 8, 16.0, 8),
|
||||
child: TextField(
|
||||
decoration: InputDecoration(
|
||||
hintText: AppLocalizations.of(
|
||||
context,
|
||||
).translate('device_list_v2.search_hint'),
|
||||
hintStyle: const TextStyle(color: Color(0xFF86909C), fontSize: 14),
|
||||
prefixIcon: const Icon(
|
||||
Icons.search,
|
||||
color: Color(0xFF86909C),
|
||||
size: 24,
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _searchController,
|
||||
decoration: InputDecoration(
|
||||
hintText: AppLocalizations.of(
|
||||
context,
|
||||
).translate('device_list_v2.search_hint'),
|
||||
hintStyle: const TextStyle(
|
||||
color: Color(0xFF86909C),
|
||||
fontSize: 14,
|
||||
),
|
||||
prefixIcon: const Icon(
|
||||
Icons.search,
|
||||
color: Color(0xFF86909C),
|
||||
size: 24,
|
||||
),
|
||||
suffixIcon: IconButton(
|
||||
onPressed: () {
|
||||
context.read<DeviceListBloc.DeviceStatusBloc>().add(
|
||||
DeviceListEvent.DeviceStatusSearch(
|
||||
_searchController.text,
|
||||
),
|
||||
);
|
||||
},
|
||||
icon: const Icon(
|
||||
Icons.search,
|
||||
color: Color(0xFF165DFF),
|
||||
size: 22,
|
||||
),
|
||||
),
|
||||
filled: true,
|
||||
fillColor: const Color(0xFFF2F3F5),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(24.0),
|
||||
borderSide: const BorderSide(
|
||||
color: Color(0xFFE5E6EB),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(24.0),
|
||||
borderSide: const BorderSide(
|
||||
color: Color(0xFFE5E6EB),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(24.0),
|
||||
borderSide: const BorderSide(
|
||||
color: Color(0xFF165DFF),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 12,
|
||||
),
|
||||
),
|
||||
style: const TextStyle(fontSize: 14, color: Color(0xFF1D2129)),
|
||||
onSubmitted: (value) {
|
||||
context.read<DeviceListBloc.DeviceStatusBloc>().add(
|
||||
DeviceListEvent.DeviceStatusSearch(value),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
suffixIcon: TextButton(
|
||||
onPressed: () {
|
||||
// TODO: 触发搜索
|
||||
const SizedBox(width: 8),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(16),
|
||||
topRight: Radius.circular(16),
|
||||
),
|
||||
),
|
||||
builder: (context) => const BluetoothScanModal(),
|
||||
).whenComplete(() {
|
||||
// 弹窗关闭时立即停止扫描(无论以什么方式关闭)
|
||||
BleManager.instance.stopScan();
|
||||
});
|
||||
},
|
||||
child: Text(
|
||||
AppLocalizations.of(context).translate('device_list_v2.search'),
|
||||
style: const TextStyle(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: const Color(0xFF165DFF).withOpacity(0.1),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.bluetooth,
|
||||
color: Color(0xFF165DFF),
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
size: 22,
|
||||
),
|
||||
),
|
||||
),
|
||||
filled: true,
|
||||
fillColor: const Color(0xFFF2F3F5),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(24.0),
|
||||
borderSide: const BorderSide(color: Color(0xFFE5E6EB), width: 1),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(24.0),
|
||||
borderSide: const BorderSide(color: Color(0xFFE5E6EB), width: 1),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(24.0),
|
||||
borderSide: const BorderSide(color: Color(0xFF165DFF), width: 1),
|
||||
),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 12,
|
||||
),
|
||||
),
|
||||
style: const TextStyle(fontSize: 14, color: Color(0xFF1D2129)),
|
||||
onSubmitted: (value) {
|
||||
// 🔥 点击键盘确定键时触发搜索
|
||||
context.read<DeviceListBloc.DeviceStatusBloc>().add(
|
||||
DeviceListEvent.DeviceStatusSearch(value),
|
||||
);
|
||||
},
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -290,14 +442,20 @@ class DeviceStatusView extends StatelessWidget {
|
||||
BuildContext context,
|
||||
DeviceListState.DeviceStatusState state,
|
||||
) {
|
||||
// 🔥 用当前 siteId 作为 Key,电站切换时强制重建子树(重建对应 BlocProvider)
|
||||
final siteId = _currentSiteId;
|
||||
|
||||
if (state is DeviceListState.DeviceStatusLoaded &&
|
||||
state.selectedType == 'robot') {
|
||||
return const RobotListPage();
|
||||
return RobotListPage(key: ValueKey('robot_$siteId'));
|
||||
}
|
||||
|
||||
if (state is DeviceListState.DeviceStatusLoaded &&
|
||||
state.selectedType == 'drone_station') {
|
||||
return _buildDroneStationList(context);
|
||||
return _buildDroneStationList(
|
||||
context,
|
||||
key: ValueKey('drone_station_$siteId'),
|
||||
);
|
||||
}
|
||||
|
||||
return _buildDeviceList(context, state);
|
||||
@@ -398,6 +556,8 @@ class DeviceStatusView extends StatelessWidget {
|
||||
debugPrint('🔍 [EmbeddedRobotList] 开始加载机器人数据, siteId: $siteId');
|
||||
|
||||
return BlocProvider(
|
||||
// 🔥 电站切换时通过 key 变化强制重建 BlocProvider,重新用新 siteId 加载
|
||||
key: ValueKey('embedded_robot_$siteId'),
|
||||
create: (_) =>
|
||||
sl<RobotListBloc>()..add(RobotListLoadData(siteId: siteId)),
|
||||
child: BlocConsumer<RobotListBloc, RobotListState>(
|
||||
@@ -441,16 +601,49 @@ class DeviceStatusView extends StatelessWidget {
|
||||
return RobotItemCard(
|
||||
name: robot.name,
|
||||
id: robot.id,
|
||||
alias: robot.alias,
|
||||
type: robot.type,
|
||||
status: robot.status,
|
||||
battery: robot.battery,
|
||||
task: robot.task,
|
||||
onTap: () {
|
||||
onTap: () async {
|
||||
debugPrint(
|
||||
'🔴🔴🔴 [全部-选中机器人] name: ${robot.name}, id: ${robot.id}, type: ${robot.type}',
|
||||
);
|
||||
|
||||
// 1. 将当前机器人设置为全局待控制设备
|
||||
final device = DeviceEntity(
|
||||
deviceName: robot.name,
|
||||
productId: -1,
|
||||
productName: robot.type,
|
||||
tenantId: 0,
|
||||
tenantName: '',
|
||||
status: robot.status == '在线' ? 1 : 0,
|
||||
onlineStatus: robot.status == '在线' ? 1 : 0,
|
||||
);
|
||||
|
||||
final remoteCubit = GetIt.I<RemoteControlCubit>();
|
||||
remoteCubit.setTargetDevice(device);
|
||||
debugPrint(
|
||||
'✅ [全部-EmbeddedRobotList] setTargetDevice 已调用',
|
||||
);
|
||||
|
||||
// 2. 跳转到机器人控制页面
|
||||
final robotMap = {
|
||||
'name': robot.name,
|
||||
'id': robot.id,
|
||||
'alias': robot.alias,
|
||||
'type': robot.type,
|
||||
'status': robot.status,
|
||||
'battery': robot.battery,
|
||||
'task': robot.task,
|
||||
};
|
||||
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
RobotControlPage(robot: robot.toJson()),
|
||||
RobotControlPage(robot: robotMap),
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -470,7 +663,11 @@ class DeviceStatusView extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDroneStationList(BuildContext context, {bool embedded = false}) {
|
||||
Widget _buildDroneStationList(
|
||||
BuildContext context, {
|
||||
bool embedded = false,
|
||||
Key? key,
|
||||
}) {
|
||||
// 从全局 SiteCubit 获取选中的场站 ID
|
||||
final selectedSite = sl<SiteCubit>().state.selectedSite;
|
||||
|
||||
@@ -493,6 +690,7 @@ class DeviceStatusView extends StatelessWidget {
|
||||
}
|
||||
|
||||
return BlocProvider(
|
||||
key: key,
|
||||
create: (_) =>
|
||||
sl<DroneStationBloc>()..add(DroneStationLoadData(selectedSite.id)),
|
||||
child: BlocConsumer<DroneStationBloc, DroneStationState>(
|
||||
@@ -692,6 +890,96 @@ class DeviceStatusView extends StatelessWidget {
|
||||
}
|
||||
|
||||
// 显示设备状态模态框 - 从底部滑出
|
||||
/// 显示添加菜单(扫一扫、添加设备)
|
||||
void _showAddMenu(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierColor: Colors.black38,
|
||||
builder: (ctx) => Stack(
|
||||
children: [
|
||||
// 点击遮罩关闭
|
||||
GestureDetector(
|
||||
onTap: () => Navigator.pop(ctx),
|
||||
child: Container(color: Colors.transparent),
|
||||
),
|
||||
Positioned(
|
||||
top: MediaQuery.of(context).padding.top + 50,
|
||||
right: 16,
|
||||
child: Material(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
color: Colors.white,
|
||||
elevation: 8,
|
||||
shadowColor: Colors.black26,
|
||||
child: SizedBox(
|
||||
width: 150,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_buildMenuOption(
|
||||
ctx,
|
||||
icon: Icons.qr_code_scanner,
|
||||
label: '扫一扫',
|
||||
onTap: () async {
|
||||
Navigator.pop(ctx);
|
||||
final result = await Navigator.of(context).push<String>(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => const QrScannerPage(),
|
||||
),
|
||||
);
|
||||
if (result != null && mounted) {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => BindDevicePage(scanResult: result),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
const Divider(height: 1, color: Color(0xFFF2F3F5)),
|
||||
_buildMenuOption(
|
||||
ctx,
|
||||
icon: Icons.add_circle_outline,
|
||||
label: '添加设备',
|
||||
onTap: () {
|
||||
Navigator.pop(ctx);
|
||||
// TODO: 添加设备功能
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMenuOption(
|
||||
BuildContext context, {
|
||||
required IconData icon,
|
||||
required String label,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(icon, color: const Color(0xFF4E5969), size: 20),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(fontSize: 15, color: Color(0xFF1D2129)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showDeviceStatusModal(BuildContext context) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
@@ -794,9 +1082,11 @@ class DeviceStatusView extends StatelessWidget {
|
||||
if (isRobot) {
|
||||
// 跳转到机器人控制页面
|
||||
debugPrint('🚀 [DeviceStatusPage] 跳转到机器人控制页面');
|
||||
final deviceAlias = device.deviceAlias ?? '';
|
||||
final robotMap = {
|
||||
'name': deviceName,
|
||||
'id': deviceId,
|
||||
'alias': deviceAlias,
|
||||
'type': deviceType,
|
||||
'status': device.status ?? '在线',
|
||||
'battery': 100.0, // DeviceEntity 没有 battery 字段,使用默认值
|
||||
|
||||
@@ -30,7 +30,7 @@ class _DroneMissionControlPageState extends State<DroneMissionControlPage> {
|
||||
FlightTaskDetailEntity? _detailTask; // 详情数据
|
||||
bool _isLoading = false;
|
||||
final Dio _dio = Dio();
|
||||
|
||||
|
||||
// 🔥 任务状态管理
|
||||
bool _isPaused = false; // 是否已暂停(用于切换暂停/恢复按钮)
|
||||
bool _isReturning = false; // 是否正在返航中
|
||||
@@ -220,9 +220,7 @@ class _DroneMissionControlPageState extends State<DroneMissionControlPage> {
|
||||
print('🔍 [DroneMissionControl] 开始暂停任务, deviceSn: ${_detailTask!.sn}');
|
||||
|
||||
final useCase = GetIt.I<PauseFlightTaskUseCase>();
|
||||
final result = await useCase.execute(
|
||||
deviceSn: _detailTask!.sn,
|
||||
);
|
||||
final result = await useCase.execute(deviceSn: _detailTask!.sn);
|
||||
|
||||
result.fold(
|
||||
(failure) {
|
||||
@@ -737,7 +735,9 @@ class _DroneMissionControlPageState extends State<DroneMissionControlPage> {
|
||||
child: ElevatedButton(
|
||||
onPressed: _isPaused ? _resumeTask : _pauseTask,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: _isPaused ? const Color(0xFF165DFF) : const Color(0xFFFF7D00),
|
||||
backgroundColor: _isPaused
|
||||
? const Color(0xFF165DFF)
|
||||
: const Color(0xFFFF7D00),
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
shape: RoundedRectangleBorder(
|
||||
@@ -747,7 +747,10 @@ class _DroneMissionControlPageState extends State<DroneMissionControlPage> {
|
||||
),
|
||||
child: Text(
|
||||
_isPaused ? '恢复任务' : '暂停任务',
|
||||
style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w500),
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -756,8 +759,14 @@ class _DroneMissionControlPageState extends State<DroneMissionControlPage> {
|
||||
child: OutlinedButton(
|
||||
onPressed: _isReturning ? null : _returnHome,
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: _isReturning ? const Color(0xFF86909C) : const Color(0xFF4E5969),
|
||||
side: BorderSide(color: _isReturning ? const Color(0xFFE5E6EB) : const Color(0xFFC9CDD4)),
|
||||
foregroundColor: _isReturning
|
||||
? const Color(0xFF86909C)
|
||||
: const Color(0xFF4E5969),
|
||||
side: BorderSide(
|
||||
color: _isReturning
|
||||
? const Color(0xFFE5E6EB)
|
||||
: const Color(0xFFC9CDD4),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
@@ -765,7 +774,10 @@ class _DroneMissionControlPageState extends State<DroneMissionControlPage> {
|
||||
),
|
||||
child: Text(
|
||||
_isReturning ? '已在返航' : '返航降落',
|
||||
style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w500),
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -3,12 +3,14 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../../../../core/di/injection.dart';
|
||||
import '../../../../../core/managers/drone_task_state_manager.dart';
|
||||
import '../../../../../core/network/mqtt/data/datasources/drone_osd_datasource.dart';
|
||||
import '../../../../../core/network/mqtt/domain/entities/drone_osd_entity.dart';
|
||||
import '../../domain/entities/drone_station_entity.dart';
|
||||
import '../bloc/drone_station_bloc.dart';
|
||||
import '../bloc/drone_station_event.dart';
|
||||
import '../bloc/drone_station_state.dart';
|
||||
import '../widgets/drone_station_osd_card.dart'; // 🔥 添加机场 OSD 卡片
|
||||
import '../widgets/drone_osd_card.dart'; // 🔥 添加无人机 OSD 卡片
|
||||
import '../widgets/drone_station_osd_card.dart';
|
||||
import '../widgets/drone_osd_card.dart';
|
||||
import 'drone_video_control_page.dart';
|
||||
import 'drone_mission_control_page.dart';
|
||||
import 'drone_monitor_page.dart';
|
||||
@@ -26,16 +28,17 @@ class DroneStationDetailPage extends StatefulWidget {
|
||||
class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
late DroneStationBloc _bloc;
|
||||
|
||||
// 无人机详情数据
|
||||
UAVDetailEntity? _detail;
|
||||
String? _droneSn;
|
||||
|
||||
// 无人机状态轮询计时器
|
||||
Timer? _droneStatusPollingTimer;
|
||||
|
||||
// 🔥 标记是否已经初始化过(用于判断是否从其他页面返回)
|
||||
bool _hasInitialized = false;
|
||||
|
||||
late DroneOsdDataSource _osdDataSource;
|
||||
StreamSubscription<DroneOsdEntity>? _stationOsdSubscription;
|
||||
final ValueNotifier<Map<String, dynamic>> _stationHostData =
|
||||
ValueNotifier<Map<String, dynamic>>({});
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -46,20 +49,78 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
deviceSn: widget.station.deviceSn,
|
||||
),
|
||||
);
|
||||
|
||||
// 🔥 标记已初始化
|
||||
_hasInitialized = true;
|
||||
|
||||
// 启动无人机状态轮询(每5秒刷新一次)
|
||||
// 🔥 已禁用自动轮询,改为手动下拉刷新
|
||||
// _startDroneStatusPolling();
|
||||
_osdDataSource = sl<DroneOsdDataSource>();
|
||||
_startStationOsdListening();
|
||||
|
||||
_hasInitialized = true;
|
||||
}
|
||||
|
||||
void _startStationOsdListening() {
|
||||
_osdDataSource.startListening(
|
||||
deviceSn: '',
|
||||
gatewaySn: widget.station.gatewaySn,
|
||||
);
|
||||
|
||||
_stationOsdSubscription = _osdDataSource.stationOsdStream.listen((osd) {
|
||||
if (!mounted) return;
|
||||
_parseAndUpdateHostData(osd);
|
||||
});
|
||||
}
|
||||
|
||||
void _parseAndUpdateHostData(DroneOsdEntity osd) {
|
||||
final data = osd.rawData;
|
||||
final hostData = data['data'] is Map ? (data['data'] as Map)['host'] : null;
|
||||
if (hostData == null || hostData is! Map) return;
|
||||
|
||||
final Map<String, dynamic> parsed = {};
|
||||
|
||||
parsed['environment_temperature'] =
|
||||
(hostData['environment_temperature'] as num?)?.toDouble();
|
||||
parsed['humidity'] = (hostData['humidity'] as num?)?.toDouble();
|
||||
parsed['wind_speed'] = (hostData['wind_speed'] as num?)?.toDouble();
|
||||
parsed['rainfall'] = hostData['rainfall']?.toString();
|
||||
parsed['cover_state'] = hostData['cover_state']?.toString();
|
||||
parsed['drone_in_dock'] = hostData['drone_in_dock']?.toString();
|
||||
parsed['temperature'] = (hostData['temperature'] as num?)?.toDouble();
|
||||
parsed['putter_state'] = hostData['putter_state']?.toString();
|
||||
parsed['supplement_light_state'] = hostData['supplement_light_state']
|
||||
?.toString();
|
||||
parsed['alarm_state'] = hostData['alarm_state']?.toString();
|
||||
parsed['emergency_stop_state'] = hostData['emergency_stop_state']
|
||||
?.toString();
|
||||
parsed['silent_mode'] = hostData['silent_mode']?.toString();
|
||||
parsed['mode_code'] = hostData['mode_code']?.toString();
|
||||
parsed['heading'] = (hostData['heading'] as num?)?.toDouble();
|
||||
parsed['height'] = (hostData['height'] as num?)?.toDouble();
|
||||
parsed['latitude'] = (hostData['latitude'] as num?)?.toDouble();
|
||||
parsed['longitude'] = (hostData['longitude'] as num?)?.toDouble();
|
||||
parsed['home_position_is_valid'] = hostData['home_position_is_valid']
|
||||
?.toString();
|
||||
parsed['battery_store_mode'] = hostData['battery_store_mode']?.toString();
|
||||
parsed['first_power_on'] = hostData['first_power_on']?.toString();
|
||||
parsed['drone_charge_state'] = hostData['drone_charge_state'];
|
||||
parsed['air_conditioner'] = hostData['air_conditioner'];
|
||||
parsed['network_state'] = hostData['network_state'];
|
||||
parsed['position_state'] = hostData['position_state'];
|
||||
parsed['storage'] = hostData['storage'];
|
||||
parsed['sub_device'] = hostData['sub_device'];
|
||||
parsed['alternate_land_point'] = hostData['alternate_land_point'];
|
||||
|
||||
if (hostData['air_conditioner'] is Map) {
|
||||
final ac = hostData['air_conditioner'] as Map;
|
||||
parsed['air_conditioner_state'] = ac['air_conditioner_state']?.toString();
|
||||
parsed['air_conditioner_switch_time'] = ac['switch_time']?.toString();
|
||||
}
|
||||
|
||||
_stationHostData.value = Map<String, dynamic>.from(parsed);
|
||||
}
|
||||
|
||||
/// 🔥 页面重新激活时调用(从其他页面返回时)
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
|
||||
|
||||
// 🔥 只有在已经初始化后才执行刷新(避免首次加载时重复刷新)
|
||||
if (_hasInitialized && _bloc.state is UAVDetailLoaded) {
|
||||
debugPrint('🔄 [DroneStationDetailPage] 从其他页面返回,刷新数据');
|
||||
@@ -75,7 +136,7 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
/// 🔥 刷新数据(无人机详情 + OSD数据会自动通过MQTT更新)
|
||||
void _refreshData() {
|
||||
if (!mounted) return;
|
||||
|
||||
|
||||
debugPrint('📡 [DroneStationDetailPage] 刷新无人机详情数据');
|
||||
_bloc.add(
|
||||
UAVDetailLoad(
|
||||
@@ -87,9 +148,10 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_stationOsdSubscription?.cancel();
|
||||
_osdDataSource.stopListening();
|
||||
_stationHostData.dispose();
|
||||
_bloc.close();
|
||||
// 🔥 已禁用自动轮询,无需停止
|
||||
// _droneStatusPollingTimer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -216,27 +278,41 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
}
|
||||
|
||||
Widget _buildContent(UAVDetailEntity detail) {
|
||||
_detail = detail; // 保存详情数据供其他方法使用
|
||||
_droneSn = detail.deviceSn; // 保存无人机序列号
|
||||
_detail = detail;
|
||||
_droneSn = detail.deviceSn;
|
||||
|
||||
if (_droneSn != null && _droneSn!.isNotEmpty) {
|
||||
_osdDataSource.startListening(
|
||||
deviceSn: _droneSn!,
|
||||
gatewaySn: widget.station.gatewaySn,
|
||||
);
|
||||
}
|
||||
|
||||
return RefreshIndicator(
|
||||
onRefresh: _handleRefresh,
|
||||
color: const Color(0xFF165DFF),
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
_buildAirportStatusCard(detail),
|
||||
ValueListenableBuilder<Map<String, dynamic>>(
|
||||
valueListenable: _stationHostData,
|
||||
builder: (context, hostData, _) {
|
||||
return _buildAirportStatusCard(detail, hostData);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
// 🔥 添加机场 OSD 实时数据卡片
|
||||
DroneStationOsdCard(
|
||||
stationOsdStream: _osdDataSource.stationOsdStream,
|
||||
gatewaySn: widget.station.gatewaySn,
|
||||
isOnline: detail.isOnline,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
// 🔥 添加无人机 OSD 实时数据卡片(无人机在线时显示)
|
||||
DroneOsdCard(
|
||||
droneOsdStream: _osdDataSource.droneOsdStream,
|
||||
deviceSn: widget.station.deviceSn,
|
||||
gatewaySn: widget.station.gatewaySn,
|
||||
isDroneOnline: detail.isDroneOnline,
|
||||
onRefresh: _refreshData,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_buildMonitorCard(),
|
||||
@@ -253,10 +329,10 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
/// 处理下拉刷新
|
||||
Future<void> _handleRefresh() async {
|
||||
debugPrint('🔄 [DroneStationDetailPage] 开始下拉刷新');
|
||||
|
||||
|
||||
// 🔥 创建一个 Completer 来等待 Bloc 状态更新
|
||||
final completer = Completer<void>();
|
||||
|
||||
|
||||
// 监听 Bloc 状态变化
|
||||
final subscription = _bloc.stream.listen((state) {
|
||||
if (state is UAVDetailLoaded || state is UAVDetailError) {
|
||||
@@ -265,7 +341,7 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// 重新加载无人机详情
|
||||
_bloc.add(
|
||||
UAVDetailLoad(
|
||||
@@ -273,7 +349,7 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
deviceSn: widget.station.deviceSn,
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
// 🔥 等待数据加载完成(最多等待5秒)
|
||||
await completer.future.timeout(
|
||||
const Duration(seconds: 5),
|
||||
@@ -281,10 +357,10 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
debugPrint('⚠️ [DroneStationDetailPage] 下拉刷新超时');
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
// 取消订阅
|
||||
subscription.cancel();
|
||||
|
||||
|
||||
debugPrint('✅ [DroneStationDetailPage] 下拉刷新完成');
|
||||
}
|
||||
|
||||
@@ -343,7 +419,90 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAirportStatusCard(UAVDetailEntity detail) {
|
||||
Widget _buildAirportStatusCard(
|
||||
UAVDetailEntity detail,
|
||||
Map<String, dynamic> hostData,
|
||||
) {
|
||||
final envTemp = hostData['environment_temperature'];
|
||||
final humidity = hostData['humidity'];
|
||||
final windSpeed = hostData['wind_speed'];
|
||||
final rainfall = hostData['rainfall'];
|
||||
final coverState = hostData['cover_state'];
|
||||
final droneInDock = hostData['drone_in_dock'];
|
||||
final acState = hostData['air_conditioner_state'];
|
||||
final alarmState = hostData['alarm_state'];
|
||||
|
||||
String envTempStr = '未知';
|
||||
if (envTemp != null) {
|
||||
envTempStr = '${envTemp.toStringAsFixed(1)}°C';
|
||||
} else if (detail.environmentTemperature != null) {
|
||||
envTempStr = '${detail.environmentTemperature}°C';
|
||||
}
|
||||
|
||||
String humidityStr = '未知';
|
||||
if (humidity != null) {
|
||||
humidityStr = '${humidity.toStringAsFixed(0)}%';
|
||||
}
|
||||
|
||||
String windStr = '未知';
|
||||
if (windSpeed != null) {
|
||||
windStr = '${windSpeed.toStringAsFixed(1)} m/s';
|
||||
} else if (detail.windSpeed != null) {
|
||||
windStr = '${detail.windSpeed} m/s';
|
||||
}
|
||||
|
||||
String rainfallStr = '未知';
|
||||
if (rainfall != null) {
|
||||
rainfallStr = _formatRainfall(rainfall);
|
||||
} else if (detail.rainfall != null) {
|
||||
rainfallStr = _formatRainfall(detail.rainfall);
|
||||
}
|
||||
|
||||
String coverStr = '未知';
|
||||
Color coverColor = const Color(0xFF86909C);
|
||||
if (coverState != null) {
|
||||
final state = int.tryParse(coverState) ?? -1;
|
||||
if (state == 1) {
|
||||
coverStr = '开启';
|
||||
coverColor = const Color(0xFFFF7D00);
|
||||
} else if (state == 0) {
|
||||
coverStr = '关闭';
|
||||
coverColor = const Color(0xFF00B42A);
|
||||
}
|
||||
}
|
||||
|
||||
String droneDockStr = '未知';
|
||||
Color droneDockColor = const Color(0xFF86909C);
|
||||
if (droneInDock != null) {
|
||||
final state = int.tryParse(droneInDock) ?? -1;
|
||||
if (state == 1) {
|
||||
droneDockStr = '在库内';
|
||||
droneDockColor = const Color(0xFF00B42A);
|
||||
} else if (state == 0) {
|
||||
droneDockStr = '出库';
|
||||
droneDockColor = const Color(0xFFFF7D00);
|
||||
}
|
||||
}
|
||||
|
||||
String acStr = '未知';
|
||||
Color acColor = const Color(0xFF86909C);
|
||||
if (acState != null) {
|
||||
final state = int.tryParse(acState) ?? -1;
|
||||
if (state == 1) {
|
||||
acStr = '开启';
|
||||
acColor = const Color(0xFF00B42A);
|
||||
} else if (state == 0) {
|
||||
acStr = '关闭';
|
||||
acColor = const Color(0xFF86909C);
|
||||
}
|
||||
}
|
||||
|
||||
bool hasAlarm = false;
|
||||
if (alarmState != null) {
|
||||
final state = int.tryParse(alarmState) ?? 0;
|
||||
hasAlarm = state != 0;
|
||||
}
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
@@ -371,6 +530,37 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
if (hasAlarm)
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF53F3F).withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: const Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.warning_amber,
|
||||
size: 14,
|
||||
color: Color(0xFFF53F3F),
|
||||
),
|
||||
SizedBox(width: 4),
|
||||
Text(
|
||||
'告警',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Color(0xFFF53F3F),
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
@@ -392,9 +582,7 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const Divider(height: 1, color: Color(0xFFF2F3F5)),
|
||||
const SizedBox(height: 16),
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoRow(
|
||||
'机场名称',
|
||||
detail.callsign.isNotEmpty ? detail.callsign : '未知',
|
||||
@@ -413,17 +601,13 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
? '${detail.capacityPercent}%'
|
||||
: '未知',
|
||||
),
|
||||
_buildInfoRow(
|
||||
'环境温度',
|
||||
detail.environmentTemperature != null
|
||||
? '${detail.environmentTemperature}°C'
|
||||
: '未知',
|
||||
),
|
||||
_buildInfoRow(
|
||||
'风速',
|
||||
detail.windSpeed != null ? '${detail.windSpeed} m/s' : '未知',
|
||||
),
|
||||
_buildInfoRow('降雨量', _formatRainfall(detail.rainfall)),
|
||||
_buildInfoRowColor('环境温度', envTempStr, const Color(0xFF165DFF)),
|
||||
_buildInfoRowColor('湿度', humidityStr, const Color(0xFF00B42A)),
|
||||
_buildInfoRowColor('风速', windStr, const Color(0xFF722ED1)),
|
||||
_buildInfoRowColor('降雨量', rainfallStr, const Color(0xFF00B42A)),
|
||||
_buildInfoRowColor('机库舱门', coverStr, coverColor),
|
||||
_buildInfoRowColor('无人机位置', droneDockStr, droneDockColor),
|
||||
_buildInfoRowColor('空调状态', acStr, acColor),
|
||||
_buildInfoRow('网络状态', detail.networkState?.toString() ?? '未知'),
|
||||
_buildPositionStateRow('位置状态', detail.positionState),
|
||||
],
|
||||
@@ -431,6 +615,41 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInfoRowColor(String label, String value, Color valueColor) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 80,
|
||||
child: Text(
|
||||
label,
|
||||
style: const TextStyle(fontSize: 12, color: Color(0xFF86909C)),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Text(
|
||||
':',
|
||||
style: TextStyle(fontSize: 12, color: Color(0xFFC0C4CC)),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
value,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: valueColor,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
textAlign: TextAlign.left,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPositionStateRow(String label, PositionState? positionState) {
|
||||
String value = '未知';
|
||||
if (positionState != null) {
|
||||
|
||||
@@ -229,6 +229,18 @@ class _DroneStationStatusPageState extends State<DroneStationStatusPage> {
|
||||
const SizedBox(height: 12),
|
||||
_buildStatusRow('舱门状态', '关闭', status: '正常'),
|
||||
const SizedBox(height: 12),
|
||||
_buildStatusRow(
|
||||
'机场空调',
|
||||
_uavDetail?.airConditionerStatus ?? '未开启',
|
||||
status: (_uavDetail?.airConditionerStatus == '开启') ? '正常' : '关闭',
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_buildStatusRow(
|
||||
'机库状态',
|
||||
_uavDetail?.hangarStatus ?? '关闭',
|
||||
status: (_uavDetail?.hangarStatus == '开启') ? '正常' : '关闭',
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_buildStatusRowWithProgress('充电状态', '充电中', '85%'),
|
||||
const SizedBox(height: 12),
|
||||
_buildWeatherRow(),
|
||||
@@ -319,8 +331,6 @@ class _DroneStationStatusPageState extends State<DroneStationStatusPage> {
|
||||
color: Color(0xFF1D2129),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_buildDroneBatteryRow(),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:math';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:volc_engine_rtc/volc_engine_rtc.dart' as volc;
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import '../../../../../core/consts/http_api_consts.dart';
|
||||
import '../../../../../core/di/injection.dart';
|
||||
import '../../../../../core/managers/drone_task_state_manager.dart';
|
||||
import '../../../../../core/network/dio_client.dart';
|
||||
import '../../../../../core/network/mqtt/data/datasources/drone_osd_datasource.dart';
|
||||
import '../../../../../core/network/mqtt/domain/entities/drone_osd_entity.dart';
|
||||
import '../../domain/entities/uav_video_stream_entity.dart';
|
||||
@@ -47,6 +52,11 @@ class _DroneVideoControlPageState extends State<DroneVideoControlPage> {
|
||||
List<CameraInfo> _effectiveCameraList = []; // 实际使用的摄像头列表
|
||||
List<CameraInfo>? _backupCameraList; // 备选摄像头列表(网关摄像头)
|
||||
|
||||
// 暂停状态
|
||||
bool _isPaused = false;
|
||||
// 任务下发后等待视频流(用于显示“无人机已启动 视频获取中”toast)
|
||||
bool _isWaitingForVideo = false;
|
||||
|
||||
// 火山引擎 RTC
|
||||
volc.RTCEngine? _rtcEngine;
|
||||
volc.RTCRoom? _rtcRoom;
|
||||
@@ -64,6 +74,9 @@ class _DroneVideoControlPageState extends State<DroneVideoControlPage> {
|
||||
List<LatLng> _trajectoryPoints = [];
|
||||
LatLng? _currentPosition;
|
||||
double? _currentHeading;
|
||||
|
||||
/// 从全局管理器恢复的轨迹点(避免退出后丢失)
|
||||
bool _hasRestoredTrajectory = false;
|
||||
StreamSubscription<DroneOsdEntity>? _osdSubscription;
|
||||
DroneOsdDataSource? _droneOsdDataSource;
|
||||
|
||||
@@ -72,6 +85,23 @@ class _DroneVideoControlPageState extends State<DroneVideoControlPage> {
|
||||
super.initState();
|
||||
_bloc = sl<DroneStationBloc>();
|
||||
|
||||
// 🔥 初始化"等待视频流"状态(任务下发后进入此页面时显示 toast)
|
||||
_isWaitingForVideo = droneTaskStateManager.isWaitingForVideo.value;
|
||||
droneTaskStateManager.isWaitingForVideo.addListener(_onVideoWaitingChanged);
|
||||
|
||||
// 🔥 从全局管理器恢复历史轨迹(退出视频页后重新进入时不丢失)
|
||||
final savedPoints = droneTaskStateManager.trajectoryPoints.value;
|
||||
if (savedPoints.isNotEmpty) {
|
||||
_trajectoryPoints = savedPoints
|
||||
.map((p) => LatLng(p.latitude, p.longitude))
|
||||
.toList();
|
||||
_currentPosition = _trajectoryPoints.last;
|
||||
_hasRestoredTrajectory = true;
|
||||
debugPrint(
|
||||
'🗺️ [DroneVideoControlPage] 恢复历史轨迹: ${_trajectoryPoints.length} 个点',
|
||||
);
|
||||
}
|
||||
|
||||
// 🔥 初始化 MQTT OSD 数据源
|
||||
_droneOsdDataSource = sl<DroneOsdDataSource>();
|
||||
_startOsdListening();
|
||||
@@ -123,11 +153,101 @@ class _DroneVideoControlPageState extends State<DroneVideoControlPage> {
|
||||
// 默认加载广角镜头
|
||||
if (_currentCamera != null) {
|
||||
_loadVideoStream(UavLensType.wide);
|
||||
} else {
|
||||
// 摄像头列表为空(任务下发后无人机刚上线,详情接口尚未返回摄像头数据)
|
||||
// 自动获取无人机详情,拿到摄像头列表
|
||||
_fetchDroneDetailAndLoadCamera();
|
||||
}
|
||||
}
|
||||
|
||||
/// 自动获取无人机详情,拿到摄像头列表
|
||||
/// 任务下发后无人机刚上线,传入的 cameraList 可能为空
|
||||
Future<void> _fetchDroneDetailAndLoadCamera() async {
|
||||
debugPrint('🔍 [DroneVideoControlPage] 摄像头列表为空,自动获取无人机详情');
|
||||
try {
|
||||
final response = await Dio().get(
|
||||
HttpApiConsts.getUAVDetail,
|
||||
queryParameters: {
|
||||
'gatewaySn': widget.gatewaySn,
|
||||
'deviceSn': widget.droneSn,
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final Map<String, dynamic> jsonData = (response.data is String)
|
||||
? json.decode(response.data)
|
||||
: Map<String, dynamic>.from(response.data);
|
||||
|
||||
if (jsonData['code'] == 0 || jsonData['code'] == 200) {
|
||||
final detailData = jsonData['data'];
|
||||
final Map<String, dynamic> detailMap = (detailData is Map)
|
||||
? Map<String, dynamic>.from(detailData)
|
||||
: <String, dynamic>{};
|
||||
|
||||
final droneDetail = UAVDetailEntity.fromJson(detailMap);
|
||||
final cameras = droneDetail.droneCameraList ?? [];
|
||||
|
||||
debugPrint('✅ [DroneVideoControlPage] 获取到摄像头列表: ${cameras.length}');
|
||||
|
||||
if (cameras.isNotEmpty && mounted) {
|
||||
setState(() {
|
||||
_effectiveCameraList = cameras;
|
||||
_currentCamera = cameras.first;
|
||||
_useBackupSource = false;
|
||||
});
|
||||
_loadVideoStream(UavLensType.wide);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 如果无人机摄像头仍然为空,尝试网关摄像头
|
||||
if (mounted) {
|
||||
_tryGatewayCameraFallback();
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('❌ [DroneVideoControlPage] 获取无人机详情失败: $e');
|
||||
if (mounted) {
|
||||
_tryGatewayCameraFallback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 尝试使用网关摄像头作为备选
|
||||
void _tryGatewayCameraFallback() {
|
||||
if (widget.gatewayCameraList != null &&
|
||||
widget.gatewayCameraList!.isNotEmpty &&
|
||||
_currentCamera == null) {
|
||||
debugPrint('⚠️ [DroneVideoControlPage] 使用网关摄像头作为备选');
|
||||
setState(() {
|
||||
_effectiveCameraList = widget.gatewayCameraList!;
|
||||
_currentCamera = _effectiveCameraList.first;
|
||||
_useBackupSource = true;
|
||||
});
|
||||
_loadVideoStream(UavLensType.wide);
|
||||
} else {
|
||||
setState(() {
|
||||
_errorMessage = '没有可用的摄像头';
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _onVideoWaitingChanged() {
|
||||
if (!mounted) return;
|
||||
final waiting = droneTaskStateManager.isWaitingForVideo.value;
|
||||
if (waiting != _isWaitingForVideo) {
|
||||
setState(() {
|
||||
_isWaitingForVideo = waiting;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
droneTaskStateManager.isWaitingForVideo.removeListener(
|
||||
_onVideoWaitingChanged,
|
||||
);
|
||||
_osdSubscription?.cancel();
|
||||
_droneOsdDataSource?.dispose();
|
||||
_mapController?.dispose();
|
||||
@@ -253,13 +373,16 @@ class _DroneVideoControlPageState extends State<DroneVideoControlPage> {
|
||||
gatewaySn: widget.gatewaySn,
|
||||
);
|
||||
|
||||
_osdSubscription = _droneOsdDataSource!.droneOsdStream.listen((osdData) {
|
||||
if (!mounted) return;
|
||||
debugPrint('📡 [DroneVideoControlPage] 收到 droneOsdStream 事件');
|
||||
_handleOsdUpdate(osdData);
|
||||
}, onError: (error) {
|
||||
debugPrint('❌ [DroneVideoControlPage] OSD 监听错误: $error');
|
||||
});
|
||||
_osdSubscription = _droneOsdDataSource!.droneOsdStream.listen(
|
||||
(osdData) {
|
||||
if (!mounted) return;
|
||||
debugPrint('📡 [DroneVideoControlPage] 收到 droneOsdStream 事件');
|
||||
_handleOsdUpdate(osdData);
|
||||
},
|
||||
onError: (error) {
|
||||
debugPrint('❌ [DroneVideoControlPage] OSD 监听错误: $error');
|
||||
},
|
||||
);
|
||||
|
||||
debugPrint('✅ [DroneVideoControlPage] OSD 监听已启动');
|
||||
}
|
||||
@@ -268,103 +391,110 @@ class _DroneVideoControlPageState extends State<DroneVideoControlPage> {
|
||||
void _handleOsdUpdate(DroneOsdEntity osdData) {
|
||||
// 从 rawData 中提取位置信息
|
||||
final rawData = osdData.rawData;
|
||||
|
||||
|
||||
// 🔥 尝试从嵌套结构中获取经纬度
|
||||
double? lat;
|
||||
double? lng;
|
||||
double? heading;
|
||||
|
||||
|
||||
// 路径1: rawData['data']['host']['99-0-0']['measure_target_latitude'] (无人机)
|
||||
if (rawData['data'] is Map &&
|
||||
(rawData['data'] as Map)['host'] is Map) {
|
||||
if (rawData['data'] is Map && (rawData['data'] as Map)['host'] is Map) {
|
||||
final host = (rawData['data'] as Map)['host'] as Map;
|
||||
|
||||
|
||||
// 尝试从 99-0-0 载荷获取(无人机)
|
||||
if (host.containsKey('99-0-0') && host['99-0-0'] is Map) {
|
||||
final payload = host['99-0-0'] as Map;
|
||||
lat = (payload['measure_target_latitude'] as num?)?.toDouble();
|
||||
lng = (payload['measure_target_longitude'] as num?)?.toDouble();
|
||||
debugPrint('✅ [DroneVideoControlPage] 从 99-0-0 获取位置: lat=$lat, lng=$lng');
|
||||
debugPrint(
|
||||
'✅ [DroneVideoControlPage] 从 99-0-0 获取位置: lat=$lat, lng=$lng',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// 如果 99-0-0 中没有,尝试从 host 直接获取(机场)
|
||||
if (lat == null || lng == null) {
|
||||
lat = (host['latitude'] as num?)?.toDouble();
|
||||
lng = (host['longitude'] as num?)?.toDouble();
|
||||
if (lat != null && lng != null) {
|
||||
debugPrint('✅ [DroneVideoControlPage] 从 host 获取位置: lat=$lat, lng=$lng');
|
||||
debugPrint(
|
||||
'✅ [DroneVideoControlPage] 从 host 获取位置: lat=$lat, lng=$lng',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 获取航向角
|
||||
heading = (host['attitude_head'] as num?)?.toDouble() ??
|
||||
(host['heading'] as num?)?.toDouble();
|
||||
heading =
|
||||
(host['attitude_head'] as num?)?.toDouble() ??
|
||||
(host['heading'] as num?)?.toDouble();
|
||||
}
|
||||
|
||||
|
||||
// 兼容旧格式:直接从 rawData 获取
|
||||
if (lat == null || lng == null) {
|
||||
lat = lat ?? (rawData['latitude'] as num?)?.toDouble() ??
|
||||
(rawData['lat'] as num?)?.toDouble();
|
||||
lng = lng ?? (rawData['longitude'] as num?)?.toDouble() ??
|
||||
(rawData['lng'] as num?)?.toDouble() ??
|
||||
(rawData['lon'] as num?)?.toDouble();
|
||||
heading = heading ?? (rawData['heading'] as num?)?.toDouble() ??
|
||||
(rawData['attitudeHeading'] as num?)?.toDouble();
|
||||
lat =
|
||||
lat ??
|
||||
(rawData['latitude'] as num?)?.toDouble() ??
|
||||
(rawData['lat'] as num?)?.toDouble();
|
||||
lng =
|
||||
lng ??
|
||||
(rawData['longitude'] as num?)?.toDouble() ??
|
||||
(rawData['lng'] as num?)?.toDouble() ??
|
||||
(rawData['lon'] as num?)?.toDouble();
|
||||
heading =
|
||||
heading ??
|
||||
(rawData['heading'] as num?)?.toDouble() ??
|
||||
(rawData['attitudeHeading'] as num?)?.toDouble();
|
||||
}
|
||||
|
||||
|
||||
debugPrint('🛰️ [DroneVideoControlPage] 收到 OSD 数据');
|
||||
debugPrint(' lat=$lat, lng=$lng, heading=$heading');
|
||||
debugPrint(' 当前轨迹点数: ${_trajectoryPoints.length}');
|
||||
debugPrint(' 当前位置: $_currentPosition');
|
||||
|
||||
|
||||
// 验证位置有效性
|
||||
if (lat != null && lng != null && lat.abs() <= 90 && lng.abs() <= 180) {
|
||||
final newPos = LatLng(lat, lng);
|
||||
|
||||
|
||||
// 轨迹"拉烟"逻辑:距离过滤(防止 GPS 抖动导致轨迹像乱麻)
|
||||
bool shouldAddPoint = false;
|
||||
if (_trajectoryPoints.isEmpty) {
|
||||
shouldAddPoint = true;
|
||||
} else {
|
||||
final distance = _calculateDistance(
|
||||
_trajectoryPoints.last.latitude,
|
||||
_trajectoryPoints.last.longitude,
|
||||
lat,
|
||||
lng,
|
||||
);
|
||||
// 只有移动超过 0.5 米才画线,否则认为是原地漂移
|
||||
shouldAddPoint = distance > 0.5;
|
||||
}
|
||||
|
||||
if (shouldAddPoint) {
|
||||
_trajectoryPoints.add(newPos);
|
||||
// 性能优化:只保留最近 1000 个点
|
||||
if (_trajectoryPoints.length > 1000) {
|
||||
_trajectoryPoints.removeAt(0);
|
||||
}
|
||||
// 🔥 同步到全局管理器(退出页面后不丢失)
|
||||
droneTaskStateManager.addTrajectoryPoint(
|
||||
DroneTrajectoryPoint(latitude: lat, longitude: lng, heading: heading),
|
||||
);
|
||||
}
|
||||
|
||||
setState(() {
|
||||
// 更新当前位置(驱动飞机 Marker)
|
||||
_currentPosition = newPos;
|
||||
_currentHeading = heading;
|
||||
|
||||
// 轨迹"拉烟"逻辑:距离过滤(防止 GPS 抖动导致轨迹像乱麻)
|
||||
if (_trajectoryPoints.isEmpty) {
|
||||
_trajectoryPoints.add(newPos);
|
||||
debugPrint('✅ [DroneVideoControlPage] 添加第一个轨迹点: $newPos');
|
||||
|
||||
// 🔥 重要:第一个点添加后,等待 UI 构建完成再移动地图
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (_mapController != null && mounted) {
|
||||
_mapController!.move(newPos, 18); // 缩放到 18 级
|
||||
debugPrint('🗺️ [DroneVideoControlPage] 首次定位到: $newPos');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
final distance = _calculateDistance(
|
||||
_trajectoryPoints.last.latitude,
|
||||
_trajectoryPoints.last.longitude,
|
||||
lat!, // ✅ 空安全:已经通过 if 检查,使用 ! 断言
|
||||
lng!, // ✅ 空安全:已经通过 if 检查,使用 ! 断言
|
||||
);
|
||||
debugPrint(' 📏 距离上一个点: ${distance.toStringAsFixed(2)} 米');
|
||||
// 只有移动超过 0.5 米才画线,否则认为是原地漂移
|
||||
if (distance > 0.5) {
|
||||
_trajectoryPoints.add(newPos);
|
||||
debugPrint('✅ [DroneVideoControlPage] 添加新轨迹点,当前总数: ${_trajectoryPoints.length}');
|
||||
// 性能优化:只保留最近 1000 个点
|
||||
if (_trajectoryPoints.length > 1000) {
|
||||
_trajectoryPoints.removeAt(0);
|
||||
}
|
||||
} else {
|
||||
debugPrint('⚠️ [DroneVideoControlPage] 距离不足0.5米(${distance.toStringAsFixed(2)}m),跳过此点');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 地图跟随:后续点也移动地图(保持飞机在视野中)
|
||||
|
||||
// 地图跟随:保持飞机在视野中
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (_mapController != null && mounted) {
|
||||
_mapController!.move(newPos, _mapController!.camera.zoom);
|
||||
debugPrint('🗺️ [DroneVideoControlPage] 地图已移动到: $newPos');
|
||||
if (_trajectoryPoints.length == 1) {
|
||||
_mapController!.move(newPos, 18); // 首次定位缩放到 18 级
|
||||
} else {
|
||||
_mapController!.move(newPos, _mapController!.camera.zoom);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -373,12 +503,20 @@ class _DroneVideoControlPageState extends State<DroneVideoControlPage> {
|
||||
}
|
||||
|
||||
/// 🔥 计算两点之间的距离(米)
|
||||
double _calculateDistance(double lat1, double lon1, double lat2, double lon2) {
|
||||
double _calculateDistance(
|
||||
double lat1,
|
||||
double lon1,
|
||||
double lat2,
|
||||
double lon2,
|
||||
) {
|
||||
const p = 0.017453292519943295; // Math.PI / 180
|
||||
final a = 0.5 -
|
||||
final a =
|
||||
0.5 -
|
||||
cos((lat2 - lat1) * p) / 2 +
|
||||
cos(lat1 * p) * cos(lat2 * p) * (1 - cos((lon2 - lon1) * p)) / 2;
|
||||
return 12742 * asin(sqrt(a)) * 1000; // 2 * R * asin(sqrt(a)) * 1000 (R = 6371km)
|
||||
return 12742 *
|
||||
asin(sqrt(a)) *
|
||||
1000; // 2 * R * asin(sqrt(a)) * 1000 (R = 6371km)
|
||||
}
|
||||
|
||||
// 初始化火山引擎事件处理器
|
||||
@@ -416,6 +554,8 @@ class _DroneVideoControlPageState extends State<DroneVideoControlPage> {
|
||||
);
|
||||
_isLoading = false;
|
||||
});
|
||||
// 收到视频流,隐藏“无人机已启动 视频获取中”toast
|
||||
droneTaskStateManager.markVideoReceived();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -664,58 +804,111 @@ class _DroneVideoControlPageState extends State<DroneVideoControlPage> {
|
||||
),
|
||||
],
|
||||
),
|
||||
body: BlocConsumer<DroneStationBloc, DroneStationState>(
|
||||
listener: (context, state) {
|
||||
if (state is UavVideoStreamLoaded) {
|
||||
setState(() {
|
||||
_videoStream = state.videoStream;
|
||||
});
|
||||
debugPrint('=== 视频流加载成功 ===');
|
||||
debugPrint('URL Type: ${state.videoStream.urlType}');
|
||||
body: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
BlocConsumer<DroneStationBloc, DroneStationState>(
|
||||
listener: (context, state) {
|
||||
if (state is UavVideoStreamLoaded) {
|
||||
setState(() {
|
||||
_videoStream = state.videoStream;
|
||||
});
|
||||
debugPrint('=== 视频流加载成功 ===');
|
||||
debugPrint('URL Type: ${state.videoStream.urlType}');
|
||||
|
||||
if (state.videoStream.urlType == 'volc') {
|
||||
_destroyRtcEngine();
|
||||
_initRtcEngine(state.videoStream);
|
||||
} else {
|
||||
setState(() {
|
||||
_errorMessage = '不支持的 URL 类型: ${state.videoStream.urlType}';
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
} else if (state is UavVideoStreamError) {
|
||||
setState(() {
|
||||
_errorMessage = '暂无视频';
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
return Column(
|
||||
children: [
|
||||
_buildTabBar(),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
_buildVideoPlayer(),
|
||||
const SizedBox(height: 12),
|
||||
// 🔥 实时轨迹地图(放在视频和飞行数据之间)
|
||||
_buildTrajectoryMap(),
|
||||
const SizedBox(height: 12),
|
||||
_buildFlightData(),
|
||||
const SizedBox(height: 12),
|
||||
_buildAIResults(),
|
||||
const SizedBox(height: 12),
|
||||
// 🔥 摇杆控制(单独一行)
|
||||
_buildJoystickControl(),
|
||||
const SizedBox(height: 16),
|
||||
_buildBottomToolbar(),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
if (state.videoStream.urlType == 'volc') {
|
||||
_destroyRtcEngine();
|
||||
_initRtcEngine(state.videoStream);
|
||||
} else {
|
||||
setState(() {
|
||||
_errorMessage =
|
||||
'不支持的 URL 类型: ${state.videoStream.urlType}';
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
} else if (state is UavVideoStreamError) {
|
||||
setState(() {
|
||||
_errorMessage = '暂无视频';
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
return Column(
|
||||
children: [
|
||||
_buildTabBar(),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
_buildVideoPlayer(),
|
||||
const SizedBox(height: 12),
|
||||
// 🔥 实时轨迹地图(放在视频和飞行数据之间)
|
||||
_buildTrajectoryMap(),
|
||||
const SizedBox(height: 12),
|
||||
_buildFlightData(),
|
||||
const SizedBox(height: 12),
|
||||
_buildAIResults(),
|
||||
const SizedBox(height: 12),
|
||||
// 抓拍/录像/变焦/补光灯(挪到滚动区内)
|
||||
_buildBottomToolbar(),
|
||||
],
|
||||
),
|
||||
),
|
||||
// 🔥 固定底部栏:方向控制 + 暂停 + 返航
|
||||
_buildFixedBottomBar(),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
if (_isWaitingForVideo)
|
||||
Positioned.fill(
|
||||
child: IgnorePointer(child: _buildVideoWaitingToast()),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 任务下发后等待视频流时的居中提示
|
||||
Widget _buildVideoWaitingToast() {
|
||||
return Center(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xE61D2129),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: const [
|
||||
BoxShadow(
|
||||
color: Color(0x29000000),
|
||||
blurRadius: 16,
|
||||
offset: Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: const [
|
||||
SizedBox(
|
||||
width: 32,
|
||||
height: 32,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 3,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 12),
|
||||
Text(
|
||||
'无人机已启动 视频获取中',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w500,
|
||||
decoration: TextDecoration.none,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -1073,7 +1266,7 @@ class _DroneVideoControlPageState extends State<DroneVideoControlPage> {
|
||||
debugPrint(' currentPosition: $_currentPosition');
|
||||
debugPrint(' currentHeading: $_currentHeading');
|
||||
debugPrint(' trajectoryPoints.length: ${_trajectoryPoints.length}');
|
||||
|
||||
|
||||
return Container(
|
||||
height: 200,
|
||||
decoration: BoxDecoration(
|
||||
@@ -1087,9 +1280,10 @@ class _DroneVideoControlPageState extends State<DroneVideoControlPage> {
|
||||
children: [
|
||||
// 🔥 地图
|
||||
FlutterMap(
|
||||
mapController: _mapController ??= MapController(), // ✅ 懒加载初始化
|
||||
mapController: _mapController ??= MapController(), // ✅ 懒加载初始化
|
||||
options: MapOptions(
|
||||
initialCenter: _currentPosition ?? const LatLng(39.9042, 116.4074),
|
||||
initialCenter:
|
||||
_currentPosition ?? const LatLng(39.9042, 116.4074),
|
||||
initialZoom: 18,
|
||||
interactionOptions: const InteractionOptions(
|
||||
flags: InteractiveFlag.all & ~InteractiveFlag.rotate,
|
||||
@@ -1098,7 +1292,8 @@ class _DroneVideoControlPageState extends State<DroneVideoControlPage> {
|
||||
children: [
|
||||
// 高德地图瓦片(最底层)
|
||||
TileLayer(
|
||||
urlTemplate: 'https://webst0{s}.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}',
|
||||
urlTemplate:
|
||||
'https://webst0{s}.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}',
|
||||
subdomains: ['1', '2', '3', '4'],
|
||||
userAgentPackageName: 'com.example.app',
|
||||
),
|
||||
@@ -1178,7 +1373,10 @@ class _DroneVideoControlPageState extends State<DroneVideoControlPage> {
|
||||
top: 8,
|
||||
right: 8,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black54,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
@@ -1206,81 +1404,138 @@ class _DroneVideoControlPageState extends State<DroneVideoControlPage> {
|
||||
);
|
||||
}
|
||||
|
||||
/// 🔥 摇杆控制(单独一行)
|
||||
Widget _buildJoystickControl() {
|
||||
/// 🔥 固定底部栏:暂停 + 返航(不随页面滚动)
|
||||
Widget _buildFixedBottomBar() {
|
||||
return Container(
|
||||
height: 200,
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: const [
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Color(0x0D000000),
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
blurRadius: 8,
|
||||
offset: Offset(0, 2),
|
||||
offset: const Offset(0, -2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFC9CDD4),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
// 暂停/恢复按钮
|
||||
_buildActionBtn(
|
||||
label: _isPaused ? '恢复' : '暂停',
|
||||
icon: _isPaused ? Icons.play_arrow : Icons.pause,
|
||||
color: _isPaused
|
||||
? const Color(0xFF00B42A)
|
||||
: const Color(0xFFFF7D00),
|
||||
onTap: () {
|
||||
if (_isPaused) {
|
||||
_sendFlightCommand('flighttask_recovery');
|
||||
} else {
|
||||
_sendFlightCommand('flighttask_pause');
|
||||
}
|
||||
setState(() => _isPaused = !_isPaused);
|
||||
},
|
||||
),
|
||||
Positioned(
|
||||
top: 16,
|
||||
child: IconButton(
|
||||
icon: const Icon(
|
||||
Icons.arrow_drop_up,
|
||||
size: 32,
|
||||
color: Color(0xFF4E5969),
|
||||
),
|
||||
onPressed: () {},
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
bottom: 16,
|
||||
child: IconButton(
|
||||
icon: const Icon(
|
||||
Icons.arrow_drop_down,
|
||||
size: 32,
|
||||
color: Color(0xFF4E5969),
|
||||
),
|
||||
onPressed: () {},
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
left: 16,
|
||||
child: IconButton(
|
||||
icon: const Icon(
|
||||
Icons.arrow_left,
|
||||
size: 32,
|
||||
color: Color(0xFF4E5969),
|
||||
),
|
||||
onPressed: () {},
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
right: 16,
|
||||
child: IconButton(
|
||||
icon: const Icon(
|
||||
Icons.arrow_right,
|
||||
size: 32,
|
||||
color: Color(0xFF4E5969),
|
||||
),
|
||||
onPressed: () {},
|
||||
),
|
||||
// 返航按钮
|
||||
_buildActionBtn(
|
||||
label: '返航',
|
||||
icon: Icons.flight_land,
|
||||
color: const Color(0xFF165DFF),
|
||||
onTap: () {
|
||||
_sendFlightCommand('return_home');
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 发送飞行指令
|
||||
Future<void> _sendFlightCommand(String command) async {
|
||||
try {
|
||||
final dio = DioClient.create();
|
||||
final response = await dio.post(
|
||||
'http://1.95.137.212:8081/iot/UAV/flightTaskCommand',
|
||||
data: {'command': command, 'deviceSn': widget.droneSn},
|
||||
);
|
||||
|
||||
debugPrint('✅ 飞行指令发送成功: $command, deviceSn: ${widget.droneSn}');
|
||||
debugPrint('响应: ${response.data}');
|
||||
|
||||
String message;
|
||||
switch (command) {
|
||||
case 'flighttask_pause':
|
||||
message = '已发送暂停指令';
|
||||
break;
|
||||
case 'flighttask_recovery':
|
||||
message = '已发送恢复指令';
|
||||
break;
|
||||
case 'return_home':
|
||||
message = '命令下达成功';
|
||||
break;
|
||||
default:
|
||||
message = '指令发送成功';
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(message),
|
||||
duration: const Duration(seconds: 1),
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('❌ 飞行指令发送失败: $e');
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('指令发送失败'),
|
||||
duration: Duration(seconds: 2),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildActionBtn({
|
||||
required String label,
|
||||
required IconData icon,
|
||||
required Color color,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
|
||||
margin: const EdgeInsets.symmetric(horizontal: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.08),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: color.withOpacity(0.3)),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(icon, size: 20, color: color),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: color,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMapAndJoystick() {
|
||||
return Row(
|
||||
children: [
|
||||
@@ -1300,7 +1555,8 @@ class _DroneVideoControlPageState extends State<DroneVideoControlPage> {
|
||||
FlutterMap(
|
||||
mapController: _mapController,
|
||||
options: MapOptions(
|
||||
initialCenter: _currentPosition ?? const LatLng(39.9042, 116.4074),
|
||||
initialCenter:
|
||||
_currentPosition ?? const LatLng(39.9042, 116.4074),
|
||||
initialZoom: 18,
|
||||
interactionOptions: const InteractionOptions(
|
||||
flags: InteractiveFlag.all & ~InteractiveFlag.rotate,
|
||||
@@ -1309,7 +1565,8 @@ class _DroneVideoControlPageState extends State<DroneVideoControlPage> {
|
||||
children: [
|
||||
// 高德地图瓦片(最底层)
|
||||
TileLayer(
|
||||
urlTemplate: 'https://webst0{s}.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}',
|
||||
urlTemplate:
|
||||
'https://webst0{s}.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}',
|
||||
subdomains: ['1', '2', '3', '4'],
|
||||
userAgentPackageName: 'com.example.app',
|
||||
),
|
||||
@@ -1357,7 +1614,10 @@ class _DroneVideoControlPageState extends State<DroneVideoControlPage> {
|
||||
top: 8,
|
||||
left: 8,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.green,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
@@ -1389,14 +1649,20 @@ class _DroneVideoControlPageState extends State<DroneVideoControlPage> {
|
||||
top: 8,
|
||||
right: 8,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black54,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
'轨迹点: ${_trajectoryPoints.length}',
|
||||
style: const TextStyle(fontSize: 10, color: Colors.white),
|
||||
style: const TextStyle(
|
||||
fontSize: 10,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -0,0 +1,242 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mobile_scanner/mobile_scanner.dart';
|
||||
|
||||
class QrScannerPage extends StatefulWidget {
|
||||
const QrScannerPage({super.key});
|
||||
|
||||
@override
|
||||
State<QrScannerPage> createState() => _QrScannerPageState();
|
||||
}
|
||||
|
||||
class _QrScannerPageState extends State<QrScannerPage> {
|
||||
final MobileScannerController _controller = MobileScannerController();
|
||||
bool _isScanned = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onDetect(BarcodeCapture capture) {
|
||||
if (_isScanned) return;
|
||||
|
||||
final List<Barcode> barcodes = capture.barcodes;
|
||||
if (barcodes.isNotEmpty) {
|
||||
final String? code = barcodes.first.rawValue;
|
||||
if (code != null && code.isNotEmpty) {
|
||||
_isScanned = true;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (context.mounted && Navigator.canPop(context)) {
|
||||
Navigator.pop(context, code);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.black,
|
||||
body: Stack(
|
||||
children: [
|
||||
MobileScanner(controller: _controller, onDetect: _onDetect),
|
||||
SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(8, 8, 8, 0),
|
||||
child: Row(
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
Icons.close,
|
||||
color: Colors.white,
|
||||
size: 28,
|
||||
),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
const Expanded(
|
||||
child: Center(
|
||||
child: Text(
|
||||
'扫一扫',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 48),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
Center(
|
||||
child: Container(
|
||||
width: 250,
|
||||
height: 250,
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: Colors.white.withOpacity(0.3),
|
||||
width: 2,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Stack(
|
||||
children: [
|
||||
Positioned(
|
||||
top: 0,
|
||||
left: 0,
|
||||
child: Container(
|
||||
width: 30,
|
||||
height: 30,
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(
|
||||
top: BorderSide(
|
||||
color: Color(0xFF165DFF),
|
||||
width: 3,
|
||||
),
|
||||
left: BorderSide(
|
||||
color: Color(0xFF165DFF),
|
||||
width: 3,
|
||||
),
|
||||
),
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(12),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
top: 0,
|
||||
right: 0,
|
||||
child: Container(
|
||||
width: 30,
|
||||
height: 30,
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(
|
||||
top: BorderSide(
|
||||
color: Color(0xFF165DFF),
|
||||
width: 3,
|
||||
),
|
||||
right: BorderSide(
|
||||
color: Color(0xFF165DFF),
|
||||
width: 3,
|
||||
),
|
||||
),
|
||||
borderRadius: BorderRadius.only(
|
||||
topRight: Radius.circular(12),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
child: Container(
|
||||
width: 30,
|
||||
height: 30,
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
color: Color(0xFF165DFF),
|
||||
width: 3,
|
||||
),
|
||||
left: BorderSide(
|
||||
color: Color(0xFF165DFF),
|
||||
width: 3,
|
||||
),
|
||||
),
|
||||
borderRadius: BorderRadius.only(
|
||||
bottomLeft: Radius.circular(12),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
bottom: 0,
|
||||
right: 0,
|
||||
child: Container(
|
||||
width: 30,
|
||||
height: 30,
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
color: Color(0xFF165DFF),
|
||||
width: 3,
|
||||
),
|
||||
right: BorderSide(
|
||||
color: Color(0xFF165DFF),
|
||||
width: 3,
|
||||
),
|
||||
),
|
||||
borderRadius: BorderRadius.only(
|
||||
bottomRight: Radius.circular(12),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
const Text(
|
||||
'将二维码放入框内,即可自动扫描',
|
||||
style: TextStyle(color: Colors.white70, fontSize: 14),
|
||||
),
|
||||
const Spacer(),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 40),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
_buildActionButton(
|
||||
icon: Icons.flash_on,
|
||||
label: '手电筒',
|
||||
onTap: () async {
|
||||
await _controller.toggleTorch();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildActionButton({
|
||||
required IconData icon,
|
||||
required String label,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.15),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(icon, color: Colors.white, size: 24),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(color: Colors.white70, fontSize: 13),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user