页面UI替换1远程遥控和各项弹窗和作业主页面和子页面+路径规划的主页面重构等
This commit is contained in:
@@ -0,0 +1,574 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
|
||||
import '../../../../devices/domain/entities/device_entity.dart';
|
||||
import '../../../../remote_control/presentation/bloc/remote_control_cubit.dart';
|
||||
import '../../../local_camera/presentation/pages/local_camera_page.dart';
|
||||
import '../../data/models/robot_data_model.dart';
|
||||
import '../widgets/device_card_v2.dart';
|
||||
import '../widgets/find_robot_sheet.dart';
|
||||
import '../widgets/voice_broadcast_sheet.dart';
|
||||
import 'robot_app_power_page_v2.dart';
|
||||
import 'robot_control_page.dart';
|
||||
import 'robot_fault_center_page_v2.dart';
|
||||
import 'robot_full_info_page_v2.dart';
|
||||
import 'robot_location_page_v2.dart';
|
||||
import 'robot_run_record_page_v2.dart';
|
||||
import 'robot_sensor_page_v2.dart';
|
||||
import 'robot_voice_preset_page_v2.dart';
|
||||
|
||||
/// 全部功能中心 V2:设备详情页「查看全部功能」进入的二级页。
|
||||
///
|
||||
/// - 分组与磁贴严格按设计稿:视频与操作 / 设备信息 / 设备监测
|
||||
/// (设计稿被遮盖的两块为 传感器监测、故障诊断);
|
||||
/// - 设计稿未画出的「人员跟随」按补充需求加入设备监测分组(横版磁贴+副标题);
|
||||
/// - 设计稿底部 tab 不参考不做(本页为 push 二级页,无底部导航);
|
||||
/// - 实时图传与远程遥控拆为两个独立入口:前者进 LocalCameraPage(本地 RTSP/USB 实时画面),
|
||||
/// 后者进 RobotControlPage(远程操控,前置 setTargetDevice 与旧直进分支逐行一致);
|
||||
/// - 其余未开发入口统一胶囊提示。
|
||||
class DeviceAllFunctionsPageV2 extends StatefulWidget {
|
||||
final RobotDataModel robot;
|
||||
|
||||
const DeviceAllFunctionsPageV2({super.key, required this.robot});
|
||||
|
||||
@override
|
||||
State<DeviceAllFunctionsPageV2> createState() =>
|
||||
_DeviceAllFunctionsPageV2State();
|
||||
}
|
||||
|
||||
class _FuncItem {
|
||||
final IconData icon;
|
||||
final String label;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
const _FuncItem(this.icon, this.label, [this.onTap]);
|
||||
}
|
||||
|
||||
class _DeviceAllFunctionsPageV2State extends State<DeviceAllFunctionsPageV2> {
|
||||
static const _navy = Color(0xFF1A2B4A);
|
||||
static const _gray = Color(0xFF86909C);
|
||||
static const _blue = Color(0xFF1C96F6);
|
||||
static const _tileBg = Color(0xFFF6FAFE);
|
||||
static const _tileBorder = Color(0xFFD9E8F8);
|
||||
static const _cardBorder = Color(0xFFE5EDF7);
|
||||
static const _onlineGreen = Color(0xFF2FBF6B);
|
||||
static const _onlineBg = Color(0xFFE5F8EC);
|
||||
static const _offlineGray = Color(0xFF6B7280);
|
||||
static const _offlineBg = Color(0xFFF0F2F5);
|
||||
|
||||
final TextEditingController _searchCtrl = TextEditingController();
|
||||
String _query = '';
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_searchCtrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
bool get _online => widget.robot.isOnline;
|
||||
|
||||
String get _displayName {
|
||||
final alias = widget.robot.alias;
|
||||
return (alias != null && alias.isNotEmpty) ? alias : widget.robot.name;
|
||||
}
|
||||
|
||||
void _todo() => CapsuleToast.show('功能暂未开发', showCheck: false);
|
||||
|
||||
/// 机器人信息:进「机器人完整信息」页(W02 设计稿)
|
||||
void _openRobotInfo() {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => RobotFullInfoPageV2(robot: widget.robot),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 位置与地图:进「位置与地图详情」页(W03 设计稿)
|
||||
void _openLocationMap() {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => RobotLocationPageV2(robot: widget.robot),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 传感器监测:进「传感器与通信详情」页(W04 设计稿)
|
||||
void _openSensor() {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => RobotSensorPageV2(robot: widget.robot)),
|
||||
);
|
||||
}
|
||||
|
||||
/// 实时图传:与设备详情页「进入实时视频」同一目标页(本地 RTSP / USB 画面)
|
||||
void _openLiveVideo() {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => const LocalCameraPage()),
|
||||
);
|
||||
}
|
||||
|
||||
/// 语音喊话:进「预设语音管理」页(编辑预设播报文字 + 实时喊话占位)
|
||||
void _openVoicePreset() {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => RobotVoicePresetPageV2(robot: widget.robot),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// APP开关机:进「APP开关机与联动控制」页(远程上下电 + 联动解锁)
|
||||
void _openAppPower() {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => RobotAppPowerPageV2(robot: widget.robot),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 一键寻车:公共底部弹窗(设备详情页、控制页复用同一实现)
|
||||
void _openFindRobot() {
|
||||
showFindRobotSheet(context, robot: widget.robot);
|
||||
}
|
||||
|
||||
/// 语音喊话:公共底部弹窗(预设语音 + 实时喊话占位)
|
||||
void _openVoiceBroadcast() {
|
||||
showVoiceBroadcastSheet(context, robot: widget.robot);
|
||||
}
|
||||
|
||||
/// 故障诊断:进「故障诊断中心」页(当前故障 + 已恢复事件 + 故障码说明)
|
||||
void _openFaultCenter() {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => RobotFaultCenterPageV2(robot: widget.robot),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 运行记录:进「运行记录与健康分析」页(统计 + 趋势 + 时间轴)
|
||||
void _openRunRecord() {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => RobotRunRecordPageV2(robot: widget.robot),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 远程遥控:回旧控制页,前置与旧直进分支逐行一致
|
||||
void _openLegacyPage() {
|
||||
final robot = widget.robot;
|
||||
final device = DeviceEntity(
|
||||
deviceName: robot.name,
|
||||
productId: -1,
|
||||
productName: robot.type,
|
||||
tenantId: 0,
|
||||
tenantName: '',
|
||||
status: robot.isOnline ? 1 : 0,
|
||||
onlineStatus: robot.isOnline ? 1 : 0,
|
||||
);
|
||||
|
||||
final remoteCubit = GetIt.I<RemoteControlCubit>();
|
||||
remoteCubit.setTargetDevice(device);
|
||||
|
||||
final robotMap = <String, dynamic>{
|
||||
'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: (_) => RobotControlPage(robot: robotMap)),
|
||||
);
|
||||
}
|
||||
|
||||
List<(String, List<_FuncItem>)> _sections() {
|
||||
return [
|
||||
(
|
||||
'视频与操作',
|
||||
[
|
||||
_FuncItem(Icons.videocam_outlined, '实时图传', _openLiveVideo),
|
||||
_FuncItem(Icons.sports_esports_outlined, '远程遥控', _openLegacyPage),
|
||||
_FuncItem(Icons.location_on_outlined, '一键寻车', _openFindRobot),
|
||||
_FuncItem(Icons.mic_outlined, '语音喊话', _openVoiceBroadcast),
|
||||
_FuncItem(Icons.power_settings_new, 'APP开关机', _openAppPower),
|
||||
_FuncItem(Icons.person_outline, '人员跟随'),
|
||||
_FuncItem(Icons.home_outlined, '一键返航'),
|
||||
],
|
||||
),
|
||||
(
|
||||
'设备信息',
|
||||
[
|
||||
_FuncItem(Icons.smart_toy_outlined, '机器人信息', _openRobotInfo),
|
||||
_FuncItem(Icons.location_on_outlined, '位置与地图', _openLocationMap),
|
||||
// 预设语音管理也放在设备信息里(与「语音喊话」磁贴同一页)
|
||||
_FuncItem(Icons.record_voice_over_outlined, '预设语音', _openVoicePreset),
|
||||
_FuncItem(Icons.bar_chart, '运行记录', _openRunRecord),
|
||||
],
|
||||
),
|
||||
(
|
||||
'设备监测',
|
||||
[
|
||||
_FuncItem(Icons.sensors_outlined, '传感器监测', _openSensor),
|
||||
_FuncItem(Icons.warning_amber_outlined, '故障诊断', _openFaultCenter),
|
||||
],
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final sections = _sections()
|
||||
.map(
|
||||
(s) => (
|
||||
s.$1,
|
||||
s.$2
|
||||
.where((e) => _query.isEmpty || e.label.contains(_query))
|
||||
.toList(),
|
||||
),
|
||||
)
|
||||
.where((s) => s.$2.isNotEmpty)
|
||||
.toList();
|
||||
final tileWidth = (MediaQuery.of(context).size.width - 32 - 20) / 3;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFEDF6FD),
|
||||
body: Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [Color(0xFFD9EBFA), Color(0xFFEDF6FD)],
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildTopBar(),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 4, 16, 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_buildHeaderCard(),
|
||||
const SizedBox(height: 12),
|
||||
_buildNotice(),
|
||||
const SizedBox(height: 12),
|
||||
_buildSearch(),
|
||||
const SizedBox(height: 16),
|
||||
if (sections.isEmpty)
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 40),
|
||||
child: Text(
|
||||
'未找到匹配功能',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 13, color: _gray),
|
||||
),
|
||||
)
|
||||
else
|
||||
for (final s in sections) ...[
|
||||
_sectionTitle(s.$1),
|
||||
const SizedBox(height: 10),
|
||||
Wrap(
|
||||
spacing: 10,
|
||||
runSpacing: 10,
|
||||
children: [
|
||||
for (final item in s.$2)
|
||||
SizedBox(width: tileWidth, child: _tile(item)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 顶栏:返回 + 标题 + 信息按钮 =====
|
||||
Widget _buildTopBar() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 6, 16, 2),
|
||||
child: Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => Navigator.of(context).pop(),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _navy.withValues(alpha: 0.06),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(Icons.arrow_back_ios, color: _blue, size: 16),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Text(
|
||||
'全部功能中心',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
GestureDetector(
|
||||
onTap: _todo,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _navy.withValues(alpha: 0.06),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(Icons.info_outline, color: _blue, size: 18),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 设备头卡:图 + 名称/在线药丸 + 型号版本/SN =====
|
||||
Widget _buildHeaderCard() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 96,
|
||||
height: 78,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: const Color(0xFFEAF3FC),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: Image.asset(
|
||||
'assets/images/robot_logo_login.png',
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Flexible(
|
||||
child: Text(
|
||||
_displayName,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 3,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: _online ? _onlineBg : _offlineBg,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
_online ? '在线' : '离线',
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: _online ? _onlineGreen : _offlineGray,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'${widget.robot.type} · ${DeviceV2Display.editionOf(widget.robot.name)}',
|
||||
style: const TextStyle(fontSize: 12, color: _gray),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'SN: ${DeviceV2Display.maskedSn(widget.robot.name)}',
|
||||
style: const TextStyle(fontSize: 12, color: _gray),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 说明卡:当前设备 + 能力边界 =====
|
||||
Widget _buildNotice() {
|
||||
final device =
|
||||
'${widget.robot.type} · ${DeviceV2Display.editionOf(widget.robot.name)}';
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFEAF4FE),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: const Color(0xFFD6E9FC)),
|
||||
),
|
||||
child: Text.rich(
|
||||
TextSpan(
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
color: Color(0xFF5C6B84),
|
||||
height: 1.5,
|
||||
),
|
||||
children: [
|
||||
const TextSpan(text: '当前设备:'),
|
||||
TextSpan(
|
||||
text: device,
|
||||
style: const TextStyle(fontWeight: FontWeight.w700, color: _navy),
|
||||
),
|
||||
const TextSpan(text: '。仅展示设备实际支持的功能;本版不提供自主规划、任务下发及一键返航。'),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 搜索框:照搬设备页样式(白底/圆角 14/无内框),按磁贴名称实时过滤 =====
|
||||
Widget _buildSearch() {
|
||||
return Container(
|
||||
height: 44,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const SizedBox(width: 14),
|
||||
const Icon(Icons.search, size: 20, color: Color(0xFFC9CDD4)),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _searchCtrl,
|
||||
onChanged: (v) => setState(() => _query = v.trim()),
|
||||
style: const TextStyle(fontSize: 14, color: _navy),
|
||||
cursorColor: _blue,
|
||||
decoration: const InputDecoration(
|
||||
isDense: true,
|
||||
border: InputBorder.none,
|
||||
enabledBorder: InputBorder.none,
|
||||
focusedBorder: InputBorder.none,
|
||||
disabledBorder: InputBorder.none,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
hintText: '搜索功能名称',
|
||||
hintStyle: TextStyle(fontSize: 14, color: Color(0xFFB9C2CF)),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 分组标题:蓝色左竖条 + 粗体 =====
|
||||
Widget _sectionTitle(String title) {
|
||||
return Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 4,
|
||||
height: 16,
|
||||
decoration: BoxDecoration(
|
||||
color: _blue,
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 九宫格磁贴:细蓝描边 + 蓝图标 =====
|
||||
Widget _tile(_FuncItem item) {
|
||||
return GestureDetector(
|
||||
onTap: item.onTap ?? _todo,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: _tileBg,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: _tileBorder),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(item.icon, size: 26, color: _blue),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
item.label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -32,6 +32,7 @@ import '../../domain/entities/drone_station_entity.dart'; // 🔥 添加 DroneSt
|
||||
import 'robot_list_page.dart';
|
||||
import 'robot_control_page.dart';
|
||||
import 'device_detail_page_v2.dart';
|
||||
import 'robot_ownership_page_v2.dart';
|
||||
import 'drone_station_detail_page.dart';
|
||||
import '../../../../../core/network/mqtt/data/datasources/drone_osd_datasource.dart';
|
||||
import 'qr_scanner_page_v2.dart';
|
||||
@@ -39,12 +40,14 @@ import 'bind_device_page_v2.dart';
|
||||
import 'no_device_page_v2.dart';
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
import '../widgets/device_card_v2.dart';
|
||||
import '../widgets/rename_device_dialog.dart';
|
||||
import 'package:maibu_satabot_v2/features/pv_control/presentation/widgets/pv_work_map.dart';
|
||||
import '../../data/models/robot_data_model.dart';
|
||||
import '../../../local_camera/presentation/pages/local_camera_page.dart';
|
||||
import '../../../usb_camera/presentation/pages/usb_camera_page.dart';
|
||||
import '../../../../remote_control/presentation/bloc/remote_control_cubit.dart';
|
||||
import '../../../../devices/domain/entities/device_entity.dart';
|
||||
import '../../../../devices/domain/usecases/update_devicename_usecase.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
|
||||
/// 设备状态页面 V2 —— 按「02_设备卡片总览」设计稿换皮。
|
||||
@@ -93,21 +96,24 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// 🔥 个人角色(roleKey == 'personal')只有一个场站,自动默认选中第一个
|
||||
final siteCubit = sl<SiteCubit>();
|
||||
final roleKey = sl<AppUserCubit>().state.user?.roleKey;
|
||||
if (roleKey == TabConfig.personalRoleKey) {
|
||||
final siteCubit = sl<SiteCubit>();
|
||||
if (siteCubit.state.sites.isEmpty) {
|
||||
// 场站列表为空则先加载
|
||||
siteCubit.loadSites();
|
||||
} else if (siteCubit.state.selectedSite == null) {
|
||||
// 还没有选中场站则自动选中第一个
|
||||
final firstSite = siteCubit.state.sites.first;
|
||||
debugPrint(
|
||||
'🔥 [DeviceStatus] 个人角色自动选中首个场站: ${firstSite.siteName} (id=${firstSite.id})',
|
||||
);
|
||||
siteCubit.selectSite(firstSite);
|
||||
}
|
||||
|
||||
// 场站列表接口(GetSiteListUseCase)原本只由 SiteSelectorWidget 的 initState
|
||||
// 触发,而它只挂在首页/告警/工单这些页面上;底部 Tab 收敛为
|
||||
// 「设备/作业/我的」后这些页不再构建,场站会恒为空,设备列表也跟着空。
|
||||
// 这里统一兜底触发:SiteCubit 内部用 _hasLoadedSites 保证只真正请求一次。
|
||||
siteCubit.loadSites();
|
||||
|
||||
// 个人角色(roleKey == 'personal')只有一个场站,自动默认选中第一个
|
||||
if (roleKey == TabConfig.personalRoleKey &&
|
||||
siteCubit.state.sites.isNotEmpty &&
|
||||
siteCubit.state.selectedSite == null) {
|
||||
final firstSite = siteCubit.state.sites.first;
|
||||
debugPrint(
|
||||
'🔥 [DeviceStatus] 个人角色自动选中首个场站: ${firstSite.siteName} (id=${firstSite.id})',
|
||||
);
|
||||
siteCubit.selectSite(firstSite);
|
||||
}
|
||||
_currentSiteId = sl<SiteCubit>().state.selectedSite?.id;
|
||||
_siteSub = sl<SiteCubit>().stream.listen((siteState) {
|
||||
@@ -218,52 +224,53 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
child: Scaffold(
|
||||
backgroundColor: context.appColors.pageBackground,
|
||||
// SafeArea 下移到常规列表分支:无设备页渐变需铺进状态栏(与我的页一致)
|
||||
body: BlocConsumer<
|
||||
DeviceListBloc.DeviceStatusBloc,
|
||||
DeviceListState.DeviceStatusState
|
||||
>(
|
||||
listener: (context, state) {
|
||||
// 🔥 监听错误状态,显示友好提示
|
||||
if (state is DeviceListState.DeviceStatusError &&
|
||||
state.shouldShowError) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(state.message),
|
||||
duration: const Duration(seconds: 2),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
backgroundColor: context.appColors.warning,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
// 无设备:该场站设备接口返回空时,整页(含顶栏)切换到
|
||||
// 「01_无设备首页」设计稿页面;逻辑链保持 场站→siteId→设备列表 不变。
|
||||
if (_isNoDeviceState(state)) {
|
||||
return const NoDevicePageV2();
|
||||
}
|
||||
// 有数据:整页切到「02_设备卡片总览」设计稿 UI。
|
||||
if (state is DeviceListState.DeviceStatusLoaded) {
|
||||
return _buildV2Loaded(context, state);
|
||||
}
|
||||
// Initial / Loading:走 V2 骨架屏 + 旋转动画,避免切「设备」tab
|
||||
// 的一瞬间闪现旧版页面;数据到达后无缝切到卡片列表或无设备页。
|
||||
if (state is! DeviceListState.DeviceStatusError) {
|
||||
return _buildV2Skeleton(context);
|
||||
}
|
||||
// Error:保留旧布局兜底(含错误提示/重试),点击与数据逻辑完全一致。
|
||||
return SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildAppBar(context),
|
||||
_buildSearchBar(context),
|
||||
_buildTypeFilterBar(context),
|
||||
Expanded(child: _buildContent(context, state)),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
body:
|
||||
BlocConsumer<
|
||||
DeviceListBloc.DeviceStatusBloc,
|
||||
DeviceListState.DeviceStatusState
|
||||
>(
|
||||
listener: (context, state) {
|
||||
// 🔥 监听错误状态,显示友好提示
|
||||
if (state is DeviceListState.DeviceStatusError &&
|
||||
state.shouldShowError) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(state.message),
|
||||
duration: const Duration(seconds: 2),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
backgroundColor: context.appColors.warning,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
// 无设备:该场站设备接口返回空时,整页(含顶栏)切换到
|
||||
// 「01_无设备首页」设计稿页面;逻辑链保持 场站→siteId→设备列表 不变。
|
||||
if (_isNoDeviceState(state)) {
|
||||
return const NoDevicePageV2();
|
||||
}
|
||||
// 有数据:整页切到「02_设备卡片总览」设计稿 UI。
|
||||
if (state is DeviceListState.DeviceStatusLoaded) {
|
||||
return _buildV2Loaded(context, state);
|
||||
}
|
||||
// Initial / Loading:走 V2 骨架屏 + 旋转动画,避免切「设备」tab
|
||||
// 的一瞬间闪现旧版页面;数据到达后无缝切到卡片列表或无设备页。
|
||||
if (state is! DeviceListState.DeviceStatusError) {
|
||||
return _buildV2Skeleton(context);
|
||||
}
|
||||
// Error:保留旧布局兜底(含错误提示/重试),点击与数据逻辑完全一致。
|
||||
return SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildAppBar(context),
|
||||
_buildSearchBar(context),
|
||||
_buildTypeFilterBar(context),
|
||||
Expanded(child: _buildContent(context, state)),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -347,11 +354,8 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
);
|
||||
}
|
||||
},
|
||||
builder: (context, stationState) => _buildV2Scaffold(
|
||||
context,
|
||||
robotState,
|
||||
stationState,
|
||||
),
|
||||
builder: (context, stationState) =>
|
||||
_buildV2Scaffold(context, robotState, stationState),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -373,7 +377,8 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
),
|
||||
),
|
||||
SafeArea(
|
||||
bottom: false,
|
||||
// 底部导航已改为 extendBody 悬浮,背景由 Stack 铺满整屏,
|
||||
// 这里让内容底部让开悬浮导航,避免卡片被盖住
|
||||
child: Column(
|
||||
children: [
|
||||
_buildV2TopBar(context),
|
||||
@@ -421,9 +426,7 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
name: s.callsign.isNotEmpty ? s.callsign : sn,
|
||||
modelText: '无人机机场 · ${DeviceV2Display.editionOf(sn)}',
|
||||
snKey: sn,
|
||||
status: s.isOnline
|
||||
? DeviceV2Status.online
|
||||
: DeviceV2Status.offline,
|
||||
status: s.isOnline ? DeviceV2Status.online : DeviceV2Status.offline,
|
||||
battery: s.isOnline ? s.capacityPercent?.round() : null,
|
||||
station: s,
|
||||
),
|
||||
@@ -442,15 +445,12 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
.where((e) => e.status == DeviceV2Status.offline)
|
||||
.length;
|
||||
final visible = switch (_statusFilter) {
|
||||
'online' => items
|
||||
.where((e) => e.status != DeviceV2Status.offline)
|
||||
.toList(),
|
||||
'working' => items
|
||||
.where((e) => e.status == DeviceV2Status.working)
|
||||
.toList(),
|
||||
'offline' => items
|
||||
.where((e) => e.status == DeviceV2Status.offline)
|
||||
.toList(),
|
||||
'online' =>
|
||||
items.where((e) => e.status != DeviceV2Status.offline).toList(),
|
||||
'working' =>
|
||||
items.where((e) => e.status == DeviceV2Status.working).toList(),
|
||||
'offline' =>
|
||||
items.where((e) => e.status == DeviceV2Status.offline).toList(),
|
||||
_ => items,
|
||||
};
|
||||
|
||||
@@ -484,80 +484,94 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
),
|
||||
),
|
||||
SafeArea(
|
||||
bottom: false,
|
||||
child: Column(
|
||||
children: [
|
||||
_buildV2TopBar(context),
|
||||
_buildV2SiteEntry(context),
|
||||
_buildV2Header(),
|
||||
_buildViewToggle(),
|
||||
_buildV2SearchBox(),
|
||||
_buildStatusPills(
|
||||
items.length,
|
||||
onlineCount,
|
||||
workingCount,
|
||||
offlineCount,
|
||||
),
|
||||
Expanded(
|
||||
child: RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
// 与旧「全部」下拉刷新一致:统计 + 两个列表一起重拉
|
||||
context
|
||||
.read<DeviceListBloc.DeviceStatusBloc>()
|
||||
.add(const DeviceListEvent.DeviceStatusRefresh());
|
||||
setState(() => _refreshTick++);
|
||||
},
|
||||
color: _v2Blue,
|
||||
child: stillLoading
|
||||
? ListView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
children: const [
|
||||
SizedBox(height: 120),
|
||||
Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: _v2Blue,
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
: ListView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
padding: const EdgeInsets.fromLTRB(16, 6, 16, 24),
|
||||
children: [
|
||||
if (visible.isEmpty)
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(40),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'没有匹配的设备',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: _v2Gray,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
...visible.map(
|
||||
(e) => Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
bottom: 14,
|
||||
),
|
||||
child: DeviceCardV2(
|
||||
name: e.name,
|
||||
modelText: e.modelText,
|
||||
snKey: e.snKey,
|
||||
status: e.status,
|
||||
batteryLevel: e.battery,
|
||||
onTap: () => _v2ItemTap(context, e),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
// 整页一起滑:顶栏/场站入口/标题/视图切换随内容滚走,
|
||||
// 搜索框 + 状态药丸用 SliverPersistentHeader 吸顶
|
||||
child: RefreshIndicator(
|
||||
color: _v2Blue,
|
||||
edgeOffset: _v2PinnedExtentCard,
|
||||
onRefresh: () async {
|
||||
// 与旧「全部」下拉刷新一致:统计 + 两个列表一起重拉
|
||||
context.read<DeviceListBloc.DeviceStatusBloc>().add(
|
||||
const DeviceListEvent.DeviceStatusRefresh(),
|
||||
);
|
||||
setState(() => _refreshTick++);
|
||||
},
|
||||
child: CustomScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
slivers: [
|
||||
SliverToBoxAdapter(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildV2TopBar(context),
|
||||
_buildV2SiteEntry(context),
|
||||
_buildV2Header(),
|
||||
_buildViewToggle(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
SliverPersistentHeader(
|
||||
pinned: true,
|
||||
delegate: _V2PinnedHeaderDelegate(
|
||||
extent: _v2PinnedExtentCard,
|
||||
child: Column(
|
||||
children: [
|
||||
_buildV2SearchBox(),
|
||||
_buildStatusPills(
|
||||
items.length,
|
||||
onlineCount,
|
||||
workingCount,
|
||||
offlineCount,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (stillLoading)
|
||||
const SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(top: 120),
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(color: _v2Blue),
|
||||
),
|
||||
),
|
||||
)
|
||||
else if (visible.isEmpty)
|
||||
const SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(40),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'没有匹配的设备',
|
||||
style: TextStyle(fontSize: 13, color: _v2Gray),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 6, 16, 24),
|
||||
sliver: SliverList.builder(
|
||||
itemCount: visible.length,
|
||||
itemBuilder: (context, i) {
|
||||
final e = visible[i];
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 14),
|
||||
child: DeviceCardV2(
|
||||
name: e.name,
|
||||
modelText: e.modelText,
|
||||
snKey: e.snKey,
|
||||
status: e.status,
|
||||
batteryLevel: e.battery,
|
||||
onTap: () => _v2ItemTap(context, e),
|
||||
onMore: () => _v2ItemMore(context, e),
|
||||
onRename: () => _v2ItemRename(context, e),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -576,6 +590,62 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
return DeviceV2Status.working;
|
||||
}
|
||||
|
||||
/// 卡片右上角「...」:进「设备归属与安全」页(仅机器人有归属关系;机场暂未开发)
|
||||
void _v2ItemMore(BuildContext context, _V2DeviceItem item) {
|
||||
final robot = item.robot;
|
||||
if (robot == null) {
|
||||
CapsuleToast.show('功能暂未开发', showCheck: false);
|
||||
return;
|
||||
}
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => RobotOwnershipPageV2(robot: robot),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 卡片铅笔图标:修改设备名称(弹窗只负责输入,下发走真实 updateDeviceAlias)
|
||||
Future<void> _v2ItemRename(BuildContext context, _V2DeviceItem item) async {
|
||||
final robot = item.robot;
|
||||
if (robot == null) {
|
||||
CapsuleToast.show('功能暂未开发', showCheck: false);
|
||||
return;
|
||||
}
|
||||
final newName = await showRenameDeviceDialog(
|
||||
context,
|
||||
currentName: item.name,
|
||||
modelText: item.modelText,
|
||||
snKey: item.snKey,
|
||||
);
|
||||
// 取消 / 名称未变(与旧页一致:不调接口直接返回)
|
||||
if (newName == null || newName == item.name || !context.mounted) return;
|
||||
|
||||
final result = await sl<UpdateDevicenameUsecase>()(
|
||||
UpdateDevicenameParams(robot.id, newName),
|
||||
);
|
||||
if (!context.mounted) return;
|
||||
|
||||
result.fold(
|
||||
(failure) => CapsuleToast.show(
|
||||
failure.message.isEmpty ? '修改设备名称失败' : failure.message,
|
||||
showCheck: false,
|
||||
),
|
||||
(code) {
|
||||
if (code != 1) {
|
||||
CapsuleToast.show('修改设备名称失败:状态码 $code', showCheck: false);
|
||||
return;
|
||||
}
|
||||
CapsuleToast.show('设备名称已更新为「$newName」');
|
||||
// 刷新卡片列表(别名优先展示,重拉后即可看到新名称)
|
||||
context.read<RobotListBloc>().add(const RobotListRefresh());
|
||||
context.read<DeviceListBloc.DeviceStatusBloc>().add(
|
||||
const DeviceListEvent.DeviceStatusRefresh(),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// 卡片点击分发:与旧列表 onTap 逐行一致(机器人→hasHost 流程,机场→详情页)
|
||||
void _v2ItemTap(BuildContext context, _V2DeviceItem item) {
|
||||
final robot = item.robot;
|
||||
@@ -807,11 +877,7 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
),
|
||||
),
|
||||
trailing: selected
|
||||
? const Icon(
|
||||
Icons.check,
|
||||
size: 20,
|
||||
color: _v2Blue,
|
||||
)
|
||||
? const Icon(Icons.check, size: 20, color: _v2Blue)
|
||||
: null,
|
||||
onTap: () {
|
||||
// 选中后 _siteSub 监听会自动重拉全部数据
|
||||
@@ -969,12 +1035,7 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
}
|
||||
|
||||
// ===== 状态过滤药丸:真实生效 =====
|
||||
Widget _buildStatusPills(
|
||||
int all,
|
||||
int online,
|
||||
int working,
|
||||
int offline,
|
||||
) {
|
||||
Widget _buildStatusPills(int all, int online, int working, int offline) {
|
||||
final pills = [
|
||||
('all', '全部', all),
|
||||
('online', '在线', online),
|
||||
@@ -999,11 +1060,11 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: selected ? Colors.white : Colors.white.withValues(alpha: 0.45),
|
||||
color: selected
|
||||
? Colors.white
|
||||
: Colors.white.withValues(alpha: 0.45),
|
||||
borderRadius: BorderRadius.circular(15),
|
||||
border: Border.all(
|
||||
color: selected ? _v2Blue : _v2Border,
|
||||
),
|
||||
border: Border.all(color: selected ? _v2Blue : _v2Border),
|
||||
),
|
||||
child: Text(
|
||||
'$label ($count)',
|
||||
@@ -1022,7 +1083,7 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
}
|
||||
|
||||
// ===== 集中概览(03 设计稿):统计卡 + 分布地图 + 复用药丸 + 设备表格 =====
|
||||
|
||||
|
||||
Widget _buildV2Overview(
|
||||
BuildContext context,
|
||||
int all,
|
||||
@@ -1044,35 +1105,57 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
),
|
||||
),
|
||||
SafeArea(
|
||||
bottom: false,
|
||||
// 背景由 Stack 铺满整屏,内容让开底部悬浮导航
|
||||
child: Column(
|
||||
children: [
|
||||
_buildOverviewAppBar(),
|
||||
_buildOverviewHeader(),
|
||||
_buildViewToggle(),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
// 与卡片视图同口径:标题/视图切换随内容滚走,状态药丸吸顶
|
||||
child: CustomScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
padding: const EdgeInsets.fromLTRB(0, 0, 0, 24),
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 14, 16, 14),
|
||||
child: _buildStatCards(
|
||||
all,
|
||||
onlineCount,
|
||||
workingCount,
|
||||
offlineCount,
|
||||
slivers: [
|
||||
SliverToBoxAdapter(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildOverviewHeader(),
|
||||
_buildViewToggle(),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: _buildDistributionCard(context, all),
|
||||
SliverPersistentHeader(
|
||||
pinned: true,
|
||||
delegate: _V2PinnedHeaderDelegate(
|
||||
extent: _v2PinnedExtentPills,
|
||||
child: _buildStatusPills(
|
||||
all,
|
||||
onlineCount,
|
||||
workingCount,
|
||||
offlineCount,
|
||||
),
|
||||
),
|
||||
),
|
||||
// 状态标签栏:直接复用卡片视图同一套药丸组件
|
||||
_buildStatusPills(all, onlineCount, workingCount, offlineCount),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 10, 16, 0),
|
||||
child: _buildOverviewTable(visible),
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 14, 16, 14),
|
||||
child: _buildStatCards(
|
||||
all,
|
||||
onlineCount,
|
||||
workingCount,
|
||||
offlineCount,
|
||||
),
|
||||
),
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: _buildDistributionCard(context, all),
|
||||
),
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 10, 16, 24),
|
||||
child: _buildOverviewTable(visible),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -1084,7 +1167,7 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/// 概览顶栏:返回箭头回到卡片视图 + 标题
|
||||
Widget _buildOverviewAppBar() {
|
||||
return SizedBox(
|
||||
@@ -1112,7 +1195,7 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Widget _buildOverviewHeader() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 4, 16, 0),
|
||||
@@ -1139,7 +1222,7 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/// 四张统计卡:设备总数 / 在线设备 / 作业中 / 告警离线
|
||||
Widget _buildStatCards(int all, int online, int working, int offline) {
|
||||
final stats = [
|
||||
@@ -1185,7 +1268,7 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/// 设备分布卡:复用路径规划同源实时地图 PvWorkMap(interactive=false
|
||||
/// 防与外层 ListView 手势冲突,PV 小卡同款用法)
|
||||
Widget _buildDistributionCard(BuildContext context, int all) {
|
||||
@@ -1218,16 +1301,9 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
children: [
|
||||
Text(
|
||||
'共 $all 台设备',
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: _v2Blue,
|
||||
),
|
||||
),
|
||||
const Icon(
|
||||
Icons.chevron_right,
|
||||
size: 16,
|
||||
color: _v2Blue,
|
||||
style: const TextStyle(fontSize: 12, color: _v2Blue),
|
||||
),
|
||||
const Icon(Icons.chevron_right, size: 16, color: _v2Blue),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -1238,16 +1314,13 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
bottom: Radius.circular(15),
|
||||
),
|
||||
child: SizedBox(
|
||||
height: 200,
|
||||
child: PvWorkMap(interactive: false),
|
||||
),
|
||||
child: SizedBox(height: 200, child: PvWorkMap(interactive: false)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/// 设备列表表格:表头 + 行(点击复用卡片视图同一套 _v2ItemTap 逻辑)
|
||||
Widget _buildOverviewTable(List<_V2DeviceItem> visible) {
|
||||
return Container(
|
||||
@@ -1309,7 +1382,7 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Widget _buildOverviewRow(_V2DeviceItem e) {
|
||||
return GestureDetector(
|
||||
onTap: () => _v2ItemTap(context, e),
|
||||
@@ -1347,10 +1420,7 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
'${DeviceV2Display.versionOf(e.snKey)} SN: ${DeviceV2Display.maskedSn(e.snKey)}',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 10,
|
||||
color: _v2Gray,
|
||||
),
|
||||
style: const TextStyle(fontSize: 10, color: _v2Gray),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -1387,7 +1457,7 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Widget _buildOverviewBadge(DeviceV2Status status) {
|
||||
final (label, fg, bg, icon) = switch (status) {
|
||||
DeviceV2Status.working => (
|
||||
@@ -1435,13 +1505,13 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
String _buildOverviewBattery(_V2DeviceItem e) {
|
||||
final b = e.battery;
|
||||
if (e.status == DeviceV2Status.offline || b == null) return '—';
|
||||
return '$b%';
|
||||
}
|
||||
|
||||
|
||||
/// 行内设备缩略图:蓝渐变底 + logo;离线置灰
|
||||
Widget _buildOverviewThumb(_V2DeviceItem e) {
|
||||
final offline = e.status == DeviceV2Status.offline;
|
||||
@@ -1450,7 +1520,9 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
gradient: offline
|
||||
? const LinearGradient(colors: [Color(0xFFB9C0CB), Color(0xFF9AA3AF)])
|
||||
? const LinearGradient(
|
||||
colors: [Color(0xFFB9C0CB), Color(0xFF9AA3AF)],
|
||||
)
|
||||
: _v2BtnGradient,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
@@ -1458,7 +1530,7 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
child: Image.asset('assets/images/shebei-logo.png'),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// ===== 添加机器人底部弹层:与无设备页同一套,各项保留原跳转 =====
|
||||
void _showV2AddSheet(BuildContext context) {
|
||||
showModalBottomSheet(
|
||||
@@ -1489,11 +1561,7 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
Icons.close,
|
||||
size: 20,
|
||||
color: _v2Gray,
|
||||
),
|
||||
icon: const Icon(Icons.close, size: 20, color: _v2Gray),
|
||||
onPressed: () => Navigator.pop(sheetCtx),
|
||||
),
|
||||
],
|
||||
@@ -1515,9 +1583,9 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
);
|
||||
// 绑定后重拉:统计 + 机器人/机场列表一起刷新
|
||||
if (context.mounted) {
|
||||
context
|
||||
.read<DeviceListBloc.DeviceStatusBloc>()
|
||||
.add(const DeviceListEvent.DeviceStatusRefresh());
|
||||
context.read<DeviceListBloc.DeviceStatusBloc>().add(
|
||||
const DeviceListEvent.DeviceStatusRefresh(),
|
||||
);
|
||||
setState(() => _refreshTick++);
|
||||
}
|
||||
}
|
||||
@@ -1576,10 +1644,7 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
children: [
|
||||
Icon(icon, size: 20, color: _v2Navy),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(fontSize: 15, color: _v2Navy),
|
||||
),
|
||||
Text(label, style: const TextStyle(fontSize: 15, color: _v2Navy)),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -1839,7 +1904,7 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
final position = notification.metrics.pixels;
|
||||
final itemWidth = 56.0; // 预估每个 tab 的宽度(包括间距)
|
||||
final newIndex = (position / itemWidth).round();
|
||||
|
||||
|
||||
if (newIndex >= 0 &&
|
||||
newIndex < typeCodes.length &&
|
||||
newIndex != selectedIndex) {
|
||||
@@ -2004,7 +2069,9 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
_buildDroneStationList(
|
||||
context,
|
||||
embedded: true,
|
||||
key: ValueKey('embedded_drone_station_${_currentSiteId}_$_refreshTick'),
|
||||
key: ValueKey(
|
||||
'embedded_drone_station_${_currentSiteId}_$_refreshTick',
|
||||
),
|
||||
),
|
||||
// 🔥 普通设备列表(仅类型 tab 生效,"全部"模式下 filteredByType 为空)
|
||||
...filteredDevices
|
||||
@@ -2108,14 +2175,14 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
debugPrint(
|
||||
'🔴🔴🔴 [全部-选中机器人] name: ${robot.name}, id: ${robot.id}, type: ${robot.type}',
|
||||
);
|
||||
debugPrint(
|
||||
'🔴🔴🔴 [全部-选中机器人] hasHost: ${robot.hasHost}',
|
||||
);
|
||||
debugPrint('🔴🔴🔴 [全部-选中机器人] hasHost: ${robot.hasHost}');
|
||||
|
||||
// 🔥 hasHost 字段判定:false → 蓝牙连接流程
|
||||
if (!robot.hasHost) {
|
||||
debugPrint('⚠️ [全部-EmbeddedRobotList] hasHost=false,进入蓝牙连接流程');
|
||||
|
||||
debugPrint(
|
||||
'⚠️ [全部-EmbeddedRobotList] hasHost=false,进入蓝牙连接流程',
|
||||
);
|
||||
|
||||
// 从设备名中提取时间戳(如 MC700PRO-CN-JS-1751525588120-0000000A-9527 → 1751525588120)
|
||||
final timestamp = _extractTimestamp(robot.name);
|
||||
if (timestamp == null || timestamp.isEmpty) {
|
||||
@@ -2128,18 +2195,26 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
debugPrint('✅ [全部-EmbeddedRobotList] 提取到时间戳: $timestamp');
|
||||
|
||||
|
||||
debugPrint(
|
||||
'✅ [全部-EmbeddedRobotList] 提取到时间戳: $timestamp',
|
||||
);
|
||||
|
||||
// 调用蓝牙连接流程
|
||||
_connectToDeviceViaBluetooth(context, robot.name, timestamp);
|
||||
_connectToDeviceViaBluetooth(
|
||||
context,
|
||||
robot.name,
|
||||
timestamp,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// hasHost == true → 走原来的逻辑:前置(setTargetDevice)不变,
|
||||
// 跳转目标换成新设备详情页(V2 概览设计稿);
|
||||
// 页内铃铛/远程遥控再回旧 RobotControlPage,方便新旧对照。
|
||||
debugPrint('✅ [全部-EmbeddedRobotList] hasHost=true,走正常控制流程');
|
||||
debugPrint(
|
||||
'✅ [全部-EmbeddedRobotList] hasHost=true,走正常控制流程',
|
||||
);
|
||||
|
||||
// 1. 将当前机器人设置为全局待控制设备
|
||||
final device = DeviceEntity(
|
||||
@@ -2721,7 +2796,7 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
String timestamp,
|
||||
) async {
|
||||
final bleManager = BleManager.instance;
|
||||
|
||||
|
||||
// 🔥 0. 优先检查:如果该设备已经连接,直接跳转详情页,不再扫描
|
||||
final connectedDevice = bleManager.connectedDevice;
|
||||
if (connectedDevice != null) {
|
||||
@@ -2753,7 +2828,7 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 2. 显示加载圈
|
||||
showDialog(
|
||||
context: context,
|
||||
@@ -2776,13 +2851,13 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
|
||||
// 4. 关闭加载圈
|
||||
Navigator.of(context).pop();
|
||||
|
||||
|
||||
// 5. 获取扫描结果并查找匹配设备
|
||||
final scanResults = bleManager.getScanResults();
|
||||
BluetoothDevice? matchedDevice;
|
||||
for (final result in scanResults) {
|
||||
final devName = result.device.platformName.isNotEmpty
|
||||
? result.device.platformName
|
||||
final devName = result.device.platformName.isNotEmpty
|
||||
? result.device.platformName
|
||||
: result.device.advName;
|
||||
if (devName.contains(timestamp)) {
|
||||
matchedDevice = result.device;
|
||||
@@ -2790,17 +2865,15 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (matchedDevice != null) {
|
||||
debugPrint('🚀 [蓝牙连接] 跳转到 BLE 详情页并连接');
|
||||
final device = matchedDevice;
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => BleDeviceDetailPage(
|
||||
device: device,
|
||||
displayName: deviceName,
|
||||
),
|
||||
builder: (_) =>
|
||||
BleDeviceDetailPage(device: device, displayName: deviceName),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
@@ -2830,22 +2903,34 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
builder: (dialogContext) {
|
||||
dialogShown = true;
|
||||
return AlertDialog(
|
||||
title: Text(AppLocalizations.of(dialogContext).translate('device_list_v2.device_not_found_title')),
|
||||
content: Text(AppLocalizations.of(dialogContext).translate('device_list_v2.device_not_found_content')),
|
||||
title: Text(
|
||||
AppLocalizations.of(
|
||||
dialogContext,
|
||||
).translate('device_list_v2.device_not_found_title'),
|
||||
),
|
||||
content: Text(
|
||||
AppLocalizations.of(
|
||||
dialogContext,
|
||||
).translate('device_list_v2.device_not_found_content'),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
dialogShown = false;
|
||||
Navigator.pop(dialogContext);
|
||||
},
|
||||
child: Text(AppLocalizations.of(dialogContext).translate('common.cancel')),
|
||||
child: Text(
|
||||
AppLocalizations.of(dialogContext).translate('common.cancel'),
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
dialogShown = false;
|
||||
Navigator.pop(dialogContext);
|
||||
},
|
||||
child: Text(AppLocalizations.of(dialogContext).translate('common.confirm')),
|
||||
child: Text(
|
||||
AppLocalizations.of(dialogContext).translate('common.confirm'),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -2861,8 +2946,8 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
}
|
||||
|
||||
for (final result in results) {
|
||||
final devName = result.device.platformName.isEmpty
|
||||
? result.device.advName
|
||||
final devName = result.device.platformName.isEmpty
|
||||
? result.device.advName
|
||||
: result.device.platformName;
|
||||
|
||||
if (devName.contains(timestamp)) {
|
||||
@@ -2891,6 +2976,64 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
|
||||
}
|
||||
|
||||
/// V2 卡片列表的统一展示项:机器人 / 无人机机场二选一
|
||||
/// 吸顶过滤栏高度:卡片视图 = 搜索框(56) + 状态药丸(42)
|
||||
const double _v2PinnedExtentCard = 98;
|
||||
|
||||
/// 吸顶过滤栏高度:集中概览视图 = 状态药丸(42)
|
||||
const double _v2PinnedExtentPills = 42;
|
||||
|
||||
/// 吸顶过滤栏:滚动压过内容时平滑补上底色与阴影,避免卡片从下方穿帮
|
||||
class _V2PinnedHeaderDelegate extends SliverPersistentHeaderDelegate {
|
||||
final double extent;
|
||||
final Widget child;
|
||||
|
||||
const _V2PinnedHeaderDelegate({required this.extent, required this.child});
|
||||
|
||||
@override
|
||||
double get minExtent => extent;
|
||||
|
||||
@override
|
||||
double get maxExtent => extent;
|
||||
|
||||
@override
|
||||
Widget build(
|
||||
BuildContext context,
|
||||
double shrinkOffset,
|
||||
bool overlapsContent,
|
||||
) {
|
||||
// 跟手动画:底色与阴影随滚动距离连续淡入(18px 内完成),
|
||||
// 滚回顶部时同样连续淡出,不会出现「咔嚓」硬切。
|
||||
final double t = (shrinkOffset / 18).clamp(0.0, 1.0);
|
||||
final double lift = Curves.easeOutCubic.transform(t);
|
||||
return Stack(
|
||||
children: [
|
||||
if (lift > 0)
|
||||
Positioned.fill(
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFFAFCFF).withValues(alpha: 0.96 * lift),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _DeviceStatusViewV2State._v2Blue.withValues(
|
||||
alpha: 0.10 * lift,
|
||||
),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
child,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRebuild(covariant _V2PinnedHeaderDelegate oldDelegate) =>
|
||||
oldDelegate.extent != extent || oldDelegate.child != child;
|
||||
}
|
||||
|
||||
class _V2DeviceItem {
|
||||
const _V2DeviceItem({
|
||||
required this.name,
|
||||
|
||||
@@ -0,0 +1,942 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
|
||||
import '../../data/models/robot_data_model.dart';
|
||||
import '../widgets/device_confirm_dialog.dart';
|
||||
import '../widgets/find_robot_sheet.dart';
|
||||
import '../widgets/robot_summary_card_v2.dart';
|
||||
import '../widgets/voice_broadcast_sheet.dart';
|
||||
|
||||
/// 一条联动操作(远程开机后才解锁)
|
||||
class _LinkageItem {
|
||||
final IconData icon;
|
||||
final String label;
|
||||
|
||||
/// 主操作文案
|
||||
final String action;
|
||||
|
||||
/// 次操作文案,null 表示只有一个操作(如急停)
|
||||
final String? secondary;
|
||||
|
||||
/// 主操作是否红色危险态
|
||||
final bool danger;
|
||||
|
||||
/// 次操作是否走「语音喊话」公共弹窗(鸣笛/语音里的语音播报)
|
||||
final bool voiceSecondary;
|
||||
|
||||
const _LinkageItem({
|
||||
required this.icon,
|
||||
required this.label,
|
||||
required this.action,
|
||||
this.secondary,
|
||||
this.danger = false,
|
||||
this.voiceSecondary = false,
|
||||
});
|
||||
}
|
||||
|
||||
/// APP开关机与联动控制(设计稿:全部功能中心 → APP开关机)
|
||||
///
|
||||
/// 二级 push 页面,无底部导航。
|
||||
///
|
||||
/// 后端目前没有独立的远程上下电 HTTP 接口,只有遥控通道里的点火位
|
||||
/// (`MachineControlStatusEntity.ignitionStatus`:0 停 / 1 点火 / 2 熄火),
|
||||
/// 且必须先取得控制权、进入遥控控制循环才会真正下发。因此本页:
|
||||
/// - 动作前一律走 [showDeviceConfirmDialog] 安全确认(公共组件,多处复用);
|
||||
/// - [onPowerOn] / [onPowerOff] / [onLinkageAction] 未注入时只做明确提示,
|
||||
/// 不修改界面状态,避免把「没发出去」显示成「已开机」;
|
||||
/// - 联动操作(割刀、底盘、灯光、鸣笛)在未开机时锁定;
|
||||
/// - 一键寻车、语音喊话直接复用公共弹窗,与其它入口同一实现。
|
||||
class RobotAppPowerPageV2 extends StatefulWidget {
|
||||
final RobotDataModel robot;
|
||||
|
||||
/// 初始开机状态:接入真实点火状态后从这里传入
|
||||
final bool initialPowered;
|
||||
|
||||
/// 远程上电通道;为 null 时仅做安全确认并提示未接入
|
||||
final VoidCallback? onPowerOn;
|
||||
|
||||
/// 远程下电通道;为 null 时仅做安全确认并提示未接入
|
||||
final VoidCallback? onPowerOff;
|
||||
|
||||
/// 联动操作回调;为 null 时提示未接入
|
||||
final void Function(String action)? onLinkageAction;
|
||||
|
||||
const RobotAppPowerPageV2({
|
||||
super.key,
|
||||
required this.robot,
|
||||
this.initialPowered = false,
|
||||
this.onPowerOn,
|
||||
this.onPowerOff,
|
||||
this.onLinkageAction,
|
||||
});
|
||||
|
||||
@override
|
||||
State<RobotAppPowerPageV2> createState() => _RobotAppPowerPageV2State();
|
||||
}
|
||||
|
||||
class _RobotAppPowerPageV2State extends State<RobotAppPowerPageV2> {
|
||||
static const Color _navy = Color(0xFF1A2B4A);
|
||||
static const Color _gray = Color(0xFF86909C);
|
||||
static const Color _hint = Color(0xFFA8B3C5);
|
||||
static const Color _blue = Color(0xFF1C96F6);
|
||||
static const Color _danger = Color(0xFFF0604D);
|
||||
static const Color _cardBorder = Color(0xFFE5EDF7);
|
||||
static const Color _softBlue = Color(0xFFEAF3FE);
|
||||
static const Color _segBg = Color(0xFFF6FAFE);
|
||||
static const Color _segBorder = Color(0xFFDCEBFA);
|
||||
static const Color _lockedBg = Color(0xFFF4F6F9);
|
||||
static const Color _lockedText = Color(0xFFB0BAC9);
|
||||
static const Color _green = Color(0xFF2FBF6B);
|
||||
static const Color _greenBg = Color(0xFFE5F8EC);
|
||||
|
||||
late bool _powered = widget.initialPowered;
|
||||
|
||||
bool get _online => widget.robot.isOnline;
|
||||
|
||||
/// 联动操作清单,顺序与设计稿一致
|
||||
static const List<_LinkageItem> _linkages = [
|
||||
_LinkageItem(
|
||||
icon: Icons.content_cut,
|
||||
label: '割刀启停',
|
||||
action: '启动',
|
||||
secondary: '停止',
|
||||
),
|
||||
_LinkageItem(
|
||||
icon: Icons.unfold_more_rounded,
|
||||
label: '底盘升降',
|
||||
action: '升起',
|
||||
secondary: '降下',
|
||||
),
|
||||
_LinkageItem(
|
||||
icon: Icons.emergency_outlined,
|
||||
label: '一键急停',
|
||||
action: '急停',
|
||||
danger: true,
|
||||
),
|
||||
_LinkageItem(
|
||||
icon: Icons.lightbulb_outline,
|
||||
label: '灯光',
|
||||
action: '开启',
|
||||
secondary: '关闭',
|
||||
),
|
||||
_LinkageItem(
|
||||
icon: Icons.campaign_outlined,
|
||||
label: '鸣笛/语音',
|
||||
action: '鸣笛',
|
||||
secondary: '语音播报',
|
||||
voiceSecondary: true,
|
||||
),
|
||||
];
|
||||
|
||||
/// 通道未接入时的统一提示(状态仍按设计稿切换,便于验收解锁态)
|
||||
void _channelTip(String action) => CapsuleToast.show(
|
||||
'$action指令通道未接入(需遥控控制权与点火位下发),当前状态仅作界面预览',
|
||||
showCheck: false,
|
||||
);
|
||||
|
||||
/// 远程开机:先弹安全确认(离线也先弹,避免点了没反应),确认后再校验下发条件
|
||||
Future<void> _powerOn() async {
|
||||
if (_powered) {
|
||||
CapsuleToast.show('设备已开机', showCheck: false);
|
||||
return;
|
||||
}
|
||||
final ok = await showDeviceConfirmDialog(
|
||||
context,
|
||||
icon: Icons.power_settings_new_rounded,
|
||||
title: '远程开机确认',
|
||||
message: '确认向机器人发送远程开机指令?开机成功后,才可启用割刀、底盘升降、急停等联动操作。',
|
||||
note: '请确认设备周边安全、网络正常。',
|
||||
confirmText: '确认开机',
|
||||
);
|
||||
if (!ok || !mounted) return;
|
||||
|
||||
if (!_online) {
|
||||
CapsuleToast.show('设备离线,开机指令未下发', showCheck: false);
|
||||
return;
|
||||
}
|
||||
if (widget.onPowerOn != null) {
|
||||
widget.onPowerOn!();
|
||||
} else {
|
||||
_channelTip('远程开机');
|
||||
}
|
||||
setState(() => _powered = true);
|
||||
}
|
||||
|
||||
/// 远程关机:同样先弹确认,确认后再校验下发条件
|
||||
Future<void> _powerOff() async {
|
||||
if (!_powered) {
|
||||
CapsuleToast.show('设备当前已关机', showCheck: false);
|
||||
return;
|
||||
}
|
||||
final ok = await showDeviceConfirmDialog(
|
||||
context,
|
||||
icon: Icons.power_settings_new_rounded,
|
||||
title: '远程关机确认',
|
||||
message: '确认向机器人发送远程关机指令?关机后割刀、底盘、灯光、鸣笛等联动功能将立即失效。',
|
||||
note: '请确认设备已停止作业并处于安全位置。',
|
||||
confirmText: '确认关机',
|
||||
danger: true,
|
||||
);
|
||||
if (!ok || !mounted) return;
|
||||
|
||||
if (!_online) {
|
||||
CapsuleToast.show('设备离线,关机指令未下发', showCheck: false);
|
||||
return;
|
||||
}
|
||||
if (widget.onPowerOff != null) {
|
||||
widget.onPowerOff!();
|
||||
} else {
|
||||
_channelTip('远程关机');
|
||||
}
|
||||
setState(() => _powered = false);
|
||||
}
|
||||
|
||||
/// 联动操作统一入口:未开机 → 锁定提示;已开机 → 回调或明确未接入
|
||||
void _linkage(String action) {
|
||||
if (!_powered) {
|
||||
CapsuleToast.show('请先远程开机,开机后方可执行$action', showCheck: false);
|
||||
return;
|
||||
}
|
||||
if (widget.onLinkageAction != null) {
|
||||
widget.onLinkageAction!(action);
|
||||
return;
|
||||
}
|
||||
CapsuleToast.show('$action指令通道未接入', showCheck: false);
|
||||
}
|
||||
|
||||
/// 次操作:语音播报走公共弹窗,其余走联动通道
|
||||
void _secondaryAction(_LinkageItem item) {
|
||||
if (!item.voiceSecondary) {
|
||||
_linkage(item.secondary!);
|
||||
return;
|
||||
}
|
||||
if (!_powered) {
|
||||
CapsuleToast.show('请先远程开机,开机后方可执行语音播报', showCheck: false);
|
||||
return;
|
||||
}
|
||||
_openVoiceBroadcast();
|
||||
}
|
||||
|
||||
/// 一键寻车:复用公共底部弹窗
|
||||
void _openFindRobot() {
|
||||
showFindRobotSheet(context, robot: widget.robot);
|
||||
}
|
||||
|
||||
/// 鸣笛/语音里的「语音播报」:复用公共语音喊话弹窗
|
||||
void _openVoiceBroadcast() {
|
||||
showVoiceBroadcastSheet(context, robot: widget.robot);
|
||||
}
|
||||
|
||||
void _openMoreUnlock() =>
|
||||
CapsuleToast.show('更多解锁功能将随版本逐步开放', showCheck: false);
|
||||
|
||||
void _openPowerHelp() =>
|
||||
CapsuleToast.show('远程开机后才可执行割刀、底盘、急停、灯光、鸣笛等联动操作', showCheck: false);
|
||||
|
||||
void _openSafetyHelp() =>
|
||||
CapsuleToast.show('远程上电与动作控制需设备端安全鉴权,确认周边无人后再操作', showCheck: false);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final tileWidth = (MediaQuery.of(context).size.width - 32 - 20) / 3;
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFEDF6FD),
|
||||
body: Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [Color(0xFFD9EBFA), Color(0xFFEDF6FD)],
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildTopBar(),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 4, 16, 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
RobotSummaryCardV2(robot: widget.robot),
|
||||
const SizedBox(height: 16),
|
||||
_buildSectionTitle(
|
||||
'远程开关机',
|
||||
trailing: GestureDetector(
|
||||
onTap: _openPowerHelp,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: const Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.help_outline_rounded,
|
||||
size: 14,
|
||||
color: _blue,
|
||||
),
|
||||
SizedBox(width: 3),
|
||||
Text(
|
||||
'开关机说明',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: _blue,
|
||||
),
|
||||
),
|
||||
Icon(
|
||||
Icons.chevron_right_rounded,
|
||||
size: 15,
|
||||
color: _blue,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_buildRemotePowerCard(),
|
||||
const SizedBox(height: 16),
|
||||
_buildSectionTitle(
|
||||
'联动操作',
|
||||
trailing: Text(
|
||||
_powered ? '已解锁,可直接操作' : '开机后再操作',
|
||||
style: const TextStyle(fontSize: 11.5, color: _hint),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Wrap(
|
||||
spacing: 10,
|
||||
runSpacing: 10,
|
||||
children: [
|
||||
for (final item in _linkages)
|
||||
SizedBox(
|
||||
width: tileWidth,
|
||||
child: _buildLinkageTile(item),
|
||||
),
|
||||
SizedBox(
|
||||
width: tileWidth,
|
||||
child: _buildFindRobotTile(),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildSectionTitle(
|
||||
'开机后解锁的控制',
|
||||
trailing: const Text(
|
||||
'远程开机成功后自动解锁',
|
||||
style: TextStyle(fontSize: 11.5, color: _hint),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_buildUnlockCard(),
|
||||
const SizedBox(height: 16),
|
||||
_buildSafetyFooter(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 顶栏:返回 + 标题 + 当前开关机状态药丸 =====
|
||||
Widget _buildTopBar() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 6, 16, 2),
|
||||
child: Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => Navigator.of(context).pop(),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _navy.withValues(alpha: 0.06),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.arrow_back_ios_new_rounded,
|
||||
color: _blue,
|
||||
size: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
const Expanded(
|
||||
child: Text(
|
||||
'APP开关机与联动控制',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 9, vertical: 5),
|
||||
decoration: BoxDecoration(
|
||||
color: _powered ? _greenBg : const Color(0xFFFDECEC),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.power_settings_new_rounded,
|
||||
size: 14,
|
||||
color: _powered ? _green : _danger,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
_powered ? '已开机' : '未开机',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: _powered ? _green : _danger,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 分节标题:蓝竖条 + 标题 + 右侧说明 =====
|
||||
Widget _buildSectionTitle(String title, {Widget? trailing}) {
|
||||
return Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 4,
|
||||
height: 15,
|
||||
decoration: BoxDecoration(
|
||||
color: _blue,
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
),
|
||||
?trailing,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 远程开关机卡:状态环 + 当前状态 + 两个动作按钮 =====
|
||||
Widget _buildRemotePowerCard() {
|
||||
final accent = _powered ? _green : _danger;
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(12, 14, 12, 14),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 状态环
|
||||
Container(
|
||||
width: 74,
|
||||
height: 74,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: const Color(0xFFF3F6FA),
|
||||
border: Border.all(
|
||||
color: accent.withValues(alpha: 0.22),
|
||||
width: 5,
|
||||
),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.power_settings_new_rounded,
|
||||
size: 32,
|
||||
color: accent,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'当前状态',
|
||||
style: TextStyle(fontSize: 12, color: _gray),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
_powered ? '已开机' : '已关机',
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
_powered
|
||||
? '联动操作已解锁,可执行割刀、底盘、灯光、鸣笛等操作。'
|
||||
: '远程开机后,方可执行割刀、底盘、急停、灯光、鸣笛等联动操作。',
|
||||
style: const TextStyle(
|
||||
fontSize: 11,
|
||||
height: 1.5,
|
||||
color: _gray,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
SizedBox(
|
||||
width: 104,
|
||||
child: Column(
|
||||
children: [
|
||||
_buildPowerButton(label: '远程开机', filled: true, onTap: _powerOn),
|
||||
const SizedBox(height: 8),
|
||||
_buildPowerButton(
|
||||
label: '远程关机',
|
||||
filled: false,
|
||||
onTap: _powerOff,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPowerButton({
|
||||
required String label,
|
||||
required bool filled,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
height: 42,
|
||||
decoration: BoxDecoration(
|
||||
color: filled ? _blue : Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: filled ? null : Border.all(color: const Color(0xFFA9D1F6)),
|
||||
boxShadow: filled
|
||||
? [
|
||||
BoxShadow(
|
||||
color: _blue.withValues(alpha: 0.24),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
]
|
||||
: null,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.power_settings_new_rounded,
|
||||
size: 15,
|
||||
color: filled ? Colors.white : _blue,
|
||||
),
|
||||
const SizedBox(width: 5),
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 12.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: filled ? Colors.white : _blue,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 联动磁贴:图标 + 名称 + 锁提示 + 分段按钮 =====
|
||||
Widget _buildLinkageTile(_LinkageItem item) {
|
||||
final locked = !_powered;
|
||||
final accent = locked ? _hint : (item.danger ? _danger : _blue);
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(9, 12, 9, 10),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
width: 34,
|
||||
height: 34,
|
||||
decoration: BoxDecoration(
|
||||
color: locked ? _lockedBg : _softBlue,
|
||||
borderRadius: BorderRadius.circular(11),
|
||||
),
|
||||
child: Icon(
|
||||
item.icon,
|
||||
size: 18,
|
||||
color: locked ? _lockedText : (item.danger ? _danger : _blue),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
item.label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 12.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: locked ? _gray : _navy,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
if (locked) ...[
|
||||
const Icon(Icons.lock_outline, size: 10, color: _hint),
|
||||
const SizedBox(width: 2),
|
||||
],
|
||||
Text(
|
||||
locked ? '设备未开机' : '可操作',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 9.5, color: _hint),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 9),
|
||||
_buildSegBar(
|
||||
item: item,
|
||||
locked: locked,
|
||||
accent: accent,
|
||||
onPrimary: () => _linkage(item.action),
|
||||
onSecondary: item.secondary == null
|
||||
? null
|
||||
: () => _secondaryAction(item),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSegBar({
|
||||
required _LinkageItem item,
|
||||
required bool locked,
|
||||
required Color accent,
|
||||
required VoidCallback onPrimary,
|
||||
VoidCallback? onSecondary,
|
||||
}) {
|
||||
final textColor = locked ? _lockedText : accent;
|
||||
return Container(
|
||||
height: 28,
|
||||
decoration: BoxDecoration(
|
||||
color: locked ? _lockedBg : _segBg,
|
||||
borderRadius: BorderRadius.circular(9),
|
||||
border: Border.all(color: locked ? _lockedBg : _segBorder),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: onPrimary,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Center(
|
||||
child: Text(
|
||||
item.action,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 10.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: textColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (onSecondary != null)
|
||||
Container(
|
||||
width: 1,
|
||||
height: 12,
|
||||
color: locked ? const Color(0xFFE3E8EF) : _segBorder,
|
||||
),
|
||||
if (onSecondary != null)
|
||||
Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: onSecondary,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Center(
|
||||
child: Text(
|
||||
item.secondary!,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 10.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: locked ? _lockedText : _blue,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 一键寻车磁贴:与联动磁贴同规格,但走公共弹窗 =====
|
||||
Widget _buildFindRobotTile() {
|
||||
final locked = !_powered;
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(9, 12, 9, 10),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
width: 34,
|
||||
height: 34,
|
||||
decoration: BoxDecoration(
|
||||
color: locked ? _lockedBg : _softBlue,
|
||||
borderRadius: BorderRadius.circular(11),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.location_on_outlined,
|
||||
size: 18,
|
||||
color: locked ? _lockedText : _blue,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'一键寻车',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 12.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: locked ? _gray : _navy,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
if (locked) ...[
|
||||
const Icon(Icons.lock_outline, size: 10, color: _hint),
|
||||
const SizedBox(width: 2),
|
||||
],
|
||||
Text(
|
||||
locked ? '声光需开机' : '可操作',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 9.5, color: _hint),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 9),
|
||||
GestureDetector(
|
||||
onTap: _openFindRobot,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
height: 28,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: _segBg,
|
||||
borderRadius: BorderRadius.circular(9),
|
||||
border: Border.all(color: _segBorder),
|
||||
),
|
||||
child: const Text(
|
||||
'开始寻车',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 10.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: _blue,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 开机后解锁的控制:开关机 → 联动功能链 =====
|
||||
Widget _buildUnlockCard() {
|
||||
const items = <(IconData, String)>[
|
||||
(Icons.content_cut, '割刀启停'),
|
||||
(Icons.unfold_more_rounded, '底盘升降'),
|
||||
(Icons.lightbulb_outline, '灯光'),
|
||||
(Icons.campaign_outlined, '鸣笛/语音'),
|
||||
];
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(12, 12, 12, 12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
// 起点:远程开机当前状态
|
||||
Column(
|
||||
children: [
|
||||
Container(
|
||||
width: 34,
|
||||
height: 34,
|
||||
decoration: BoxDecoration(
|
||||
color: _powered ? _greenBg : _lockedBg,
|
||||
borderRadius: BorderRadius.circular(11),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.power_settings_new_rounded,
|
||||
size: 18,
|
||||
color: _powered ? _green : _hint,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
'远程开机',
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: _powered ? _navy : _gray,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
_powered ? '已开机' : '当前状态',
|
||||
style: const TextStyle(fontSize: 8.5, color: _hint),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
const Icon(
|
||||
Icons.keyboard_double_arrow_right_rounded,
|
||||
size: 16,
|
||||
color: _hint,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
// 解锁项
|
||||
Expanded(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
for (final item in items)
|
||||
Column(
|
||||
children: [
|
||||
Container(
|
||||
width: 30,
|
||||
height: 30,
|
||||
decoration: BoxDecoration(
|
||||
color: _powered ? _softBlue : _lockedBg,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Icon(
|
||||
item.$1,
|
||||
size: 16,
|
||||
color: _powered ? _blue : _lockedText,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Text(
|
||||
item.$2,
|
||||
style: TextStyle(
|
||||
fontSize: 9,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: _powered ? _navy : _hint,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: _openMoreUnlock,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: const Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 30,
|
||||
height: 30,
|
||||
child: Icon(
|
||||
Icons.more_horiz_rounded,
|
||||
size: 16,
|
||||
color: _hint,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
Text('更多', style: TextStyle(fontSize: 9, color: _hint)),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 页脚:安全鉴权提示 =====
|
||||
Widget _buildSafetyFooter() {
|
||||
return GestureDetector(
|
||||
onTap: _openSafetyHelp,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.fromLTRB(12, 12, 10, 12),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFEAF4FE),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: const Color(0xFFD6E9FC)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.verified_user_rounded, size: 16, color: _blue),
|
||||
const SizedBox(width: 8),
|
||||
const Expanded(
|
||||
child: Text(
|
||||
'涉及远程上电与动作控制,需通过安全鉴权,确保设备与人员安全。',
|
||||
style: TextStyle(
|
||||
fontSize: 11.5,
|
||||
height: 1.5,
|
||||
color: Color(0xFF5C6B84),
|
||||
),
|
||||
),
|
||||
),
|
||||
const Icon(Icons.chevron_right_rounded, size: 18, color: _hint),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,868 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
|
||||
import '../../data/models/robot_data_model.dart';
|
||||
import '../widgets/robot_summary_card_v2.dart';
|
||||
import 'robot_sensor_page_v2.dart';
|
||||
|
||||
/// 一条故障码说明(诊断支持 → 故障码说明)
|
||||
class _FaultCode {
|
||||
final String code;
|
||||
final String name;
|
||||
final IconData icon;
|
||||
final String desc;
|
||||
final String impact;
|
||||
final String advice;
|
||||
|
||||
const _FaultCode({
|
||||
required this.code,
|
||||
required this.name,
|
||||
required this.icon,
|
||||
required this.desc,
|
||||
required this.impact,
|
||||
required this.advice,
|
||||
});
|
||||
}
|
||||
|
||||
/// 一条故障事件(已恢复 / 当前)
|
||||
class _FaultEvent {
|
||||
final String code;
|
||||
final String name;
|
||||
final String time;
|
||||
final IconData icon;
|
||||
|
||||
const _FaultEvent({
|
||||
required this.code,
|
||||
required this.name,
|
||||
required this.time,
|
||||
required this.icon,
|
||||
});
|
||||
}
|
||||
|
||||
/// 故障诊断中心(设计稿:全部功能中心 → 故障诊断)
|
||||
///
|
||||
/// 二级 push 页面,无底部导航。
|
||||
/// - 当前故障:设计稿明确要求「离线或遥测过期时不得显示无故障」,
|
||||
/// 所以这里只用设备在线状态判定:在线 → 无未恢复故障;离线 → 状态未知,不判健康;
|
||||
/// - 已恢复事件 / 故障码说明:后端暂无故障接口(`RunningStatusEntity` 只有一个避障标志位,
|
||||
/// 没有故障码字段),先用本地示例与静态码表渲染,并在页脚注明;
|
||||
/// - 传感器与通信实时状态:直接复用已实现的「传感器与通信详情」页。
|
||||
class RobotFaultCenterPageV2 extends StatefulWidget {
|
||||
final RobotDataModel robot;
|
||||
|
||||
const RobotFaultCenterPageV2({super.key, required this.robot});
|
||||
|
||||
@override
|
||||
State<RobotFaultCenterPageV2> createState() => _RobotFaultCenterPageV2State();
|
||||
}
|
||||
|
||||
class _RobotFaultCenterPageV2State extends State<RobotFaultCenterPageV2> {
|
||||
static const Color _navy = Color(0xFF1A2B4A);
|
||||
static const Color _gray = Color(0xFF86909C);
|
||||
static const Color _hint = Color(0xFFA8B3C5);
|
||||
static const Color _blue = Color(0xFF1C96F6);
|
||||
static const Color _cardBorder = Color(0xFFE5EDF7);
|
||||
static const Color _divider = Color(0xFFF0F4FA);
|
||||
static const Color _green = Color(0xFF2FBF6B);
|
||||
static const Color _greenBg = Color(0xFFE5F8EC);
|
||||
static const Color _softBlue = Color(0xFFEAF3FE);
|
||||
static const Color _softGray = Color(0xFFF4F6F9);
|
||||
static const Color _trackBg = Color(0xFFDCEBFA);
|
||||
|
||||
/// 故障码静态码表(设计稿出现过的两个码 + 通用排查口径)
|
||||
static const List<_FaultCode> _faultCodes = [
|
||||
_FaultCode(
|
||||
code: 'C201',
|
||||
name: '4G信号短时中断',
|
||||
icon: Icons.wifi_off_rounded,
|
||||
desc: '设备与云端之间的 4G 链路在短时间内断开,重连成功后自动恢复。',
|
||||
impact: '影响:远程指令下发与状态上报延迟,作业本身不受影响。',
|
||||
advice: '排查:确认作业区域 4G 覆盖;检查天线连接;频繁出现时更换运营商卡。',
|
||||
),
|
||||
_FaultCode(
|
||||
code: 'U108',
|
||||
name: '超声波短时通信异常',
|
||||
icon: Icons.settings_input_antenna_rounded,
|
||||
desc: '超声波探头的串口通信出现短暂丢包,链路恢复后自动解除。',
|
||||
impact: '影响:避障距离刷新滞后,期间低速作业仍可继续。',
|
||||
advice: '排查:检查探头线束与接插件是否松动;清洁探头表面;必要时更换探头。',
|
||||
),
|
||||
];
|
||||
|
||||
/// 最近已恢复事件(示例数据:后端暂无故障记录接口)
|
||||
static const List<_FaultEvent> _recoveredEvents = [
|
||||
_FaultEvent(
|
||||
code: 'C201',
|
||||
name: '4G信号短时中断',
|
||||
time: '10月19日 18:23',
|
||||
icon: Icons.wifi_off_rounded,
|
||||
),
|
||||
_FaultEvent(
|
||||
code: 'U108',
|
||||
name: '超声波短时通信异常',
|
||||
time: '10月17日 15:42',
|
||||
icon: Icons.settings_input_antenna_rounded,
|
||||
),
|
||||
];
|
||||
|
||||
/// 0 当前 / 1 已恢复 / 2 全部记录
|
||||
int _filter = 0;
|
||||
|
||||
late final String _checkedAt;
|
||||
|
||||
bool get _online => widget.robot.isOnline;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_checkedAt = _formatNow();
|
||||
}
|
||||
|
||||
String _formatNow() {
|
||||
final now = DateTime.now();
|
||||
String two(int v) => v.toString().padLeft(2, '0');
|
||||
return '${two(now.hour)}:${two(now.minute)}:${two(now.second)}';
|
||||
}
|
||||
|
||||
void _todo() => CapsuleToast.show('功能暂未开发', showCheck: false);
|
||||
|
||||
void _openSensorPage() {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => RobotSensorPageV2(robot: widget.robot)),
|
||||
);
|
||||
}
|
||||
|
||||
/// 已恢复事件 / 故障码说明共用的弹窗
|
||||
void _showFaultDetail(_FaultCode code, {String? recoveredAt}) {
|
||||
showModalBottomSheet<void>(
|
||||
context: context,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (sheetCtx) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.all(12),
|
||||
padding: const EdgeInsets.fromLTRB(18, 16, 18, 20),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(18),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: _softBlue,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Icon(code.icon, size: 21, color: _blue),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'${code.code} · ${code.name}',
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
if (recoveredAt != null) ...[
|
||||
const SizedBox(height: 3),
|
||||
Text(
|
||||
'$recoveredAt · 已恢复',
|
||||
style: const TextStyle(fontSize: 12, color: _gray),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
if (recoveredAt != null)
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 9,
|
||||
vertical: 3,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: _greenBg,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: const Text(
|
||||
'已恢复',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: _green,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
_buildSheetLine('问题说明', code.desc),
|
||||
const SizedBox(height: 10),
|
||||
_buildSheetLine('影响与建议', '${code.impact}\n${code.advice}'),
|
||||
const SizedBox(height: 14),
|
||||
GestureDetector(
|
||||
onTap: () => Navigator.of(sheetCtx).pop(),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
height: 44,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: _softBlue,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: const Text(
|
||||
'知道了',
|
||||
style: TextStyle(
|
||||
fontSize: 14.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: _blue,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSheetLine(String label, String text) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
text,
|
||||
style: const TextStyle(fontSize: 13, height: 1.55, color: _gray),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void _openFaultCodeList() {
|
||||
showModalBottomSheet<void>(
|
||||
context: context,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (sheetCtx) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.all(12),
|
||||
padding: const EdgeInsets.fromLTRB(16, 16, 16, 16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(18),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'故障码说明',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
const Text(
|
||||
'点击任意故障码查看问题说明、影响与排查建议',
|
||||
style: TextStyle(fontSize: 11.5, color: _hint),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
for (var i = 0; i < _faultCodes.length; i++)
|
||||
Column(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.of(sheetCtx).pop();
|
||||
_showFaultDetail(_faultCodes[i]);
|
||||
},
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: _softBlue,
|
||||
borderRadius: BorderRadius.circular(11),
|
||||
),
|
||||
child: Icon(
|
||||
_faultCodes[i].icon,
|
||||
size: 19,
|
||||
color: _blue,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 11),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'${_faultCodes[i].code} · ${_faultCodes[i].name}',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 13.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
Text(
|
||||
_faultCodes[i].desc,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 11.5,
|
||||
color: _gray,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Icon(
|
||||
Icons.chevron_right_rounded,
|
||||
size: 18,
|
||||
color: _hint,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (i != _faultCodes.length - 1)
|
||||
const Divider(height: 1, color: _divider),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFEDF6FD),
|
||||
body: Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [Color(0xFFD9EBFA), Color(0xFFEDF6FD)],
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildTopBar(context),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 4, 16, 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
RobotSummaryCardV2(robot: widget.robot),
|
||||
const SizedBox(height: 18),
|
||||
_buildSectionTitle('当前故障与预警'),
|
||||
const SizedBox(height: 10),
|
||||
_buildCurrentFaultCard(),
|
||||
const SizedBox(height: 18),
|
||||
_buildSectionTitle('故障筛选'),
|
||||
const SizedBox(height: 10),
|
||||
_buildFilterBar(),
|
||||
const SizedBox(height: 18),
|
||||
_buildSectionTitle(_listTitle),
|
||||
const SizedBox(height: 10),
|
||||
_buildEventList(),
|
||||
const SizedBox(height: 18),
|
||||
_buildSectionTitle('诊断支持'),
|
||||
const SizedBox(height: 10),
|
||||
_buildSupportCard(),
|
||||
const SizedBox(height: 14),
|
||||
_buildOfflineRuleNote(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 顶栏 =====
|
||||
Widget _buildTopBar(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 6, 16, 2),
|
||||
child: Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => Navigator.of(context).pop(),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _navy.withValues(alpha: 0.06),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.arrow_back_ios_new_rounded,
|
||||
color: _blue,
|
||||
size: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Expanded(
|
||||
child: Text(
|
||||
'故障诊断中心',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: _todo,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _navy.withValues(alpha: 0.06),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.info_outline_rounded,
|
||||
color: _blue,
|
||||
size: 18,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 分节标题 =====
|
||||
Widget _buildSectionTitle(String title) {
|
||||
return Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 4,
|
||||
height: 15,
|
||||
decoration: BoxDecoration(
|
||||
color: _blue,
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 当前故障卡 =====
|
||||
Widget _buildCurrentFaultCard() {
|
||||
// 设计稿规则:离线或遥测过期时不得显示「无故障」,只能标注状态未知
|
||||
final title = _online ? '当前无未恢复故障' : '当前故障状态未知';
|
||||
final subtitle = _online
|
||||
? '最新有效上报 · $_checkedAt'
|
||||
: '设备离线,遥测已中断 · 检查于 $_checkedAt';
|
||||
final pillText = _online ? '正常' : '未知';
|
||||
final pillColor = _online ? _green : _gray;
|
||||
final pillBg = _online ? _greenBg : _softGray;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(14, 16, 14, 16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
_online ? Icons.verified_user_outlined : Icons.help_outline_rounded,
|
||||
size: 40,
|
||||
color: _navy,
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Text(
|
||||
subtitle,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 12, color: _gray),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: pillBg,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Text(
|
||||
pillText,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: pillColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 故障筛选 =====
|
||||
Widget _buildFilterBar() {
|
||||
final labels = ['当前(0)', '已恢复(${_recoveredEvents.length})', '全部记录'];
|
||||
return Container(
|
||||
height: 46,
|
||||
padding: const EdgeInsets.all(4),
|
||||
decoration: BoxDecoration(
|
||||
color: _trackBg,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
child: Row(
|
||||
children: List.generate(labels.length, (index) {
|
||||
final selected = _filter == index;
|
||||
return Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () => setState(() => _filter = index),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 180),
|
||||
curve: Curves.easeOutCubic,
|
||||
decoration: BoxDecoration(
|
||||
color: selected ? Colors.white : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(11),
|
||||
boxShadow: selected
|
||||
? [
|
||||
BoxShadow(
|
||||
color: _navy.withValues(alpha: 0.08),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
]
|
||||
: null,
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
labels[index],
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: selected ? FontWeight.w700 : FontWeight.w500,
|
||||
color: selected ? _blue : _gray,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String get _listTitle {
|
||||
switch (_filter) {
|
||||
case 1:
|
||||
return '已恢复事件';
|
||||
case 2:
|
||||
return '全部记录';
|
||||
case 0:
|
||||
default:
|
||||
return '最近已恢复事件';
|
||||
}
|
||||
}
|
||||
|
||||
/// 当前筛选下要展示的事件;「当前」筛选下只作参考展示最近已恢复事件(与设计稿一致)
|
||||
bool get _showEmptyCurrent => _filter == 0 && !_online;
|
||||
|
||||
Widget _buildEventList() {
|
||||
final events = _showEmptyCurrent ? const <_FaultEvent>[] : _recoveredEvents;
|
||||
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: events.isEmpty
|
||||
? Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 30),
|
||||
child: Center(
|
||||
child: Text(
|
||||
_showEmptyCurrent ? '设备离线,暂无可用记录' : '暂无记录',
|
||||
style: const TextStyle(fontSize: 13, color: _gray),
|
||||
),
|
||||
),
|
||||
)
|
||||
: Column(
|
||||
children: [
|
||||
for (var i = 0; i < events.length; i++)
|
||||
Column(
|
||||
children: [
|
||||
_buildEventRow(events[i]),
|
||||
if (i != events.length - 1)
|
||||
const Divider(
|
||||
height: 1,
|
||||
thickness: 1,
|
||||
color: _divider,
|
||||
indent: 12,
|
||||
endIndent: 12,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEventRow(_FaultEvent event) {
|
||||
final code = _faultCodes.firstWhere(
|
||||
(e) => e.code == event.code,
|
||||
orElse: () => _faultCodes.first,
|
||||
);
|
||||
return GestureDetector(
|
||||
onTap: () => _showFaultDetail(code, recoveredAt: event.time),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(12, 12, 10, 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: _softBlue,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Icon(event.icon, size: 21, color: _blue),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'${event.code} · ${event.name}',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 14.5,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'${event.time} · 已恢复',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 12, color: _gray),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 9, vertical: 3),
|
||||
decoration: BoxDecoration(
|
||||
color: _greenBg,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: const Text(
|
||||
'已恢复',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: _green,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 2),
|
||||
const Icon(Icons.chevron_right_rounded, size: 18, color: _hint),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 诊断支持 =====
|
||||
Widget _buildSupportCard() {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildSupportRow(
|
||||
icon: Icons.description_outlined,
|
||||
title: '查看故障码说明',
|
||||
subtitle: '问题说明、影响和排查建议',
|
||||
onTap: _openFaultCodeList,
|
||||
),
|
||||
const Divider(
|
||||
height: 1,
|
||||
thickness: 1,
|
||||
color: _divider,
|
||||
indent: 12,
|
||||
endIndent: 12,
|
||||
),
|
||||
_buildSupportRow(
|
||||
icon: Icons.show_chart_rounded,
|
||||
title: '传感器与通信实时状态',
|
||||
subtitle: '确认当前链路和硬件反馈',
|
||||
onTap: _openSensorPage,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSupportRow({
|
||||
required IconData icon,
|
||||
required String title,
|
||||
required String subtitle,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(12, 13, 10, 13),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: _softBlue,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Icon(icon, size: 21, color: _blue),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 14.5,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
subtitle,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 12, color: _gray),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const Icon(Icons.chevron_right_rounded, size: 18, color: _hint),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 底部规则提示(设计稿原有说明条)=====
|
||||
Widget _buildOfflineRuleNote() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(12, 10, 12, 10),
|
||||
decoration: BoxDecoration(
|
||||
color: _softBlue,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: const Color(0xFFD6E9FC)),
|
||||
),
|
||||
child: const Text(
|
||||
'离线或遥测过期时不得显示「无故障」,应标注「当前故障状态未知」。'
|
||||
'已恢复事件为示例数据,接入故障记录接口后自动替换。',
|
||||
style: TextStyle(fontSize: 11.5, height: 1.5, color: _hint),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,561 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
|
||||
import '../../data/models/robot_data_model.dart';
|
||||
import '../widgets/robot_summary_card_v2.dart';
|
||||
|
||||
/// 一条历史升级记录
|
||||
class _UpgradeRecord {
|
||||
final String module;
|
||||
final String time;
|
||||
final String result;
|
||||
|
||||
const _UpgradeRecord({
|
||||
required this.module,
|
||||
required this.time,
|
||||
required this.result,
|
||||
});
|
||||
}
|
||||
|
||||
/// 软件与固件升级(设计稿:设备详情 → 设置 → 固件与OTA升级)
|
||||
///
|
||||
/// 二级 push 页面,无底部导航。
|
||||
///
|
||||
/// 后端目前没有固件版本查询与 OTA 下发接口,因此:
|
||||
/// - 版本号、历史记录按设计稿展示为示例口径,页脚明确注明;
|
||||
/// - 「检查可用更新」只做安全前置提示,不返回假的「有新版本」;
|
||||
/// - 升级动作(如有)必须先过 [showDeviceConfirmDialog] 二次确认。
|
||||
class RobotFirmwarePageV2 extends StatefulWidget {
|
||||
final RobotDataModel robot;
|
||||
|
||||
const RobotFirmwarePageV2({super.key, required this.robot});
|
||||
|
||||
@override
|
||||
State<RobotFirmwarePageV2> createState() => _RobotFirmwarePageV2State();
|
||||
}
|
||||
|
||||
class _RobotFirmwarePageV2State extends State<RobotFirmwarePageV2> {
|
||||
static const Color _navy = Color(0xFF1A2B4A);
|
||||
static const Color _gray = Color(0xFF86909C);
|
||||
static const Color _hint = Color(0xFFA8B3C5);
|
||||
static const Color _blue = Color(0xFF1C96F6);
|
||||
static const Color _cardBorder = Color(0xFFE5EDF7);
|
||||
static const Color _softBlue = Color(0xFFEAF3FE);
|
||||
static const Color _divider = Color(0xFFF0F4FA);
|
||||
static const Color _green = Color(0xFF2FBF6B);
|
||||
static const Color _greenBg = Color(0xFFE5F8EC);
|
||||
static const Color _trackBg = Color(0xFFF1F3F6);
|
||||
|
||||
/// 检查状态:待检查 / 检查中 / 已是最新(示例态,无真实 OTA 服务)
|
||||
String _checkState = '待检查';
|
||||
|
||||
static const List<_UpgradeRecord> _records = [
|
||||
_UpgradeRecord(
|
||||
module: 'MCU v1.0.3',
|
||||
time: '2026-10-18 10:36',
|
||||
result: '成功',
|
||||
),
|
||||
_UpgradeRecord(
|
||||
module: '通信模块 v1.1.2',
|
||||
time: '2026-09-26 15:12',
|
||||
result: '成功',
|
||||
),
|
||||
_UpgradeRecord(
|
||||
module: '图传模块 v1.0.8',
|
||||
time: '2026-08-30 09:05',
|
||||
result: '成功',
|
||||
),
|
||||
];
|
||||
|
||||
bool get _online => widget.robot.isOnline;
|
||||
|
||||
/// 检查更新:先做前置条件校验,再明确告知 OTA 通道未接入
|
||||
Future<void> _checkUpdate() async {
|
||||
if (!_online) {
|
||||
CapsuleToast.show('设备离线,无法检查更新', showCheck: false);
|
||||
return;
|
||||
}
|
||||
if (_checkState == '检查中…') return;
|
||||
setState(() => _checkState = '检查中…');
|
||||
await Future<void>.delayed(const Duration(milliseconds: 600));
|
||||
if (!mounted) return;
|
||||
setState(() => _checkState = '待检查');
|
||||
CapsuleToast.show('OTA 升级服务未接入,暂不返回版本检查结果', showCheck: false);
|
||||
}
|
||||
|
||||
void _openRecord(_UpgradeRecord record) =>
|
||||
CapsuleToast.show('${record.module} 升级详情暂未开放', showCheck: false);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFEDF6FD),
|
||||
body: Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [Color(0xFFD9EBFA), Color(0xFFEDF6FD)],
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildTopBar(),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 4, 16, 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
RobotSummaryCardV2(robot: widget.robot),
|
||||
const SizedBox(height: 18),
|
||||
_buildSectionTitle('当前版本'),
|
||||
const SizedBox(height: 10),
|
||||
_buildVersionCard(),
|
||||
const SizedBox(height: 18),
|
||||
_buildSectionTitle('升级检查'),
|
||||
const SizedBox(height: 10),
|
||||
_buildCheckCard(),
|
||||
const SizedBox(height: 18),
|
||||
_buildSectionTitle('升级前必须确认'),
|
||||
const SizedBox(height: 10),
|
||||
_buildPrerequisiteCard(),
|
||||
const SizedBox(height: 18),
|
||||
_buildSectionTitle('历史升级记录'),
|
||||
const SizedBox(height: 10),
|
||||
_buildHistoryCard(),
|
||||
const SizedBox(height: 14),
|
||||
_buildFooterNote(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 顶栏:返回 + 标题 + 信息按钮 =====
|
||||
Widget _buildTopBar() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 6, 16, 2),
|
||||
child: Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => Navigator.of(context).pop(),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _navy.withValues(alpha: 0.06),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.arrow_back_ios_new_rounded,
|
||||
color: _blue,
|
||||
size: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Expanded(
|
||||
child: Text(
|
||||
'软件与固件升级',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
GestureDetector(
|
||||
onTap: () =>
|
||||
CapsuleToast.show('升级需设备在线、供电稳定且处于安全停机状态', showCheck: false),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _navy.withValues(alpha: 0.06),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.info_outline_rounded,
|
||||
color: _blue,
|
||||
size: 18,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSectionTitle(String title) {
|
||||
return Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 4,
|
||||
height: 15,
|
||||
decoration: BoxDecoration(
|
||||
color: _blue,
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 当前版本:四行只读 KV =====
|
||||
Widget _buildVersionCard() {
|
||||
const rows = <(String, String)>[
|
||||
('下位机 MCU', 'v1.0.3'),
|
||||
('通信模块', 'v1.1.2'),
|
||||
('图传模块', 'v1.0.8'),
|
||||
('设备配置版本', 'CFG-20261018'),
|
||||
];
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
for (int i = 0; i < rows.length; i++) ...[
|
||||
if (i > 0)
|
||||
const Divider(height: 1, thickness: 0.6, color: _divider),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
rows[i].$1,
|
||||
style: const TextStyle(fontSize: 13, color: _hint),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
rows[i].$2,
|
||||
textAlign: TextAlign.right,
|
||||
style: const TextStyle(
|
||||
fontSize: 13.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 升级检查:标题行 + 状态药丸 + 通栏按钮 =====
|
||||
Widget _buildCheckCard() {
|
||||
final checking = _checkState == '检查中…';
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(14, 14, 14, 14),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 42,
|
||||
height: 42,
|
||||
decoration: BoxDecoration(
|
||||
color: _softBlue,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.system_update_alt_rounded,
|
||||
size: 22,
|
||||
color: _blue,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'系统更新检查',
|
||||
style: TextStyle(
|
||||
fontSize: 14.5,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 3),
|
||||
Text(
|
||||
'需确认设备在线、供电稳定且安全停机',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(fontSize: 11.5, color: _gray),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: _trackBg,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Text(
|
||||
_checkState,
|
||||
style: const TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: _gray,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
GestureDetector(
|
||||
onTap: _checkUpdate,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
height: 46,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: _blue,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _blue.withValues(alpha: 0.26),
|
||||
blurRadius: 14,
|
||||
offset: const Offset(0, 5),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Text(
|
||||
checking ? '检查中…' : '检查可用更新',
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 升级前必须确认:勾选清单 =====
|
||||
Widget _buildPrerequisiteCard() {
|
||||
const items = <String>[
|
||||
'机器人处于安全停机/待机状态',
|
||||
'割刀与底盘执行机构已停止',
|
||||
'电源充足且通信稳定',
|
||||
'当前账号具有升级权限',
|
||||
];
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(14, 6, 14, 6),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
for (final text in items)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 11),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.check_rounded, size: 16, color: _blue),
|
||||
const SizedBox(width: 9),
|
||||
Expanded(
|
||||
child: Text(
|
||||
text,
|
||||
style: const TextStyle(fontSize: 13, color: _navy),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 历史升级记录 =====
|
||||
Widget _buildHistoryCard() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
for (int i = 0; i < _records.length; i++) ...[
|
||||
if (i > 0)
|
||||
const Divider(
|
||||
height: 1,
|
||||
thickness: 0.6,
|
||||
color: _divider,
|
||||
indent: 46,
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () => _openRecord(_records[i]),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: _softBlue,
|
||||
borderRadius: BorderRadius.circular(11),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.check_rounded,
|
||||
size: 19,
|
||||
color: _blue,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
_records[i].module,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
Text(
|
||||
'${_records[i].time} · ${_records[i].result}',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 11.5,
|
||||
color: _gray,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 9,
|
||||
vertical: 3,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: _greenBg,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: const Text(
|
||||
'已完成',
|
||||
style: TextStyle(
|
||||
fontSize: 10.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: _green,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
const Icon(
|
||||
Icons.chevron_right_rounded,
|
||||
size: 20,
|
||||
color: Color(0xFFC9CDD4),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFooterNote() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: _softBlue,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Icon(Icons.info_outline_rounded, size: 15, color: _blue),
|
||||
const SizedBox(width: 7),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'版本号与历史记录为示例口径;设备端版本接口与 OTA 通道接入后自动替换为真实数据,'
|
||||
'升级动作会先做二次确认再下发。',
|
||||
style: TextStyle(
|
||||
fontSize: 11.5,
|
||||
height: 1.55,
|
||||
color: const Color(0xFF5C6B84),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,420 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
|
||||
import '../../data/models/robot_data_model.dart';
|
||||
import '../widgets/robot_summary_card_v2.dart';
|
||||
|
||||
/// 机器人完整信息(设计稿:全部功能中心 → 机器人信息)
|
||||
///
|
||||
/// 二级 push 页面,无底部导航。数据全部取自传入的 [RobotDataModel]
|
||||
/// (设备列表接口已有字段);
|
||||
/// 后端未返回的字段用设计稿示例值占位并在页脚注明,避免看起来像真实数据。
|
||||
class RobotFullInfoPageV2 extends StatelessWidget {
|
||||
final RobotDataModel robot;
|
||||
|
||||
const RobotFullInfoPageV2({super.key, required this.robot});
|
||||
|
||||
// ===== 色板(与全部功能中心一致)=====
|
||||
static const Color _navy = Color(0xFF1A2B4A);
|
||||
static const Color _gray = Color(0xFF86909C);
|
||||
static const Color _hint = Color(0xFFA8B3C5);
|
||||
static const Color _blue = Color(0xFF1C96F6);
|
||||
static const Color _cardBorder = Color(0xFFE5EDF7);
|
||||
static const Color _green = Color(0xFF2FBF6B);
|
||||
static const Color _greenBg = Color(0xFFE5F8EC);
|
||||
static const Color _statBg = Color(0xFFEAF3FE);
|
||||
static const Color _divider = Color(0xFFF0F4FA);
|
||||
|
||||
static const String _robotImage = 'assets/images/robot_logo_login.png';
|
||||
|
||||
bool get _online => robot.isOnline;
|
||||
|
||||
String get _displayName {
|
||||
final alias = robot.alias;
|
||||
return (alias != null && alias.isNotEmpty) ? alias : robot.name;
|
||||
}
|
||||
|
||||
/// 型号:接口 type 为空时按设计稿兜底
|
||||
String get _model {
|
||||
final type = robot.type.trim();
|
||||
return type.isEmpty ? 'MC700' : type;
|
||||
}
|
||||
|
||||
/// SN 脱敏:保留前 4 位与后 2 位
|
||||
String get _maskedSn {
|
||||
final sn = robot.id;
|
||||
if (sn.isEmpty) return '--';
|
||||
if (sn.length <= 6) return sn;
|
||||
return '${sn.substring(0, 4)} · · · · ${sn.substring(sn.length - 2)}(脱敏)';
|
||||
}
|
||||
|
||||
/// 电量:0 视为未上报
|
||||
String get _batteryText {
|
||||
final b = robot.battery;
|
||||
if (b <= 0) return '--';
|
||||
return '${b.round()}%';
|
||||
}
|
||||
|
||||
/// 运行模式:任务字段为“无/空”时按待机展示
|
||||
String get _modeText {
|
||||
final task = robot.task.trim();
|
||||
if (task.isEmpty || task == '无' || task == 'null') return '待机';
|
||||
return task;
|
||||
}
|
||||
|
||||
void _todo() => CapsuleToast.show('功能暂未开发', showCheck: false);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFEDF6FD),
|
||||
body: Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [Color(0xFFD9EBFA), Color(0xFFEDF6FD)],
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildTopBar(context),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 4, 16, 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
RobotSummaryCardV2(robot: robot),
|
||||
const SizedBox(height: 18),
|
||||
_buildSectionTitle('机器人基础资料'),
|
||||
const SizedBox(height: 10),
|
||||
_buildProfileCard(),
|
||||
const SizedBox(height: 18),
|
||||
_buildSectionTitle('运行与控制信息'),
|
||||
const SizedBox(height: 10),
|
||||
_buildRuntimeCard(),
|
||||
const SizedBox(height: 14),
|
||||
const Center(
|
||||
child: Text(
|
||||
'动力类型、最近上报、控制会话、故障数为示例;接入后自动替换',
|
||||
style: TextStyle(fontSize: 10.5, color: _hint),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 顶栏:返回 + 标题 + 说明按钮 =====
|
||||
Widget _buildTopBar(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 6, 16, 2),
|
||||
child: Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => Navigator.of(context).pop(),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _navy.withValues(alpha: 0.06),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.arrow_back_ios_new_rounded,
|
||||
color: _blue,
|
||||
size: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Text(
|
||||
'机器人完整信息',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
GestureDetector(
|
||||
onTap: _todo,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _navy.withValues(alpha: 0.06),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.info_outline_rounded,
|
||||
color: _blue,
|
||||
size: 18,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPill(String text, Color color, Color bg) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2.5),
|
||||
decoration: BoxDecoration(
|
||||
color: bg,
|
||||
borderRadius: BorderRadius.circular(9),
|
||||
),
|
||||
child: Text(
|
||||
text,
|
||||
style: TextStyle(
|
||||
fontSize: 10.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 分节标题:蓝色竖条 + 标题 =====
|
||||
Widget _buildSectionTitle(String title) {
|
||||
return Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 4,
|
||||
height: 15,
|
||||
decoration: BoxDecoration(
|
||||
color: _blue,
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 基础资料卡 =====
|
||||
Widget _buildProfileCard() {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(12, 12, 14, 12),
|
||||
child: Row(
|
||||
children: [
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Container(
|
||||
width: 124,
|
||||
height: 92,
|
||||
color: const Color(0xFFF4F8FD),
|
||||
child: Image.asset(_robotImage, fit: BoxFit.contain),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'$_model · STD标准版',
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
height: 1.3,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
const Text(
|
||||
'独立图传 · 超声波声光 · 基础GNSS',
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(fontSize: 10.5, color: _gray),
|
||||
),
|
||||
const SizedBox(height: 7),
|
||||
_buildPill(
|
||||
_online ? '在线 · $_modeText' : '离线 · $_modeText',
|
||||
_online ? _green : const Color(0xFF6B7280),
|
||||
_online ? _greenBg : const Color(0xFFF0F2F5),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Divider(height: 1, color: _divider),
|
||||
_buildInfoRow('设备名称', _displayName),
|
||||
_buildInfoRow('设备SN', _maskedSn),
|
||||
_buildInfoRow('绑定状态', robot.hasHost ? '已授权' : '未绑定'),
|
||||
_buildInfoRow('所属类型', '履带式割草机器人'),
|
||||
_buildInfoRow('动力类型', '示例:纯电'),
|
||||
_buildInfoRow('最近上报', '示例:2026-10-20 09:41', isLast: true),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 运行与控制卡 =====
|
||||
Widget _buildRuntimeCard() {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(12, 12, 12, 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildStatBlock(
|
||||
Icons.battery_std_rounded,
|
||||
_batteryText,
|
||||
'能源状态',
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: _buildStatBlock(
|
||||
Icons.monitor_heart_outlined,
|
||||
_modeText,
|
||||
'运行模式',
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: _buildStatBlock(
|
||||
Icons.sports_esports_outlined,
|
||||
'无',
|
||||
'控制会话',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Divider(height: 1, color: _divider),
|
||||
_buildInfoRow(
|
||||
'GNSS定位',
|
||||
_online ? '定位有效' : '无定位',
|
||||
valueColor: _online ? _green : _gray,
|
||||
),
|
||||
_buildInfoRow('当前故障', '0项', isLast: true),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatBlock(IconData icon, String value, String label) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
decoration: BoxDecoration(
|
||||
color: _statBg,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(icon, size: 18, color: _navy),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
value,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
height: 1.05,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 10.5, color: _gray),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 通用信息行:左标签 / 右值 =====
|
||||
Widget _buildInfoRow(
|
||||
String label,
|
||||
String value, {
|
||||
Color? valueColor,
|
||||
bool isLast = false,
|
||||
}) {
|
||||
return Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 13),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(label, style: const TextStyle(fontSize: 13, color: _gray)),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
value,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
textAlign: TextAlign.right,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: valueColor ?? _navy,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (!isLast) const Divider(height: 1, color: _divider),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,563 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
|
||||
import '../../data/models/robot_data_model.dart';
|
||||
import '../widgets/robot_summary_card_v2.dart';
|
||||
|
||||
/// 灯光与声光(设备详情 → 常用控制操作 → 灯光与声光)
|
||||
///
|
||||
/// 二级 push 页面,无底部导航。
|
||||
///
|
||||
/// 能力边界(不编造):
|
||||
/// - 后端 / 遥控协议目前只有割刀、底盘升降、点火、急停,**没有灯光与鸣笛指令位**,
|
||||
/// 所以开关只切换界面状态并明确提示「指令通道未接入」,不伪装成真机已执行;
|
||||
/// - 音量、鸣笛时长、自动策略均为本地偏好口径,页脚与卡片内统一注明;
|
||||
/// - 设备离线时先拦截,给出明确离线提示。
|
||||
class RobotLightSoundPageV2 extends StatefulWidget {
|
||||
final RobotDataModel robot;
|
||||
|
||||
const RobotLightSoundPageV2({super.key, required this.robot});
|
||||
|
||||
@override
|
||||
State<RobotLightSoundPageV2> createState() => _RobotLightSoundPageV2State();
|
||||
}
|
||||
|
||||
class _RobotLightSoundPageV2State extends State<RobotLightSoundPageV2> {
|
||||
static const Color _navy = Color(0xFF1A2B4A);
|
||||
static const Color _gray = Color(0xFF86909C);
|
||||
static const Color _hint = Color(0xFFA8B3C5);
|
||||
static const Color _blue = Color(0xFF1C96F6);
|
||||
static const Color _cardBorder = Color(0xFFE5EDF7);
|
||||
static const Color _softBlue = Color(0xFFEAF3FE);
|
||||
static const Color _divider = Color(0xFFF0F4FA);
|
||||
static const Color _segBg = Color(0xFFF6FAFE);
|
||||
|
||||
/// 灯光开关(界面态;真机下发通道未接入)
|
||||
bool _headlight = false;
|
||||
bool _warningLight = false;
|
||||
bool _markerLight = false;
|
||||
|
||||
/// 自动策略(本地偏好)
|
||||
bool _nightAuto = true;
|
||||
bool _workWarning = true;
|
||||
bool _lowBatteryAlert = false;
|
||||
|
||||
/// 报警音量:0 低 / 1 中 / 2 高
|
||||
int _volumeIdx = 1;
|
||||
|
||||
/// 鸣笛时长:3 / 5 / 10 秒
|
||||
int _hornIdx = 0;
|
||||
|
||||
bool get _online => widget.robot.isOnline;
|
||||
|
||||
/// 统一的未接入提示:状态仍按操作切换,方便验收界面态
|
||||
void _notifyChannel(String action) {
|
||||
if (!_online) {
|
||||
CapsuleToast.show('设备离线,$action指令未下发', showCheck: false);
|
||||
} else {
|
||||
CapsuleToast.show(
|
||||
'$action指令通道未接入(设备端未开放灯光位),当前状态仅作界面预览',
|
||||
showCheck: false,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFEDF6FD),
|
||||
body: Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [Color(0xFFD9EBFA), Color(0xFFEDF6FD)],
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildTopBar(),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 4, 16, 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
RobotSummaryCardV2(robot: widget.robot),
|
||||
const SizedBox(height: 16),
|
||||
_buildSectionTitle(
|
||||
'灯光控制',
|
||||
trailing: _buildStatePill(
|
||||
on: _headlight || _warningLight || _markerLight,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_buildLightCard(),
|
||||
const SizedBox(height: 16),
|
||||
_buildSectionTitle('声光提示'),
|
||||
const SizedBox(height: 10),
|
||||
_buildSoundCard(),
|
||||
const SizedBox(height: 16),
|
||||
_buildSectionTitle('自动策略'),
|
||||
const SizedBox(height: 10),
|
||||
_buildAutoCard(),
|
||||
const SizedBox(height: 16),
|
||||
_buildFooterNote(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 顶栏 =====
|
||||
Widget _buildTopBar() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 6, 16, 10),
|
||||
child: Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => Navigator.of(context).pop(),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _navy.withValues(alpha: 0.06),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.arrow_back_ios_new_rounded,
|
||||
color: _blue,
|
||||
size: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
const Expanded(
|
||||
child: Text(
|
||||
'灯光与声光',
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () =>
|
||||
CapsuleToast.show('灯光与鸣笛需设备端开放控制通道,当前仅作界面预览', showCheck: false),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _navy.withValues(alpha: 0.06),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(Icons.info_outline, color: _blue, size: 18),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 分节标题:蓝竖条 + 标题 =====
|
||||
Widget _buildSectionTitle(String title, {Widget? trailing}) {
|
||||
return Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 4,
|
||||
height: 15,
|
||||
decoration: BoxDecoration(
|
||||
color: _blue,
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
?trailing,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatePill({required bool on}) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 9, vertical: 3),
|
||||
decoration: BoxDecoration(
|
||||
color: on ? _softBlue : const Color(0xFFF4F6F9),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Text(
|
||||
on ? '灯光已开' : '灯光全关',
|
||||
style: TextStyle(
|
||||
fontSize: 10.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: on ? _blue : _hint,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 卡片外壳 =====
|
||||
Widget _buildCard({required List<Widget> children}) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(14, 4, 14, 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: children,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 灯光控制 =====
|
||||
Widget _buildLightCard() {
|
||||
return _buildCard(
|
||||
children: [
|
||||
_buildSwitchRow(
|
||||
icon: Icons.lightbulb_outline,
|
||||
title: '前照灯',
|
||||
subtitle: '作业与夜间照明,照亮行进方向',
|
||||
value: _headlight,
|
||||
onChanged: (v) {
|
||||
setState(() => _headlight = v);
|
||||
_notifyChannel(v ? '开启前照灯' : '关闭前照灯');
|
||||
},
|
||||
),
|
||||
const Divider(height: 1, thickness: 0.6, color: _divider),
|
||||
_buildSwitchRow(
|
||||
icon: Icons.warning_amber_rounded,
|
||||
title: '警示灯',
|
||||
subtitle: '黄色频闪,作业时提醒周边人员',
|
||||
value: _warningLight,
|
||||
onChanged: (v) {
|
||||
setState(() => _warningLight = v);
|
||||
_notifyChannel(v ? '开启警示灯' : '关闭警示灯');
|
||||
},
|
||||
),
|
||||
const Divider(height: 1, thickness: 0.6, color: _divider),
|
||||
_buildSwitchRow(
|
||||
icon: Icons.light_mode_outlined,
|
||||
title: '示廓灯',
|
||||
subtitle: '车体轮廓提示,夜间让他人识别车身',
|
||||
value: _markerLight,
|
||||
onChanged: (v) {
|
||||
setState(() => _markerLight = v);
|
||||
_notifyChannel(v ? '开启示廓灯' : '关闭示廓灯');
|
||||
},
|
||||
isLast: true,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 声光提示 =====
|
||||
Widget _buildSoundCard() {
|
||||
return _buildCard(
|
||||
children: [
|
||||
const SizedBox(height: 12),
|
||||
_buildRowTitle(icon: Icons.volume_up_outlined, title: '报警音量'),
|
||||
const SizedBox(height: 10),
|
||||
_buildSegBar(
|
||||
labels: const ['低', '中', '高'],
|
||||
index: _volumeIdx,
|
||||
onChanged: (i) {
|
||||
setState(() => _volumeIdx = i);
|
||||
CapsuleToast.show(
|
||||
'音量档位已设为「${['低', '中', '高'][i]}」(本地偏好,未下发设备)',
|
||||
showCheck: false,
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildRowTitle(icon: Icons.schedule_outlined, title: '鸣笛时长'),
|
||||
const SizedBox(height: 10),
|
||||
_buildSegBar(
|
||||
labels: const ['3 秒', '5 秒', '10 秒'],
|
||||
index: _hornIdx,
|
||||
onChanged: (i) {
|
||||
setState(() => _hornIdx = i);
|
||||
CapsuleToast.show(
|
||||
'鸣笛时长已设为「${['3 秒', '5 秒', '10 秒'][i]}」(本地偏好,未下发设备)',
|
||||
showCheck: false,
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
GestureDetector(
|
||||
onTap: () => _notifyChannel('鸣笛'),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
height: 44,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: _blue.withValues(alpha: 0.5)),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.campaign_outlined, size: 18, color: _blue),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
'试鸣笛 ${['3 秒', '5 秒', '10 秒'][_hornIdx]}',
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: _blue,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 自动策略 =====
|
||||
Widget _buildAutoCard() {
|
||||
return _buildCard(
|
||||
children: [
|
||||
_buildSwitchRow(
|
||||
icon: Icons.nightlight_outlined,
|
||||
title: '夜间自动开灯',
|
||||
subtitle: '光线不足时自动开启前照灯与示廓灯',
|
||||
value: _nightAuto,
|
||||
onChanged: (v) {
|
||||
setState(() => _nightAuto = v);
|
||||
CapsuleToast.show(
|
||||
'夜间自动开灯${v ? '已启用' : '已关闭'}(本地策略,未下发设备)',
|
||||
showCheck: false,
|
||||
);
|
||||
},
|
||||
),
|
||||
const Divider(height: 1, thickness: 0.6, color: _divider),
|
||||
_buildSwitchRow(
|
||||
icon: Icons.agriculture_outlined,
|
||||
title: '作业时开启警示灯',
|
||||
subtitle: '任务开始自动点亮警示灯,结束后关闭',
|
||||
value: _workWarning,
|
||||
onChanged: (v) {
|
||||
setState(() => _workWarning = v);
|
||||
CapsuleToast.show(
|
||||
'作业时开启警示灯${v ? '已启用' : '已关闭'}(本地策略,未下发设备)',
|
||||
showCheck: false,
|
||||
);
|
||||
},
|
||||
),
|
||||
const Divider(height: 1, thickness: 0.6, color: _divider),
|
||||
_buildSwitchRow(
|
||||
icon: Icons.battery_alert_outlined,
|
||||
title: '低电量声光提醒',
|
||||
subtitle: '电量低于 20% 时鸣笛并闪烁警示灯',
|
||||
value: _lowBatteryAlert,
|
||||
onChanged: (v) {
|
||||
setState(() => _lowBatteryAlert = v);
|
||||
CapsuleToast.show(
|
||||
'低电量声光提醒${v ? '已启用' : '已关闭'}(本地策略,未下发设备)',
|
||||
showCheck: false,
|
||||
);
|
||||
},
|
||||
isLast: true,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 通用行:图标 + 标题 → 开关 =====
|
||||
Widget _buildSwitchRow({
|
||||
required IconData icon,
|
||||
required String title,
|
||||
required String subtitle,
|
||||
required bool value,
|
||||
required ValueChanged<bool> onChanged,
|
||||
bool isLast = false,
|
||||
}) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(top: 14, bottom: isLast ? 14 : 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 34,
|
||||
height: 34,
|
||||
decoration: BoxDecoration(
|
||||
color: _softBlue,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Icon(icon, size: 18, color: _blue),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 14.5,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
subtitle,
|
||||
style: const TextStyle(fontSize: 12, color: _gray),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Switch(
|
||||
value: value,
|
||||
onChanged: onChanged,
|
||||
activeThumbColor: Colors.white,
|
||||
activeTrackColor: _blue,
|
||||
inactiveThumbColor: Colors.white,
|
||||
inactiveTrackColor: const Color(0xFFDCE3EC),
|
||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildRowTitle({required IconData icon, required String title}) {
|
||||
return Row(
|
||||
children: [
|
||||
Icon(icon, size: 17, color: _blue),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 分段条:浅蓝轨道 + 白滑块(与 APP 开关机页同一套)
|
||||
Widget _buildSegBar({
|
||||
required List<String> labels,
|
||||
required int index,
|
||||
required ValueChanged<int> onChanged,
|
||||
}) {
|
||||
return Container(
|
||||
height: 40,
|
||||
padding: const EdgeInsets.all(3),
|
||||
decoration: BoxDecoration(
|
||||
color: _segBg,
|
||||
borderRadius: BorderRadius.circular(11),
|
||||
border: Border.all(color: const Color(0xFFDCEBFA)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
for (var i = 0; i < labels.length; i++)
|
||||
Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () => onChanged(i),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 160),
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: i == index ? Colors.white : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(9),
|
||||
boxShadow: i == index
|
||||
? [
|
||||
BoxShadow(
|
||||
color: _blue.withValues(alpha: 0.12),
|
||||
blurRadius: 6,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
]
|
||||
: null,
|
||||
),
|
||||
child: Text(
|
||||
labels[i],
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: i == index
|
||||
? FontWeight.w800
|
||||
: FontWeight.w600,
|
||||
color: i == index ? _blue : _gray,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFooterNote() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 11),
|
||||
decoration: BoxDecoration(
|
||||
color: _softBlue,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Icon(Icons.info_outline, size: 16, color: _blue),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'遥控协议暂未开放灯光与鸣笛指令位:本页开关只反映界面状态,'
|
||||
'音量、鸣笛时长与自动策略为本地偏好。真机控制需设备端开放对应通道。',
|
||||
style: TextStyle(
|
||||
fontSize: 11.5,
|
||||
height: 1.55,
|
||||
color: const Color(0xFF5C6B84).withValues(alpha: 0.95),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,588 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/usecases/get_device_location_usecase.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/site/presentation/cubit/site_cubit.dart';
|
||||
|
||||
import '../../data/models/robot_data_model.dart';
|
||||
import '../widgets/robot_summary_card_v2.dart';
|
||||
|
||||
/// 位置与地图详情(设计稿:全部功能中心 → 位置与地图)
|
||||
///
|
||||
/// 二级 push 页面,无底部导航。
|
||||
/// 经纬度走 `GetDeviceLocationUseCase`(与 DevicesCubit 同一接口源),
|
||||
/// 接口没返回就显示 `--`,不编造坐标;地图块是纯示意(设计稿也注明"地图为示意")。
|
||||
class RobotLocationPageV2 extends StatefulWidget {
|
||||
final RobotDataModel robot;
|
||||
|
||||
const RobotLocationPageV2({super.key, required this.robot});
|
||||
|
||||
@override
|
||||
State<RobotLocationPageV2> createState() => _RobotLocationPageV2State();
|
||||
}
|
||||
|
||||
class _RobotLocationPageV2State extends State<RobotLocationPageV2> {
|
||||
// ===== 色板(与机器人完整信息页一致)=====
|
||||
static const Color _navy = Color(0xFF1A2B4A);
|
||||
static const Color _gray = Color(0xFF86909C);
|
||||
static const Color _hint = Color(0xFFA8B3C5);
|
||||
static const Color _blue = Color(0xFF1C96F6);
|
||||
static const Color _cardBorder = Color(0xFFE5EDF7);
|
||||
static const Color _green = Color(0xFF2FBF6B);
|
||||
static const Color _greenBg = Color(0xFFE5F8EC);
|
||||
static const Color _divider = Color(0xFFF0F4FA);
|
||||
|
||||
double? _lat;
|
||||
double? _lng;
|
||||
bool _loading = true;
|
||||
String? _error;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadLocation();
|
||||
}
|
||||
|
||||
/// 定位接口:按设备名查询(与 DevicesCubit.getDeviceLocation 同一 usecase)
|
||||
Future<void> _loadLocation() async {
|
||||
setState(() {
|
||||
_loading = true;
|
||||
_error = null;
|
||||
});
|
||||
try {
|
||||
final result = await GetIt.I<GetDeviceLocationUseCase>().call(
|
||||
widget.robot.name,
|
||||
);
|
||||
if (!mounted) return;
|
||||
result.fold(
|
||||
(failure) => setState(() {
|
||||
_loading = false;
|
||||
_error = failure.message;
|
||||
}),
|
||||
(location) => setState(() {
|
||||
_loading = false;
|
||||
_lat = location.latitude;
|
||||
_lng = location.longitude;
|
||||
}),
|
||||
);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_loading = false;
|
||||
_error = '$e';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
bool get _hasLocation =>
|
||||
_lat != null && _lng != null && (_lat != 0 || _lng != 0);
|
||||
|
||||
/// 经度:东经 E / 西经 W
|
||||
String get _lngText {
|
||||
final v = _lng;
|
||||
if (v == null) return '--';
|
||||
return '${v.abs().toStringAsFixed(5)}° ${v >= 0 ? 'E' : 'W'}';
|
||||
}
|
||||
|
||||
/// 纬度:北纬 N / 南纬 S
|
||||
String get _latText {
|
||||
final v = _lat;
|
||||
if (v == null) return '--';
|
||||
return '${v.abs().toStringAsFixed(5)}° ${v >= 0 ? 'N' : 'S'}';
|
||||
}
|
||||
|
||||
void _todo() => CapsuleToast.show('功能暂未开发', showCheck: false);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFEDF6FD),
|
||||
body: Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [Color(0xFFD9EBFA), Color(0xFFEDF6FD)],
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildTopBar(context),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 4, 16, 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
RobotSummaryCardV2(robot: widget.robot),
|
||||
const SizedBox(height: 18),
|
||||
_buildSectionHeader(
|
||||
'当前位置与地图',
|
||||
trailing: '定位信息',
|
||||
onTrailingTap: _todo,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_buildMapCard(),
|
||||
const SizedBox(height: 18),
|
||||
_buildSectionTitle('位置数据'),
|
||||
const SizedBox(height: 10),
|
||||
_buildLocationDataCard(),
|
||||
const SizedBox(height: 14),
|
||||
Center(
|
||||
child: Text(
|
||||
_loading
|
||||
? '正在获取设备定位…'
|
||||
: (_hasLocation
|
||||
? '坐标来自设备实际 GNSS 上报'
|
||||
: (_error != null
|
||||
? '定位获取失败:$_error'
|
||||
: '设备暂未上报有效定位')),
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(fontSize: 10.5, color: _hint),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 顶栏 =====
|
||||
Widget _buildTopBar(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 6, 16, 2),
|
||||
child: Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => Navigator.of(context).pop(),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _navy.withValues(alpha: 0.06),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.arrow_back_ios_new_rounded,
|
||||
color: _blue,
|
||||
size: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Text(
|
||||
'位置与地图详情',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
GestureDetector(
|
||||
onTap: _todo,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _navy.withValues(alpha: 0.06),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.info_outline_rounded,
|
||||
color: _blue,
|
||||
size: 18,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPill(String text, Color color, Color bg) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2.5),
|
||||
decoration: BoxDecoration(
|
||||
color: bg,
|
||||
borderRadius: BorderRadius.circular(9),
|
||||
),
|
||||
child: Text(
|
||||
text,
|
||||
style: TextStyle(
|
||||
fontSize: 10.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 分节标题 =====
|
||||
Widget _buildSectionTitle(String title) {
|
||||
return Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 4,
|
||||
height: 15,
|
||||
decoration: BoxDecoration(
|
||||
color: _blue,
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSectionHeader(
|
||||
String title, {
|
||||
String? trailing,
|
||||
VoidCallback? onTrailingTap,
|
||||
}) {
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(child: _buildSectionTitle(title)),
|
||||
if (trailing != null)
|
||||
GestureDetector(
|
||||
onTap: onTrailingTap,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
trailing,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: _blue,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 2),
|
||||
const Icon(Icons.north_east_rounded, size: 12, color: _blue),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 地图卡 =====
|
||||
Widget _buildMapCard() {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(12, 12, 12, 0),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
child: SizedBox(
|
||||
height: 190,
|
||||
width: double.infinity,
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
// 示意地图:田垄 + 中央地块(纯绘制,不依赖任何地图 SDK)
|
||||
CustomPaint(painter: _FarmFieldPainter()),
|
||||
// 左上角场站标签
|
||||
Positioned(left: 10, top: 10, child: _buildSiteTag()),
|
||||
// 中央定位点(只有拿到真实坐标才显示)
|
||||
if (_hasLocation && !_loading)
|
||||
const Center(child: _LocationDot()),
|
||||
if (_loading)
|
||||
const Center(
|
||||
child: SizedBox(
|
||||
width: 22,
|
||||
height: 22,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: Color(0xFF1C96F6),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(14, 12, 14, 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'设备位置',
|
||||
style: TextStyle(
|
||||
fontSize: 13.5,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
const Text(
|
||||
'地图为示意,定位点来自设备实际GNSS数据',
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(fontSize: 10.5, color: _gray),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
_buildPill(
|
||||
_hasLocation ? 'GNSS有效' : '无定位',
|
||||
_hasLocation ? _green : const Color(0xFF6B7280),
|
||||
_hasLocation ? _greenBg : const Color(0xFFF0F2F5),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 地图左上角场站标签:真实场站名,取不到就不显示
|
||||
Widget _buildSiteTag() {
|
||||
final site = GetIt.I<SiteCubit>().state.selectedSite?.siteName;
|
||||
if (site == null || site.isEmpty) return const SizedBox.shrink();
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _navy.withValues(alpha: 0.10),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Text(
|
||||
site,
|
||||
style: const TextStyle(
|
||||
fontSize: 11.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 位置数据卡 =====
|
||||
Widget _buildLocationDataCard() {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildInfoRow('经度', _lngText),
|
||||
_buildInfoRow('纬度', _latText),
|
||||
_buildInfoRow('定位方式', '内置 GNSS'),
|
||||
_buildInfoRow(
|
||||
'定位状态',
|
||||
_hasLocation ? '有效 · 米级' : '未上报',
|
||||
valueColor: _hasLocation ? _green : _gray,
|
||||
),
|
||||
_buildInfoRow('卫星信息', '仅显示设备真实上报', isLast: true),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInfoRow(
|
||||
String label,
|
||||
String value, {
|
||||
Color? valueColor,
|
||||
bool isLast = false,
|
||||
}) {
|
||||
return Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 13),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(label, style: const TextStyle(fontSize: 13, color: _gray)),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
value,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
textAlign: TextAlign.right,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: valueColor ?? _navy,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (!isLast) const Divider(height: 1, color: _divider),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 中央定位点:外圈淡蓝光晕 + 白环 + 蓝色圆心
|
||||
class _LocationDot extends StatelessWidget {
|
||||
const _LocationDot();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: 68,
|
||||
height: 68,
|
||||
alignment: Alignment.center,
|
||||
decoration: const BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: Color(0x332B8FE8),
|
||||
),
|
||||
child: Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
alignment: Alignment.center,
|
||||
decoration: const BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: Colors.white,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Color(0x331A2B4A),
|
||||
blurRadius: 8,
|
||||
offset: Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Container(
|
||||
width: 18,
|
||||
height: 18,
|
||||
decoration: const BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: Color(0xFF1C96F6),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 示意地图:浅绿田垄 + 中央深蓝地块(对应设计稿的插画底图)
|
||||
class _FarmFieldPainter extends CustomPainter {
|
||||
static const Color _field = Color(0xFFDCE7DA);
|
||||
static const Color _plotDark = Color(0xFF1D4460);
|
||||
static const Color _plotLight = Color(0xFF2A5C7C);
|
||||
static const Color _plotBorder = Color(0xFF59C8F5);
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final rect = Offset.zero & size;
|
||||
canvas.drawRect(rect, Paint()..color = _field);
|
||||
|
||||
// 斜向田垄
|
||||
final stripe = Paint()..color = Colors.white.withValues(alpha: 0.42);
|
||||
const double gap = 44;
|
||||
const double stripeWidth = 20;
|
||||
for (double x = -size.height; x < size.width + size.height; x += gap) {
|
||||
canvas.save();
|
||||
canvas.translate(x, 0);
|
||||
canvas.rotate(-0.30);
|
||||
canvas.drawRect(
|
||||
Rect.fromLTWH(0, -size.height, stripeWidth, size.height * 3),
|
||||
stripe,
|
||||
);
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
// 中央地块:深蓝斜矩形 + 浅蓝描边
|
||||
final center = Offset(size.width / 2, size.height / 2);
|
||||
final plotRect = Rect.fromCenter(
|
||||
center: Offset.zero,
|
||||
width: size.width * 0.66,
|
||||
height: size.height * 0.72,
|
||||
);
|
||||
canvas.save();
|
||||
canvas.translate(center.dx, center.dy);
|
||||
canvas.rotate(-0.20);
|
||||
|
||||
final plotPaint = Paint()
|
||||
..shader = const LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [_plotLight, _plotDark],
|
||||
).createShader(plotRect);
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(plotRect, const Radius.circular(8)),
|
||||
plotPaint,
|
||||
);
|
||||
|
||||
// 地块内纵向纹理
|
||||
final linePaint = Paint()
|
||||
..color = const Color(0xFF0F2E44).withValues(alpha: 0.45)
|
||||
..strokeWidth = 2.5;
|
||||
for (double x = plotRect.left + 12; x < plotRect.right; x += 22) {
|
||||
canvas.drawLine(
|
||||
Offset(x, plotRect.top + 4),
|
||||
Offset(x, plotRect.bottom - 4),
|
||||
linePaint,
|
||||
);
|
||||
}
|
||||
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(plotRect, const Radius.circular(8)),
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 4
|
||||
..color = _plotBorder,
|
||||
);
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(covariant _FarmFieldPainter oldDelegate) => false;
|
||||
}
|
||||
@@ -0,0 +1,525 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/usecases/get_device_location_usecase.dart';
|
||||
|
||||
import '../../data/models/robot_data_model.dart';
|
||||
import '../widgets/robot_summary_card_v2.dart';
|
||||
import 'robot_location_page_v2.dart';
|
||||
|
||||
/// 网络与定位设置(设计稿:设备详情 → 设置 → 网络与定位参数)
|
||||
///
|
||||
/// 二级 push 页面,无底部导航。
|
||||
///
|
||||
/// 数据口径:
|
||||
/// - 在线状态、心跳、云平台连接都来自设备在线态与本地会话,不编造 RSSI/运营商;
|
||||
/// - GNSS 经纬度走 [GetDeviceLocationUseCase],与「位置与地图详情」同一接口源;
|
||||
/// - 后端没有 4G 信号强度、运营商、Wi-Fi 配置接口,相关行一律标「示例/未接入」,
|
||||
/// 点击不做假成功。
|
||||
class RobotNetworkLocationPageV2 extends StatefulWidget {
|
||||
final RobotDataModel robot;
|
||||
|
||||
const RobotNetworkLocationPageV2({super.key, required this.robot});
|
||||
|
||||
@override
|
||||
State<RobotNetworkLocationPageV2> createState() =>
|
||||
_RobotNetworkLocationPageV2State();
|
||||
}
|
||||
|
||||
class _RobotNetworkLocationPageV2State
|
||||
extends State<RobotNetworkLocationPageV2> {
|
||||
static const Color _navy = Color(0xFF1A2B4A);
|
||||
static const Color _gray = Color(0xFF86909C);
|
||||
static const Color _hint = Color(0xFFA8B3C5);
|
||||
static const Color _blue = Color(0xFF1C96F6);
|
||||
static const Color _cardBorder = Color(0xFFE5EDF7);
|
||||
static const Color _trackBg = Color(0xFFDCEBFA);
|
||||
static const Color _softBlue = Color(0xFFEAF3FE);
|
||||
static const Color _divider = Color(0xFFF0F4FA);
|
||||
static const Color _green = Color(0xFF2FBF6B);
|
||||
|
||||
/// 0 = 网络通信,1 = GNSS定位
|
||||
int _tab = 0;
|
||||
|
||||
double? _lat;
|
||||
double? _lng;
|
||||
bool _loading = true;
|
||||
String? _error;
|
||||
String _loadedAt = '--';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadLocation();
|
||||
}
|
||||
|
||||
Future<void> _loadLocation() async {
|
||||
setState(() {
|
||||
_loading = true;
|
||||
_error = null;
|
||||
});
|
||||
try {
|
||||
final result = await GetIt.I<GetDeviceLocationUseCase>().call(
|
||||
widget.robot.name,
|
||||
);
|
||||
if (!mounted) return;
|
||||
result.fold(
|
||||
(failure) => setState(() {
|
||||
_loading = false;
|
||||
_error = failure.message;
|
||||
}),
|
||||
(location) => setState(() {
|
||||
_loading = false;
|
||||
_lat = location.latitude;
|
||||
_lng = location.longitude;
|
||||
_loadedAt = _timeText(DateTime.now());
|
||||
}),
|
||||
);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_loading = false;
|
||||
_error = '$e';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static String _timeText(DateTime t) =>
|
||||
'${t.hour.toString().padLeft(2, '0')}:${t.minute.toString().padLeft(2, '0')}:${t.second.toString().padLeft(2, '0')}';
|
||||
|
||||
bool get _online => widget.robot.isOnline;
|
||||
|
||||
bool get _hasLocation =>
|
||||
_lat != null && _lng != null && (_lat != 0 || _lng != 0);
|
||||
|
||||
String get _latText {
|
||||
final v = _lat;
|
||||
if (v == null) return '--';
|
||||
return '${v.abs().toStringAsFixed(5)}° ${v >= 0 ? 'N' : 'S'}';
|
||||
}
|
||||
|
||||
String get _lngText {
|
||||
final v = _lng;
|
||||
if (v == null) return '--';
|
||||
return '${v.abs().toStringAsFixed(5)}° ${v >= 0 ? 'E' : 'W'}';
|
||||
}
|
||||
|
||||
void _todo() => CapsuleToast.show('配置通道未接入', showCheck: false);
|
||||
|
||||
void _openMap() {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => RobotLocationPageV2(robot: widget.robot),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFEDF6FD),
|
||||
body: Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [Color(0xFFD9EBFA), Color(0xFFEDF6FD)],
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildTopBar(),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 4, 16, 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
RobotSummaryCardV2(robot: widget.robot),
|
||||
const SizedBox(height: 14),
|
||||
_buildTabBar(),
|
||||
const SizedBox(height: 16),
|
||||
if (_tab == 0)
|
||||
..._buildNetworkTab()
|
||||
else
|
||||
..._buildGnssTab(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 顶栏:返回 + 标题 + 信息按钮 =====
|
||||
Widget _buildTopBar() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 6, 16, 2),
|
||||
child: Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => Navigator.of(context).pop(),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _navy.withValues(alpha: 0.06),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.arrow_back_ios_new_rounded,
|
||||
color: _blue,
|
||||
size: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Expanded(
|
||||
child: Text(
|
||||
'网络与定位设置',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
GestureDetector(
|
||||
onTap: () => CapsuleToast.show(
|
||||
'网络配置以设备端实际能力为准,APP 侧仅展示与只读',
|
||||
showCheck: false,
|
||||
),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _navy.withValues(alpha: 0.06),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.info_outline_rounded,
|
||||
color: _blue,
|
||||
size: 18,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 双档切换:网络通信 / GNSS定位 =====
|
||||
Widget _buildTabBar() {
|
||||
const labels = ['网络通信', 'GNSS定位'];
|
||||
return Container(
|
||||
height: 46,
|
||||
padding: const EdgeInsets.all(4),
|
||||
decoration: BoxDecoration(
|
||||
color: _trackBg,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
child: Row(
|
||||
children: List.generate(labels.length, (index) {
|
||||
final selected = _tab == index;
|
||||
return Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () => setState(() => _tab = index),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 180),
|
||||
curve: Curves.easeOutCubic,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: selected ? Colors.white : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(11),
|
||||
boxShadow: selected
|
||||
? [
|
||||
BoxShadow(
|
||||
color: _navy.withValues(alpha: 0.08),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
]
|
||||
: null,
|
||||
),
|
||||
child: Text(
|
||||
labels[index],
|
||||
style: TextStyle(
|
||||
fontSize: 13.5,
|
||||
fontWeight: selected ? FontWeight.w700 : FontWeight.w500,
|
||||
color: selected ? _blue : _gray,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 网络通信 =====
|
||||
List<Widget> _buildNetworkTab() {
|
||||
return [
|
||||
_buildSectionTitle('当前网络'),
|
||||
const SizedBox(height: 10),
|
||||
_buildInfoCard([
|
||||
('连接模式', _online ? '4G蜂窝网络' : '未连接'),
|
||||
('网络状态', _online ? '在线 · 信号良好' : '离线'),
|
||||
('云平台连接', _online ? '正常' : '断开'),
|
||||
('最近设备心跳', _online ? '刚刚' : '无心跳'),
|
||||
('独立图传视频', '未打开监看会话'),
|
||||
]),
|
||||
const SizedBox(height: 18),
|
||||
_buildSectionTitle('网络配置'),
|
||||
const SizedBox(height: 10),
|
||||
_buildEntryCard([
|
||||
(Icons.cell_tower_rounded, '4G模块信息', '运营商、信号强度与模块状态', _todo),
|
||||
(Icons.wifi_rounded, 'Wi-Fi配置', '按设备实际Wi-Fi硬件开放', _todo),
|
||||
(Icons.cloud_outlined, '云平台接入', '服务器与心跳只读/受限配置', _todo),
|
||||
]),
|
||||
const SizedBox(height: 14),
|
||||
_buildNote('连接模式与云平台状态取自设备在线态;运营商、信号强度需设备端上报后才会显示真实值。'),
|
||||
];
|
||||
}
|
||||
|
||||
// ===== GNSS 定位 =====
|
||||
List<Widget> _buildGnssTab() {
|
||||
return [
|
||||
_buildSectionTitle('定位状态'),
|
||||
const SizedBox(height: 10),
|
||||
_buildInfoCard([
|
||||
('定位模块', '内置 GNSS'),
|
||||
('当前定位', _loading ? '获取中…' : (_hasLocation ? '有效 · 米级' : '无定位')),
|
||||
('卫星信息', '仅显示设备真实上报'),
|
||||
('最近定位时间', _hasLocation ? _loadedAt : '--'),
|
||||
]),
|
||||
const SizedBox(height: 18),
|
||||
_buildSectionTitle('坐标'),
|
||||
const SizedBox(height: 10),
|
||||
_buildInfoCard([('纬度', _latText), ('经度', _lngText)]),
|
||||
const SizedBox(height: 18),
|
||||
_buildSectionTitle('定位配置与地图'),
|
||||
const SizedBox(height: 10),
|
||||
_buildEntryCard([
|
||||
(Icons.map_outlined, '在地图中查看定位', '定位点、轨迹与最后更新时间', _openMap),
|
||||
(Icons.explore_outlined, '定位参数', '坐标系、上报频率(设备端配置)', _todo),
|
||||
]),
|
||||
const SizedBox(height: 14),
|
||||
_buildNote(
|
||||
_loading
|
||||
? '正在获取设备定位…'
|
||||
: (_hasLocation
|
||||
? '坐标来自设备实际 GNSS 上报,已同步到「位置与地图详情」'
|
||||
: (_error != null ? '定位获取失败:$_error' : '设备暂未上报有效定位')),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
// ===== 分节标题:蓝竖条 + 粗体 =====
|
||||
Widget _buildSectionTitle(String title) {
|
||||
return Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 4,
|
||||
height: 15,
|
||||
decoration: BoxDecoration(
|
||||
color: _blue,
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 只读信息卡:左浅灰标签 + 右深色值 + 细分隔线 =====
|
||||
Widget _buildInfoCard(List<(String, String)> rows) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
for (int i = 0; i < rows.length; i++) ...[
|
||||
if (i > 0)
|
||||
const Divider(height: 1, thickness: 0.6, color: _divider),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
rows[i].$1,
|
||||
style: const TextStyle(fontSize: 13, color: _hint),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
rows[i].$2,
|
||||
textAlign: TextAlign.right,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 13.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 可点入口卡:图标 + 标题 + 副标题 + 箭头 =====
|
||||
Widget _buildEntryCard(List<(IconData, String, String, VoidCallback)> rows) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
for (int i = 0; i < rows.length; i++) ...[
|
||||
if (i > 0)
|
||||
const Divider(
|
||||
height: 1,
|
||||
thickness: 0.6,
|
||||
color: _divider,
|
||||
indent: 46,
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: rows[i].$4,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: _softBlue,
|
||||
borderRadius: BorderRadius.circular(11),
|
||||
),
|
||||
child: Icon(rows[i].$1, size: 19, color: _blue),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
rows[i].$2,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
Text(
|
||||
rows[i].$3,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 11.5,
|
||||
color: _gray,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const Icon(
|
||||
Icons.chevron_right_rounded,
|
||||
size: 20,
|
||||
color: Color(0xFFC9CDD4),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNote(String text) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: _softBlue,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Icon(
|
||||
_hasLocation
|
||||
? Icons.verified_user_rounded
|
||||
: Icons.info_outline_rounded,
|
||||
size: 15,
|
||||
color: _hasLocation ? _green : _blue,
|
||||
),
|
||||
const SizedBox(width: 7),
|
||||
Expanded(
|
||||
child: Text(
|
||||
text,
|
||||
style: const TextStyle(
|
||||
fontSize: 11.5,
|
||||
height: 1.55,
|
||||
color: Color(0xFF5C6B84),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,399 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
|
||||
import '../../data/models/robot_data_model.dart';
|
||||
import '../widgets/device_confirm_dialog.dart';
|
||||
import '../widgets/robot_summary_card_v2.dart';
|
||||
|
||||
/// 设备归属与安全(设计稿:设备卡片 → 更多 → 设备归属与安全)
|
||||
///
|
||||
/// 二级 push 页面,无底部导航。
|
||||
///
|
||||
/// 数据口径:
|
||||
/// - 设备名称、型号、在线态、SN 均来自 [RobotDataModel],SN 支持明文/脱敏切换;
|
||||
/// - 所有者、归属类型、首次认领、管理员列表后端暂无对应接口,按设计稿展示为示例值,
|
||||
/// 页脚与行内统一注明,不伪装成真实归属关系;
|
||||
/// - 高风险操作(移交管理员、解绑与所有权转让)一律先过 [showDeviceConfirmDialog],
|
||||
/// 未接入下发通道时只给明确提示,不执行不可逆动作。
|
||||
class RobotOwnershipPageV2 extends StatefulWidget {
|
||||
final RobotDataModel robot;
|
||||
|
||||
const RobotOwnershipPageV2({super.key, required this.robot});
|
||||
|
||||
@override
|
||||
State<RobotOwnershipPageV2> createState() => _RobotOwnershipPageV2State();
|
||||
}
|
||||
|
||||
class _RobotOwnershipPageV2State extends State<RobotOwnershipPageV2> {
|
||||
static const Color _navy = Color(0xFF1A2B4A);
|
||||
static const Color _gray = Color(0xFF86909C);
|
||||
static const Color _hint = Color(0xFFA8B3C5);
|
||||
static const Color _blue = Color(0xFF1C96F6);
|
||||
static const Color _danger = Color(0xFFF0483E);
|
||||
static const Color _cardBorder = Color(0xFFE5EDF7);
|
||||
static const Color _softBlue = Color(0xFFEAF3FE);
|
||||
static const Color _divider = Color(0xFFF0F4FA);
|
||||
static const Color _green = Color(0xFF2FBF6B);
|
||||
|
||||
/// SN 是否显示明文
|
||||
bool _showSn = false;
|
||||
|
||||
bool get _online => widget.robot.isOnline;
|
||||
|
||||
String get _snText =>
|
||||
_showSn ? widget.robot.name : RobotSummaryCardV2.maskedSnOf(widget.robot);
|
||||
|
||||
void _toggleSn() => setState(() => _showSn = !_showSn);
|
||||
|
||||
void _openSharedMembers() =>
|
||||
CapsuleToast.show('成员共享管理通道未接入', showCheck: false);
|
||||
|
||||
/// 移交管理员:变更角色不改变所有权
|
||||
Future<void> _transferAdmin() async {
|
||||
final ok = await showDeviceConfirmDialog(
|
||||
context,
|
||||
icon: Icons.workspace_premium_rounded,
|
||||
title: '移交管理员权限',
|
||||
message: '移交后你将成为普通成员,设备所有权不变。确认继续?',
|
||||
note: '建议先确认接手成员已在成员列表中。',
|
||||
confirmText: '继续移交',
|
||||
);
|
||||
if (!ok || !mounted) return;
|
||||
CapsuleToast.show('管理员移交通道未接入', showCheck: false);
|
||||
}
|
||||
|
||||
/// 解绑与所有权转让:不可逆,红色确认
|
||||
Future<void> _transferOwnership() async {
|
||||
final ok = await showDeviceConfirmDialog(
|
||||
context,
|
||||
icon: Icons.swap_horiz_rounded,
|
||||
title: '设备解绑与所有权转让',
|
||||
message: '解绑后你与本设备的关联将立即失效,需重新绑定才能继续使用。确认继续?',
|
||||
note: '需核验所有者权限和身份,SN 不能代替身份核验。',
|
||||
confirmText: '确认操作',
|
||||
danger: true,
|
||||
);
|
||||
if (!ok || !mounted) return;
|
||||
CapsuleToast.show('所有权转让通道未接入,需所有者身份核验', showCheck: false);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFEDF6FD),
|
||||
body: Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [Color(0xFFD9EBFA), Color(0xFFEDF6FD)],
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildTopBar(),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 4, 16, 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
RobotSummaryCardV2(robot: widget.robot),
|
||||
const SizedBox(height: 14),
|
||||
_buildOwnershipCard(),
|
||||
const SizedBox(height: 14),
|
||||
_buildAdminCard(),
|
||||
const SizedBox(height: 14),
|
||||
_buildRiskyCard(),
|
||||
const SizedBox(height: 14),
|
||||
_buildFooterNote(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 顶栏:返回 + 居中标题 =====
|
||||
Widget _buildTopBar() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 6, 16, 10),
|
||||
child: Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => Navigator.of(context).pop(),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: const SizedBox(
|
||||
width: 36,
|
||||
height: 36,
|
||||
child: Icon(
|
||||
Icons.arrow_back_ios_new_rounded,
|
||||
color: _navy,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
),
|
||||
const Expanded(
|
||||
child: Text(
|
||||
'设备归属与安全',
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 36),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 卡内标题:18 w800 =====
|
||||
Widget _buildCardTitle(String title, {Color color = _navy}) {
|
||||
return Text(
|
||||
title,
|
||||
style: TextStyle(fontSize: 17, fontWeight: FontWeight.w800, color: color),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 设备归属信息 =====
|
||||
Widget _buildOwnershipCard() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(14, 16, 14, 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_buildCardTitle('设备归属信息'),
|
||||
const SizedBox(height: 6),
|
||||
_buildKvRow('设备所有者', '待归属接口上报', muted: true),
|
||||
const Divider(height: 1, thickness: 0.6, color: _divider),
|
||||
_buildKvRow('归属类型', '企业组织', muted: true),
|
||||
const Divider(height: 1, thickness: 0.6, color: _divider),
|
||||
_buildKvRow('当前绑定', _online ? '已激活 · 归属有效' : '已绑定 · 设备离线'),
|
||||
const Divider(height: 1, thickness: 0.6, color: _divider),
|
||||
_buildKvRow(
|
||||
'设备SN',
|
||||
_snText,
|
||||
trailing: GestureDetector(
|
||||
onTap: _toggleSn,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 6),
|
||||
child: Icon(
|
||||
_showSn
|
||||
? Icons.visibility_rounded
|
||||
: Icons.visibility_off_outlined,
|
||||
size: 18,
|
||||
color: _gray,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const Divider(height: 1, thickness: 0.6, color: _divider),
|
||||
_buildKvRow('首次认领', '待归属接口上报', muted: true, isLast: true),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 管理员与授权 =====
|
||||
Widget _buildAdminCard() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(14, 16, 14, 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_buildCardTitle('管理员与授权'),
|
||||
const SizedBox(height: 6),
|
||||
_buildKvRow('当前管理员', '待归属接口上报', muted: true),
|
||||
const Divider(height: 1, thickness: 0.6, color: _divider),
|
||||
GestureDetector(
|
||||
onTap: _openSharedMembers,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: _buildKvRow(
|
||||
'成员权限管理',
|
||||
'进入共享管理',
|
||||
valueColor: _blue,
|
||||
isLast: true,
|
||||
trailing: const Icon(
|
||||
Icons.chevron_right_rounded,
|
||||
size: 20,
|
||||
color: _hint,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 高风险归属操作 =====
|
||||
Widget _buildRiskyCard() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(14, 16, 14, 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_buildCardTitle('高风险归属操作', color: _danger),
|
||||
const SizedBox(height: 4),
|
||||
_buildActionRow(
|
||||
icon: Icons.workspace_premium_rounded,
|
||||
title: '移交管理员权限',
|
||||
subtitle: '变更管理角色,不改变所有权',
|
||||
onTap: _transferAdmin,
|
||||
),
|
||||
const Divider(height: 1, thickness: 0.6, color: _divider),
|
||||
_buildActionRow(
|
||||
icon: Icons.swap_horiz_rounded,
|
||||
title: '设备解绑与所有权转让',
|
||||
subtitle: '需核验所有者权限和身份',
|
||||
danger: true,
|
||||
isLast: true,
|
||||
onTap: _transferOwnership,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildActionRow({
|
||||
required IconData icon,
|
||||
required String title,
|
||||
required String subtitle,
|
||||
required VoidCallback onTap,
|
||||
bool danger = false,
|
||||
bool isLast = false,
|
||||
}) {
|
||||
final color = danger ? _danger : _blue;
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(top: 14, bottom: isLast ? 14 : 12),
|
||||
child: Row(
|
||||
children: [
|
||||
SizedBox(width: 30, child: Icon(icon, size: 22, color: color)),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
subtitle,
|
||||
style: const TextStyle(fontSize: 12, color: _gray),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const Icon(
|
||||
Icons.chevron_right_rounded,
|
||||
size: 20,
|
||||
color: Color(0xFFC9CDD4),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 通用 KV 行 =====
|
||||
Widget _buildKvRow(
|
||||
String label,
|
||||
String value, {
|
||||
bool muted = false,
|
||||
Color? valueColor,
|
||||
Widget? trailing,
|
||||
bool isLast = false,
|
||||
}) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(top: 14, bottom: isLast ? 14 : 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(label, style: const TextStyle(fontSize: 13.5, color: _hint)),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
value,
|
||||
textAlign: TextAlign.right,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 13.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: valueColor ?? (muted ? _hint : _navy),
|
||||
),
|
||||
),
|
||||
),
|
||||
?trailing,
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFooterNote() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 11),
|
||||
decoration: BoxDecoration(
|
||||
color: _softBlue,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.verified_user_rounded,
|
||||
size: 16,
|
||||
color: _online ? _green : _blue,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const Expanded(
|
||||
child: Text(
|
||||
'管理员身份不等于设备所有者;SN 仅用于识别,不能凭 SN 完成解绑。'
|
||||
'归属信息需设备归属接口接入后显示真实值。',
|
||||
style: TextStyle(
|
||||
fontSize: 11.5,
|
||||
height: 1.55,
|
||||
color: Color(0xFF5C6B84),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,584 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
|
||||
import '../../data/models/robot_data_model.dart';
|
||||
import '../widgets/robot_summary_card_v2.dart';
|
||||
|
||||
/// 时间范围档位:标题 + 柱状图数据 + 横轴标签(示例数据)
|
||||
class _RangeData {
|
||||
final String label;
|
||||
final String chartTitle;
|
||||
final List<double> bars;
|
||||
final List<String> axis;
|
||||
|
||||
const _RangeData({
|
||||
required this.label,
|
||||
required this.chartTitle,
|
||||
required this.bars,
|
||||
required this.axis,
|
||||
});
|
||||
}
|
||||
|
||||
/// 一条历史事件
|
||||
class _RunEvent {
|
||||
final String title;
|
||||
final String time;
|
||||
final String tag;
|
||||
|
||||
const _RunEvent({required this.title, required this.time, required this.tag});
|
||||
}
|
||||
|
||||
/// 运行记录与健康分析(设计稿:全部功能中心 → 运行记录)
|
||||
///
|
||||
/// 二级 push 页面,无底部导航。
|
||||
/// 后端目前没有运行统计 / 运行事件接口(`device_run_param` 只有控制参数,
|
||||
/// `RunningStatusEntity` 只有实时值),所以三块统计、趋势柱状图、历史事件
|
||||
/// 均用示例数据渲染,并在页脚注明;里程后续可换成
|
||||
/// `RunningStatusEntity.totalWorkDistance`(host 累计作业里程)。
|
||||
class RobotRunRecordPageV2 extends StatefulWidget {
|
||||
final RobotDataModel robot;
|
||||
|
||||
const RobotRunRecordPageV2({super.key, required this.robot});
|
||||
|
||||
@override
|
||||
State<RobotRunRecordPageV2> createState() => _RobotRunRecordPageV2State();
|
||||
}
|
||||
|
||||
class _RobotRunRecordPageV2State extends State<RobotRunRecordPageV2> {
|
||||
static const Color _navy = Color(0xFF1A2B4A);
|
||||
static const Color _gray = Color(0xFF86909C);
|
||||
static const Color _hint = Color(0xFFA8B3C5);
|
||||
static const Color _blue = Color(0xFF1C96F6);
|
||||
static const Color _cardBorder = Color(0xFFE5EDF7);
|
||||
static const Color _softBlue = Color(0xFFEAF3FE);
|
||||
static const Color _trackBg = Color(0xFFDCEBFA);
|
||||
static const Color _gridLine = Color(0xFFE8F1FA);
|
||||
static const Color _axisLine = Color(0xFFCDE2F5);
|
||||
|
||||
/// 三个可切换档位(数据为示例,仅用于展示图表形态)
|
||||
static const List<_RangeData> _ranges = [
|
||||
_RangeData(
|
||||
label: '近7天',
|
||||
chartTitle: '运行趋势(最近7天)',
|
||||
bars: [3.2, 4.6, 2.8, 5.1, 4.0, 4.4, 5.0],
|
||||
axis: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
|
||||
),
|
||||
_RangeData(
|
||||
label: '近30天',
|
||||
chartTitle: '运行趋势(最近30天)',
|
||||
bars: [18.4, 22.6, 20.1, 25.4, 21.9],
|
||||
axis: ['第1周', '第2周', '第3周', '第4周', '第5周'],
|
||||
),
|
||||
_RangeData(
|
||||
label: '近90天',
|
||||
chartTitle: '运行趋势(最近90天)',
|
||||
bars: [62.5, 74.2, 81.6],
|
||||
axis: ['7月', '8月', '9月'],
|
||||
),
|
||||
];
|
||||
|
||||
/// 历史记录与事件(示例数据:后端暂无运行事件接口)
|
||||
static const List<_RunEvent> _events = [
|
||||
_RunEvent(title: '机器人开机', time: '今日 08:41', tag: '运行状态'),
|
||||
_RunEvent(title: 'APP遥控会话释放', time: '昨日 17:06', tag: '控制操作'),
|
||||
_RunEvent(title: '超声波联动停刀触发', time: '10月18日 15:42', tag: '已解除'),
|
||||
_RunEvent(title: '云端连接恢复', time: '10月18日 15:40', tag: '网络'),
|
||||
];
|
||||
|
||||
int _rangeIndex = 0;
|
||||
|
||||
_RangeData get _range => _ranges[_rangeIndex];
|
||||
|
||||
void _todo() => CapsuleToast.show('功能暂未开发', showCheck: false);
|
||||
|
||||
void _onCustomRange() {
|
||||
CapsuleToast.show('自定义时间范围暂未开发', showCheck: false);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFEDF6FD),
|
||||
body: Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [Color(0xFFD9EBFA), Color(0xFFEDF6FD)],
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildTopBar(context),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 4, 16, 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
RobotSummaryCardV2(robot: widget.robot),
|
||||
const SizedBox(height: 14),
|
||||
_buildRangeBar(),
|
||||
const SizedBox(height: 18),
|
||||
_buildSectionTitle('运行数据概况'),
|
||||
const SizedBox(height: 10),
|
||||
_buildOverviewCard(),
|
||||
const SizedBox(height: 18),
|
||||
_buildSectionTitle(_range.chartTitle),
|
||||
const SizedBox(height: 10),
|
||||
_buildChartCard(),
|
||||
const SizedBox(height: 18),
|
||||
_buildSectionTitle('历史记录与事件'),
|
||||
const SizedBox(height: 10),
|
||||
_buildEventTimeline(),
|
||||
const SizedBox(height: 14),
|
||||
const Center(
|
||||
child: Text(
|
||||
'运行统计与历史事件为示例数据,接入统计接口后自动替换',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 10.5, color: _hint),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 顶栏 =====
|
||||
Widget _buildTopBar(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 6, 16, 2),
|
||||
child: Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => Navigator.of(context).pop(),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _navy.withValues(alpha: 0.06),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.arrow_back_ios_new_rounded,
|
||||
color: _blue,
|
||||
size: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Expanded(
|
||||
child: Text(
|
||||
'运行记录与健康分析',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: _todo,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _navy.withValues(alpha: 0.06),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.info_outline_rounded,
|
||||
color: _blue,
|
||||
size: 18,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 分节标题 =====
|
||||
Widget _buildSectionTitle(String title) {
|
||||
return Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 4,
|
||||
height: 15,
|
||||
decoration: BoxDecoration(
|
||||
color: _blue,
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 时间范围:近7天 / 近30天 / 近90天 / 自定义 =====
|
||||
Widget _buildRangeBar() {
|
||||
final labels = [..._ranges.map((e) => e.label), '自定义'];
|
||||
return Container(
|
||||
height: 46,
|
||||
padding: const EdgeInsets.all(4),
|
||||
decoration: BoxDecoration(
|
||||
color: _trackBg,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
child: Row(
|
||||
children: List.generate(labels.length, (index) {
|
||||
final isCustom = index == labels.length - 1;
|
||||
final selected = !isCustom && _rangeIndex == index;
|
||||
return Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: isCustom
|
||||
? _onCustomRange
|
||||
: () => setState(() => _rangeIndex = index),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 180),
|
||||
curve: Curves.easeOutCubic,
|
||||
decoration: BoxDecoration(
|
||||
color: selected ? Colors.white : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(11),
|
||||
boxShadow: selected
|
||||
? [
|
||||
BoxShadow(
|
||||
color: _navy.withValues(alpha: 0.08),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
]
|
||||
: null,
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
labels[index],
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: selected ? FontWeight.w700 : FontWeight.w500,
|
||||
color: selected ? _blue : _gray,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 运行数据概况:三块浅蓝统计 =====
|
||||
Widget _buildOverviewCard() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildStatBlock(
|
||||
icon: Icons.access_time_rounded,
|
||||
value: '128.5h',
|
||||
label: '累计运行',
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: _buildStatBlock(
|
||||
icon: Icons.power_settings_new_rounded,
|
||||
value: '86次',
|
||||
label: '启动次数',
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: _buildStatBlock(
|
||||
icon: Icons.show_chart_rounded,
|
||||
value: '12.8km',
|
||||
label: '示例里程',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatBlock({
|
||||
required IconData icon,
|
||||
required String value,
|
||||
required String label,
|
||||
}) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
decoration: BoxDecoration(
|
||||
color: _softBlue,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(icon, size: 22, color: _navy),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
value,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 11.5, color: _gray),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 趋势柱状图卡 =====
|
||||
Widget _buildChartCard() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(14, 14, 14, 12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
const Text(
|
||||
'每日运行时长',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
Text(
|
||||
'单位:小时',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: _hint.withValues(alpha: 0.95),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
_buildBarChart(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBarChart() {
|
||||
final bars = _range.bars;
|
||||
final axis = _range.axis;
|
||||
final maxValue = bars.reduce(math.max);
|
||||
const double chartHeight = 132;
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: chartHeight,
|
||||
child: Stack(
|
||||
children: [
|
||||
// 横向网格线(4 条)
|
||||
Positioned.fill(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: List.generate(
|
||||
4,
|
||||
(_) => Container(height: 1, color: _gridLine),
|
||||
),
|
||||
),
|
||||
),
|
||||
// 柱体
|
||||
Positioned.fill(
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
for (var i = 0; i < bars.length; i++)
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6),
|
||||
child: _buildBar(
|
||||
height: maxValue == 0
|
||||
? 0
|
||||
: (bars[i] / maxValue) * (chartHeight - 18),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Container(height: 1, color: _axisLine),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
for (var i = 0; i < axis.length; i++)
|
||||
Expanded(
|
||||
child: Text(
|
||||
axis[i],
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 11, color: _gray),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBar({required double height}) {
|
||||
return Container(
|
||||
height: height < 6 ? 6 : height,
|
||||
decoration: BoxDecoration(
|
||||
gradient: const LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [Color(0xFF8FD0FC), Color(0xFF1C96F6)],
|
||||
),
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(7),
|
||||
topRight: Radius.circular(7),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 历史记录时间轴 =====
|
||||
Widget _buildEventTimeline() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(14, 8, 14, 10),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
for (var i = 0; i < _events.length; i++)
|
||||
_buildEventRow(_events[i], isLast: i == _events.length - 1),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEventRow(_RunEvent event, {required bool isLast}) {
|
||||
return IntrinsicHeight(
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 22,
|
||||
child: Column(
|
||||
children: [
|
||||
const SizedBox(height: 16),
|
||||
Container(
|
||||
width: 9,
|
||||
height: 9,
|
||||
decoration: const BoxDecoration(
|
||||
color: _blue,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
if (!isLast)
|
||||
Expanded(child: Container(width: 1.4, color: _gridLine)),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(top: 10, bottom: isLast ? 6 : 14),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
event.title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 14.5,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Text(
|
||||
'${event.time} · ${event.tag}',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 12, color: _gray),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,665 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/usecases/get_device_location_usecase.dart';
|
||||
|
||||
import '../../data/models/robot_data_model.dart';
|
||||
import '../widgets/robot_summary_card_v2.dart';
|
||||
|
||||
/// 传感器与通信详情(设计稿:全部功能中心 → 传感器监测)
|
||||
///
|
||||
/// 二级 push 页面:超声波 / 定位 / 通信 / 机构 四个分段。
|
||||
/// - 超声波:设计稿本身注明“以下为演示距离”,后端目前只有避障标志位
|
||||
/// (`RunningStatusEntity.obstacleFlag`),没有 6 路测距,故按示例渲染并注明;
|
||||
/// - 定位:走 `GetDeviceLocationUseCase`,经纬度是设备真实上报;
|
||||
/// - 通信 / 机构:后端暂无对应字段,示例值逐行标注「示例」。
|
||||
class RobotSensorPageV2 extends StatefulWidget {
|
||||
final RobotDataModel robot;
|
||||
|
||||
const RobotSensorPageV2({super.key, required this.robot});
|
||||
|
||||
@override
|
||||
State<RobotSensorPageV2> createState() => _RobotSensorPageV2State();
|
||||
}
|
||||
|
||||
class _RobotSensorPageV2State extends State<RobotSensorPageV2> {
|
||||
// ===== 色板(与机器人完整信息 / 位置与地图详情一致)=====
|
||||
static const Color _navy = Color(0xFF1A2B4A);
|
||||
static const Color _gray = Color(0xFF86909C);
|
||||
static const Color _hint = Color(0xFFA8B3C5);
|
||||
static const Color _blue = Color(0xFF1C96F6);
|
||||
static const Color _cardBorder = Color(0xFFE5EDF7);
|
||||
static const Color _green = Color(0xFF2FBF6B);
|
||||
static const Color _greenBg = Color(0xFFE5F8EC);
|
||||
static const Color _divider = Color(0xFFF0F4FA);
|
||||
static const Color _trackBg = Color(0xFFDFEBF9);
|
||||
|
||||
static const List<String> _tabs = ['超声波', '定位', '通信', '机构'];
|
||||
|
||||
/// 超声波 6 路测距(示例值,与设计稿一致)
|
||||
static const List<(String, String)> _ultrasonicRows = [
|
||||
('前左', '1.5m'),
|
||||
('前中', '1.8m'),
|
||||
('前右', '2.0m'),
|
||||
('左侧', '1.3m'),
|
||||
('右侧', '1.7m'),
|
||||
('后部', '2.1m'),
|
||||
];
|
||||
|
||||
int _tabIndex = 0;
|
||||
|
||||
double? _lat;
|
||||
double? _lng;
|
||||
bool _locLoading = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadLocation();
|
||||
}
|
||||
|
||||
Future<void> _loadLocation() async {
|
||||
try {
|
||||
final result = await GetIt.I<GetDeviceLocationUseCase>().call(
|
||||
widget.robot.name,
|
||||
);
|
||||
if (!mounted) return;
|
||||
result.fold(
|
||||
(_) => setState(() => _locLoading = false),
|
||||
(location) => setState(() {
|
||||
_locLoading = false;
|
||||
_lat = location.latitude;
|
||||
_lng = location.longitude;
|
||||
}),
|
||||
);
|
||||
} catch (_) {
|
||||
if (!mounted) return;
|
||||
setState(() => _locLoading = false);
|
||||
}
|
||||
}
|
||||
|
||||
bool get _hasLocation =>
|
||||
_lat != null && _lng != null && (_lat != 0 || _lng != 0);
|
||||
|
||||
String get _lngText {
|
||||
final v = _lng;
|
||||
if (v == null) return '--';
|
||||
return '${v.abs().toStringAsFixed(5)}° ${v >= 0 ? 'E' : 'W'}';
|
||||
}
|
||||
|
||||
String get _latText {
|
||||
final v = _lat;
|
||||
if (v == null) return '--';
|
||||
return '${v.abs().toStringAsFixed(5)}° ${v >= 0 ? 'N' : 'S'}';
|
||||
}
|
||||
|
||||
void _todo() => CapsuleToast.show('功能暂未开发', showCheck: false);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFEDF6FD),
|
||||
body: Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [Color(0xFFD9EBFA), Color(0xFFEDF6FD)],
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildTopBar(context),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 4, 16, 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
RobotSummaryCardV2(robot: widget.robot),
|
||||
const SizedBox(height: 14),
|
||||
_buildTabBar(),
|
||||
const SizedBox(height: 16),
|
||||
_buildTabContent(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 顶栏 =====
|
||||
Widget _buildTopBar(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 6, 16, 2),
|
||||
child: Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => Navigator.of(context).pop(),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _navy.withValues(alpha: 0.06),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.arrow_back_ios_new_rounded,
|
||||
color: _blue,
|
||||
size: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Expanded(
|
||||
child: Text(
|
||||
'传感器与通信详情',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: _todo,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _navy.withValues(alpha: 0.06),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.info_outline_rounded,
|
||||
color: _blue,
|
||||
size: 18,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 四段 Tab:超声波 / 定位 / 通信 / 机构 =====
|
||||
Widget _buildTabBar() {
|
||||
return Container(
|
||||
height: 46,
|
||||
padding: const EdgeInsets.all(4),
|
||||
decoration: BoxDecoration(
|
||||
color: _trackBg,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
child: Row(
|
||||
children: List.generate(_tabs.length, (index) {
|
||||
final selected = _tabIndex == index;
|
||||
return Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () => setState(() => _tabIndex = index),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 180),
|
||||
curve: Curves.easeOutCubic,
|
||||
decoration: BoxDecoration(
|
||||
color: selected ? Colors.white : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(11),
|
||||
boxShadow: selected
|
||||
? [
|
||||
BoxShadow(
|
||||
color: _navy.withValues(alpha: 0.08),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
]
|
||||
: null,
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
_tabs[index],
|
||||
style: TextStyle(
|
||||
fontSize: 12.5,
|
||||
fontWeight: selected ? FontWeight.w700 : FontWeight.w500,
|
||||
color: selected ? _blue : _gray,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTabContent() {
|
||||
switch (_tabIndex) {
|
||||
case 1:
|
||||
return _buildPositionTab();
|
||||
case 2:
|
||||
return _buildCommTab();
|
||||
case 3:
|
||||
return _buildMechanismTab();
|
||||
case 0:
|
||||
default:
|
||||
return _buildUltrasonicTab();
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 分节标题 =====
|
||||
Widget _buildSectionTitle(String title) {
|
||||
return Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 4,
|
||||
height: 15,
|
||||
decoration: BoxDecoration(
|
||||
color: _blue,
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 超声波 =====
|
||||
Widget _buildUltrasonicTab() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_buildSectionTitle('超声波实时状态'),
|
||||
const SizedBox(height: 10),
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(14, 13, 14, 0),
|
||||
child: Row(
|
||||
children: [
|
||||
const Text(
|
||||
'超声波障碍检测',
|
||||
style: TextStyle(
|
||||
fontSize: 13.5,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 9,
|
||||
vertical: 3,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: _greenBg,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: const Text(
|
||||
'6/6正常',
|
||||
style: TextStyle(
|
||||
fontSize: 10.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: _green,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(12, 10, 12, 0),
|
||||
child: _buildSonarPanel(),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(14, 10, 14, 13),
|
||||
child: Text(
|
||||
'以下为演示距离;实际传感器位置、数量按设备SN加载。',
|
||||
style: TextStyle(
|
||||
fontSize: 10.5,
|
||||
color: _gray.withValues(alpha: 0.95),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 18),
|
||||
_buildSectionTitle('传感器测距'),
|
||||
const SizedBox(height: 10),
|
||||
_buildRowsCard(
|
||||
_ultrasonicRows
|
||||
.map((row) => (row.$1, '${row.$2} · 正常', _green))
|
||||
.toList(),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 超声波示意区:同心虚线环 + 中央机器人 + 前后距离标签
|
||||
Widget _buildSonarPanel() {
|
||||
return ClipRRect(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
child: Container(
|
||||
height: 248,
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [Color(0xFFEDF6FD), Color(0xFFD8E9F8)],
|
||||
),
|
||||
),
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
// 虚线同心环
|
||||
Positioned.fill(
|
||||
child: CustomPaint(painter: _SonarRingPainter(color: _blue)),
|
||||
),
|
||||
// 前方距离标签
|
||||
Positioned(top: 26, child: _buildDistanceTag('前:1.8m')),
|
||||
// 中央机器人
|
||||
_buildRobotBlock(),
|
||||
// 后方距离标签
|
||||
Positioned(bottom: 26, child: _buildDistanceTag('后:2.1m')),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDistanceTag(String text) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 11, vertical: 5),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _navy.withValues(alpha: 0.08),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Text(
|
||||
text,
|
||||
style: const TextStyle(
|
||||
fontSize: 12.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: _blue,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 中央机器人方块:深蓝机身 + 红橙描边 + 竖排 SATA / MC700
|
||||
///
|
||||
/// 宽高跟设计稿同比例:宽 ≈ 最内圈虚线环直径(不大于它,避免把内环完全盖住),
|
||||
/// 高约为宽的 0.88,圆角、描边、字号均按该比例缩放。
|
||||
Widget _buildRobotBlock() {
|
||||
return Container(
|
||||
width: 88,
|
||||
height: 78,
|
||||
decoration: BoxDecoration(
|
||||
gradient: const LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [Color(0xFF2A4A61), Color(0xFF16324A)],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(color: const Color(0xFFF0604D), width: 5),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _navy.withValues(alpha: 0.18),
|
||||
blurRadius: 16,
|
||||
offset: const Offset(0, 6),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
RotatedBox(
|
||||
quarterTurns: 1,
|
||||
child: Text(
|
||||
'SATA',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
height: 1.1,
|
||||
fontWeight: FontWeight.w800,
|
||||
letterSpacing: 1.5,
|
||||
color: Colors.white.withValues(alpha: 0.95),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 9),
|
||||
RotatedBox(
|
||||
quarterTurns: 1,
|
||||
child: Text(
|
||||
RobotSummaryCardV2.modelOf(widget.robot),
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
height: 1.1,
|
||||
fontWeight: FontWeight.w800,
|
||||
letterSpacing: 1,
|
||||
color: Colors.white.withValues(alpha: 0.95),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 定位 =====
|
||||
Widget _buildPositionTab() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_buildSectionTitle('定位与卫星'),
|
||||
const SizedBox(height: 10),
|
||||
_buildRowsCard([
|
||||
('经度', _lngText, _navy),
|
||||
('纬度', _latText, _navy),
|
||||
('定位方式', '内置 GNSS', _navy),
|
||||
(
|
||||
'定位状态',
|
||||
_locLoading ? '获取中…' : (_hasLocation ? '有效 · 米级' : '未上报'),
|
||||
_hasLocation ? _green : _gray,
|
||||
),
|
||||
('卫星数', '示例:18 颗', _navy),
|
||||
('RTK 差分', '示例:未启用', _navy),
|
||||
]),
|
||||
const SizedBox(height: 10),
|
||||
_buildSampleNote(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 通信 =====
|
||||
Widget _buildCommTab() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_buildSectionTitle('通信链路'),
|
||||
const SizedBox(height: 10),
|
||||
_buildRowsCard([
|
||||
(
|
||||
'设备在线',
|
||||
widget.robot.isOnline ? '在线' : '离线',
|
||||
widget.robot.isOnline ? _green : _gray,
|
||||
),
|
||||
('通信方式', '示例:MQTT 长连接', _navy),
|
||||
('网络类型', '示例:4G 全网通', _navy),
|
||||
('信号强度', '示例:-68 dBm', _navy),
|
||||
('链路延迟', '示例:120 ms', _navy),
|
||||
('最后上报', '示例:2026-10-20 09:41', _navy),
|
||||
]),
|
||||
const SizedBox(height: 10),
|
||||
_buildSampleNote(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 机构 =====
|
||||
Widget _buildMechanismTab() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_buildSectionTitle('作业机构'),
|
||||
const SizedBox(height: 10),
|
||||
_buildRowsCard([
|
||||
('割盘升降', '示例:停止', _navy),
|
||||
('刀盘转速', '示例:0 r/min', _navy),
|
||||
('底盘倾角', '示例:正常', _green),
|
||||
('障碍物检测', '示例:未触发', _green),
|
||||
('行走驱动', '示例:正常', _green),
|
||||
('急停开关', '示例:未按下', _green),
|
||||
]),
|
||||
const SizedBox(height: 10),
|
||||
_buildSampleNote(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSampleNote() {
|
||||
return const Center(
|
||||
child: Text(
|
||||
'标注「示例」的字段后端暂未上报,接入后自动替换',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 10.5, color: _hint),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 通用两栏行卡 =====
|
||||
Widget _buildRowsCard(List<(String, String, Color)> rows) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
for (var i = 0; i < rows.length; i++)
|
||||
Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 14,
|
||||
vertical: 13,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
rows[i].$1,
|
||||
style: const TextStyle(fontSize: 13, color: _gray),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
rows[i].$2,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
textAlign: TextAlign.right,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: rows[i].$3,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (i != rows.length - 1)
|
||||
const Divider(height: 1, color: _divider),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 超声波示意:三圈虚线同心环
|
||||
class _SonarRingPainter extends CustomPainter {
|
||||
final Color color;
|
||||
|
||||
const _SonarRingPainter({required this.color});
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final center = Offset(size.width / 2, size.height / 2);
|
||||
final paint = Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 1.2
|
||||
..color = color.withValues(alpha: 0.28);
|
||||
|
||||
// 三圈半径按面板高度等比缩放,保证小屏也不过界
|
||||
final maxRadius = math.min(size.width, size.height) * 0.44;
|
||||
for (final factor in const [0.42, 0.72, 1.0]) {
|
||||
final radius = maxRadius * factor;
|
||||
const double dash = 5;
|
||||
const double gap = 6;
|
||||
final circumference = 2 * math.pi * radius;
|
||||
final total = (circumference / (dash + gap)).floor();
|
||||
for (var i = 0; i < total; i++) {
|
||||
final start = (i * (dash + gap)) / radius;
|
||||
final sweep = dash / radius;
|
||||
canvas.drawArc(
|
||||
Rect.fromCircle(center: center, radius: radius),
|
||||
start,
|
||||
sweep,
|
||||
false,
|
||||
paint,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(covariant _SonarRingPainter oldDelegate) =>
|
||||
oldDelegate.color != color;
|
||||
}
|
||||
@@ -0,0 +1,644 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
|
||||
import '../../data/models/robot_data_model.dart';
|
||||
import '../../data/voice_preset_store.dart';
|
||||
import '../widgets/robot_summary_card_v2.dart';
|
||||
|
||||
/// 预设语音管理(设计稿:全部功能中心 → 语音喊话)
|
||||
///
|
||||
/// 二级 push 页面,无底部导航。
|
||||
/// - 预设语音:后端暂无语音接口,按设备名存在本地 prefs([VoicePresetStore]),
|
||||
/// 列表可新增 / 编辑,出厂自带三条默认语音;
|
||||
/// - 试听:需要设备端语音合成,当前未接入,点击给明确提示而不是假装播放;
|
||||
/// - 实时喊话:第二阶段能力,入口保留并标「待开放」。
|
||||
class RobotVoicePresetPageV2 extends StatefulWidget {
|
||||
final RobotDataModel robot;
|
||||
|
||||
const RobotVoicePresetPageV2({super.key, required this.robot});
|
||||
|
||||
@override
|
||||
State<RobotVoicePresetPageV2> createState() => _RobotVoicePresetPageV2State();
|
||||
}
|
||||
|
||||
class _RobotVoicePresetPageV2State extends State<RobotVoicePresetPageV2> {
|
||||
static const Color _navy = Color(0xFF1A2B4A);
|
||||
static const Color _gray = Color(0xFF86909C);
|
||||
static const Color _hint = Color(0xFFA8B3C5);
|
||||
static const Color _blue = Color(0xFF1C96F6);
|
||||
static const Color _cardBorder = Color(0xFFE5EDF7);
|
||||
static const Color _divider = Color(0xFFF0F4FA);
|
||||
static const Color _softBlue = Color(0xFFEAF3FE);
|
||||
static const Color _softGray = Color(0xFFF4F6F9);
|
||||
|
||||
final TextEditingController _nameCtrl = TextEditingController();
|
||||
final TextEditingController _textCtrl = TextEditingController();
|
||||
final FocusNode _nameFocus = FocusNode();
|
||||
final GlobalKey _editorKey = GlobalKey();
|
||||
final ScrollController _scrollCtrl = ScrollController();
|
||||
|
||||
List<VoicePreset> _presets = <VoicePreset>[];
|
||||
bool _loading = true;
|
||||
|
||||
/// null 表示正在新增;否则为被编辑语音的 id
|
||||
String? _editingId;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_load();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_nameCtrl.dispose();
|
||||
_textCtrl.dispose();
|
||||
_nameFocus.dispose();
|
||||
_scrollCtrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _load() async {
|
||||
final presets = await VoicePresetStore.loadPresets(widget.robot.name);
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_presets = presets;
|
||||
_loading = false;
|
||||
});
|
||||
}
|
||||
|
||||
void _todo() => CapsuleToast.show('功能暂未开发', showCheck: false);
|
||||
|
||||
/// 点列表项右侧铅笔:把这条填进下方编辑卡
|
||||
void _editPreset(VoicePreset preset) {
|
||||
setState(() => _editingId = preset.id);
|
||||
_nameCtrl.text = preset.name;
|
||||
_textCtrl.text = preset.text;
|
||||
_focusEditor();
|
||||
}
|
||||
|
||||
/// 点「+ 新增」:清空编辑卡,进入新建模式
|
||||
void _startCreate() {
|
||||
setState(() => _editingId = null);
|
||||
_nameCtrl.clear();
|
||||
_textCtrl.clear();
|
||||
_focusEditor();
|
||||
}
|
||||
|
||||
void _focusEditor() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
final ctx = _editorKey.currentContext;
|
||||
if (ctx != null) {
|
||||
Scrollable.ensureVisible(
|
||||
ctx,
|
||||
duration: const Duration(milliseconds: 260),
|
||||
curve: Curves.easeOutCubic,
|
||||
alignment: 0.05,
|
||||
);
|
||||
}
|
||||
_nameFocus.requestFocus();
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _savePreset() async {
|
||||
final name = _nameCtrl.text.trim();
|
||||
final text = _textCtrl.text.trim();
|
||||
if (name.isEmpty) {
|
||||
CapsuleToast.show('请填写语音名称', showCheck: false);
|
||||
_nameFocus.requestFocus();
|
||||
return;
|
||||
}
|
||||
if (text.isEmpty) {
|
||||
CapsuleToast.show('请填写语音文字', showCheck: false);
|
||||
return;
|
||||
}
|
||||
|
||||
final presets = List<VoicePreset>.of(_presets);
|
||||
final editingId = _editingId;
|
||||
if (editingId == null) {
|
||||
final id = 'custom_${DateTime.now().millisecondsSinceEpoch}';
|
||||
presets.add(VoicePreset(id: id, name: name, text: text));
|
||||
_editingId = id;
|
||||
} else {
|
||||
final index = presets.indexWhere((e) => e.id == editingId);
|
||||
if (index < 0) {
|
||||
presets.add(VoicePreset(id: editingId, name: name, text: text));
|
||||
} else {
|
||||
presets[index] = presets[index].copyWith(name: name, text: text);
|
||||
}
|
||||
}
|
||||
|
||||
await VoicePresetStore.savePresets(widget.robot.name, presets);
|
||||
if (!mounted) return;
|
||||
setState(() => _presets = presets);
|
||||
CapsuleToast.show('预设语音已保存');
|
||||
}
|
||||
|
||||
void _playPreset(VoicePreset preset) {
|
||||
debugPrint('🔊 [VoicePreset] 试听: ${preset.name} / ${preset.text}');
|
||||
CapsuleToast.show('试听需设备端语音合成,暂未接入', showCheck: false);
|
||||
}
|
||||
|
||||
void _realtimeTalk() {
|
||||
CapsuleToast.show('实时喊话将在第二阶段开放', showCheck: false);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFEDF6FD),
|
||||
body: Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [Color(0xFFD9EBFA), Color(0xFFEDF6FD)],
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildTopBar(context),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
controller: _scrollCtrl,
|
||||
padding: const EdgeInsets.fromLTRB(16, 4, 16, 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
RobotSummaryCardV2(robot: widget.robot),
|
||||
const SizedBox(height: 18),
|
||||
_buildSectionHeader('预设语音列表'),
|
||||
const SizedBox(height: 10),
|
||||
_buildPresetList(),
|
||||
const SizedBox(height: 18),
|
||||
_buildSectionTitle('编辑语音内容'),
|
||||
const SizedBox(height: 10),
|
||||
_buildEditorCard(),
|
||||
const SizedBox(height: 18),
|
||||
_buildSectionTitle('实时喊话(第二阶段)'),
|
||||
const SizedBox(height: 10),
|
||||
_buildRealtimeCard(),
|
||||
const SizedBox(height: 14),
|
||||
const Center(
|
||||
child: Text(
|
||||
'预设语音保存在本机;语音合成为设备端能力,需设备支持后才会播报',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 10.5, color: _hint),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 顶栏 =====
|
||||
Widget _buildTopBar(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 6, 16, 2),
|
||||
child: Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => Navigator.of(context).pop(),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _navy.withValues(alpha: 0.06),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.arrow_back_ios_new_rounded,
|
||||
color: _blue,
|
||||
size: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Expanded(
|
||||
child: Text(
|
||||
'预设语音管理',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: _todo,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _navy.withValues(alpha: 0.06),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.info_outline_rounded,
|
||||
color: _blue,
|
||||
size: 18,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 分节标题:蓝色竖条 + 标题(可带右侧蓝色操作)=====
|
||||
Widget _buildSectionTitle(String title) {
|
||||
return Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 4,
|
||||
height: 15,
|
||||
decoration: BoxDecoration(
|
||||
color: _blue,
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSectionHeader(String title) {
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(child: _buildSectionTitle(title)),
|
||||
GestureDetector(
|
||||
onTap: _startCreate,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 2, vertical: 4),
|
||||
child: Text(
|
||||
'+ 新增',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: _blue,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 预设语音列表 =====
|
||||
Widget _buildPresetList() {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: _loading
|
||||
? const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 36),
|
||||
child: Center(
|
||||
child: SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: _blue,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
: Column(
|
||||
children: [
|
||||
for (var i = 0; i < _presets.length; i++)
|
||||
Column(
|
||||
children: [
|
||||
_buildPresetRow(_presets[i]),
|
||||
if (i != _presets.length - 1)
|
||||
const Divider(
|
||||
height: 1,
|
||||
thickness: 1,
|
||||
color: _divider,
|
||||
indent: 12,
|
||||
endIndent: 12,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPresetRow(VoicePreset preset) {
|
||||
final selected = _editingId == preset.id;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(12, 10, 12, 10),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: _softBlue,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: const Icon(Icons.volume_up_rounded, size: 21, color: _blue),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
preset.name,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 14.5,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: selected ? _blue : _navy,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
preset.text,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
height: 1.35,
|
||||
color: _gray,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
_buildIconButton(
|
||||
icon: Icons.play_arrow_rounded,
|
||||
bg: _softBlue,
|
||||
color: _blue,
|
||||
onTap: () => _playPreset(preset),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
_buildIconButton(
|
||||
icon: Icons.edit_outlined,
|
||||
bg: _softGray,
|
||||
color: _gray,
|
||||
onTap: () => _editPreset(preset),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildIconButton({
|
||||
required IconData icon,
|
||||
required Color bg,
|
||||
required Color color,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
width: 34,
|
||||
height: 34,
|
||||
decoration: BoxDecoration(
|
||||
color: bg,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Icon(icon, size: 19, color: color),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 编辑语音内容 =====
|
||||
Widget _buildEditorCard() {
|
||||
return Container(
|
||||
key: _editorKey,
|
||||
padding: const EdgeInsets.fromLTRB(14, 14, 14, 14),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const Text('语音名称', style: TextStyle(fontSize: 12.5, color: _gray)),
|
||||
const SizedBox(height: 8),
|
||||
_buildField(
|
||||
controller: _nameCtrl,
|
||||
focusNode: _nameFocus,
|
||||
hint: '如:安全警示',
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
const Text(
|
||||
'语音文字(用户可编辑)',
|
||||
style: TextStyle(fontSize: 12.5, color: _gray),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_buildField(
|
||||
controller: _textCtrl,
|
||||
hint: '输入要播报的文字内容',
|
||||
minLines: 4,
|
||||
maxLines: 6,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
const Text(
|
||||
'语言:中文简体',
|
||||
style: TextStyle(fontSize: 12.5, color: _gray),
|
||||
),
|
||||
const Spacer(),
|
||||
Text(
|
||||
'语音合成/同步需设备支持',
|
||||
style: TextStyle(
|
||||
fontSize: 11.5,
|
||||
color: _hint.withValues(alpha: 0.95),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
GestureDetector(
|
||||
onTap: _savePreset,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
height: 46,
|
||||
decoration: BoxDecoration(
|
||||
color: _blue,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _blue.withValues(alpha: 0.26),
|
||||
blurRadius: 14,
|
||||
offset: const Offset(0, 5),
|
||||
),
|
||||
],
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: const Text(
|
||||
'保存预设语音',
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildField({
|
||||
required TextEditingController controller,
|
||||
FocusNode? focusNode,
|
||||
required String hint,
|
||||
int minLines = 1,
|
||||
int maxLines = 1,
|
||||
}) {
|
||||
return TextField(
|
||||
controller: controller,
|
||||
focusNode: focusNode,
|
||||
minLines: minLines,
|
||||
maxLines: maxLines,
|
||||
textInputAction: maxLines > 1
|
||||
? TextInputAction.newline
|
||||
: TextInputAction.next,
|
||||
style: const TextStyle(fontSize: 14, height: 1.4, color: _navy),
|
||||
cursorColor: _blue,
|
||||
decoration: InputDecoration(
|
||||
isDense: true,
|
||||
filled: true,
|
||||
fillColor: Colors.white,
|
||||
hintText: hint,
|
||||
hintStyle: const TextStyle(fontSize: 14, color: Color(0xFFB9C2CF)),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 14,
|
||||
vertical: 13,
|
||||
),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: const BorderSide(color: _cardBorder),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: const BorderSide(color: _cardBorder),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: const BorderSide(color: _blue, width: 1.2),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 实时喊话(第二阶段)=====
|
||||
Widget _buildRealtimeCard() {
|
||||
return GestureDetector(
|
||||
onTap: _realtimeTalk,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.fromLTRB(12, 14, 12, 14),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _cardBorder),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: _softGray,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: const Icon(Icons.mic_none_rounded, size: 21, color: _gray),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'通过APP麦克风实时喊话',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 14.5,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 4),
|
||||
Text(
|
||||
'通过APP麦克风采集语音,实时下发设备播放',
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(fontSize: 12, height: 1.35, color: _gray),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: _softGray,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: const Text(
|
||||
'待开放',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: _gray,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user