作业首页和机器状态的数据
This commit is contained in:
@@ -1,14 +1,20 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
|
||||
import '../../data/models/robot_data_model.dart';
|
||||
import '../cubit/find_robot_cubit.dart';
|
||||
import '../cubit/find_robot_state.dart';
|
||||
import 'robot_summary_card_v2.dart';
|
||||
|
||||
/// 一键寻车底部弹窗(设计稿:设备控制 → 一键寻车)
|
||||
///
|
||||
/// 多处复用:全部功能中心、设备详情页、控制页都可以直接调用。
|
||||
/// 寻车指令下发通道尚未接入,未注入回调时统一给出明确提示,不假装成功。
|
||||
/// 启动寻车已接入真实接口(GET /iot/host/searchDevice,deviceId=设备编码),
|
||||
/// 走 FindRobotCubit → UseCase → Repository → DataSource;停止/地图入口仍为占位。
|
||||
Future<void> showFindRobotSheet(
|
||||
BuildContext context, {
|
||||
required RobotDataModel robot,
|
||||
@@ -22,12 +28,15 @@ Future<void> showFindRobotSheet(
|
||||
backgroundColor: Colors.transparent,
|
||||
isScrollControlled: true,
|
||||
barrierColor: const Color(0x8C0B1B2B),
|
||||
builder: (_) => _FindRobotSheet(
|
||||
robot: robot,
|
||||
gnssValid: gnssValid ?? robot.isOnline,
|
||||
onOpenMap: onOpenMap,
|
||||
onStartFind: onStartFind,
|
||||
onStopFind: onStopFind,
|
||||
builder: (_) => BlocProvider(
|
||||
create: (_) => GetIt.I<FindRobotCubit>(),
|
||||
child: _FindRobotSheet(
|
||||
robot: robot,
|
||||
gnssValid: gnssValid ?? robot.isOnline,
|
||||
onOpenMap: onOpenMap,
|
||||
onStartFind: onStartFind,
|
||||
onStopFind: onStopFind,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -61,39 +70,81 @@ class _FindRobotSheet extends StatelessWidget {
|
||||
bool get _online => robot.isOnline;
|
||||
|
||||
void _handleStart(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
if (!_online) {
|
||||
CapsuleToast.show('设备离线,无法触发声光寻车', showCheck: false);
|
||||
CapsuleToast.show(
|
||||
l10n.translate('device_list_v2.fr_toast_offline'),
|
||||
showCheck: false,
|
||||
);
|
||||
return;
|
||||
}
|
||||
// 外部显式注入回调时优先使用(保留自定义下发通道的能力)
|
||||
if (onStartFind != null) {
|
||||
onStartFind!();
|
||||
return;
|
||||
}
|
||||
CapsuleToast.show('声光寻车指令下发未接入', showCheck: false);
|
||||
// 一键寻车:deviceId 传设备编码(deviceName,MC700- 开头),
|
||||
// 不是 getSiteList 的数字主键 robot.id;deviceName 异常为空时回退 id 兜底。
|
||||
final deviceCode = robot.name.isNotEmpty ? robot.name : robot.id;
|
||||
context.read<FindRobotCubit>().startFind(deviceCode: deviceCode);
|
||||
}
|
||||
|
||||
void _handleStop() {
|
||||
if (onStopFind != null) {
|
||||
onStopFind!();
|
||||
/// 寻车下发结果:成功/失败均弹提示并复位,避免重复触发
|
||||
void _handleFindState(BuildContext context, FindRobotState state) {
|
||||
if (state.isSubmitting) return;
|
||||
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final cubit = context.read<FindRobotCubit>();
|
||||
|
||||
if (state.isSuccess) {
|
||||
CapsuleToast.show(l10n.translate('device_list_v2.fr_toast_start_sent'));
|
||||
cubit.reset();
|
||||
return;
|
||||
}
|
||||
CapsuleToast.show('停止寻车指令下发未接入', showCheck: false);
|
||||
|
||||
final message = state.errorMessage;
|
||||
if (message == null) return;
|
||||
CapsuleToast.show(
|
||||
message.isEmpty
|
||||
? l10n.translate('device_list_v2.fr_toast_start_failed')
|
||||
: message,
|
||||
showCheck: false,
|
||||
);
|
||||
cubit.reset();
|
||||
}
|
||||
|
||||
// 一键寻车为一次性下发,无「停止」语义,停止按钮已按需求注释掉(方法一并保留注释备恢复)。
|
||||
// void _handleStop(BuildContext context) {
|
||||
// if (onStopFind != null) {
|
||||
// onStopFind!();
|
||||
// return;
|
||||
// }
|
||||
// CapsuleToast.show(
|
||||
// AppLocalizations.of(context).translate('device_list_v2.fr_toast_stop_todo'),
|
||||
// showCheck: false,
|
||||
// );
|
||||
// }
|
||||
|
||||
void _handleOpenMap(BuildContext context) {
|
||||
if (onOpenMap != null) {
|
||||
onOpenMap!();
|
||||
return;
|
||||
}
|
||||
CapsuleToast.show('地图定位入口暂未接入', showCheck: false);
|
||||
CapsuleToast.show(
|
||||
AppLocalizations.of(context).translate('device_list_v2.fr_toast_map_todo'),
|
||||
showCheck: false,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final model = RobotSummaryCardV2.modelOf(robot);
|
||||
return SafeArea(
|
||||
top: false,
|
||||
child: Container(
|
||||
return BlocListener<FindRobotCubit, FindRobotState>(
|
||||
listener: _handleFindState,
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
child: Container(
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(24)),
|
||||
@@ -107,10 +158,10 @@ class _FindRobotSheet extends StatelessWidget {
|
||||
// 标题行
|
||||
Row(
|
||||
children: [
|
||||
const Expanded(
|
||||
Expanded(
|
||||
child: Text(
|
||||
'一键寻车',
|
||||
style: TextStyle(
|
||||
l10n.translate('device_list_v2.fr_title'),
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
@@ -163,7 +214,7 @@ class _FindRobotSheet extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Text(
|
||||
'${gnssValid ? 'GNSS定位有效' : 'GNSS定位无效'} · $model 标准版',
|
||||
'${gnssValid ? l10n.translate('device_list_v2.fr_gnss_valid') : l10n.translate('device_list_v2.fr_gnss_invalid')} · ${l10n.translate('device_list_v2.fr_model_std').replaceAll('%s', model)}',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 12, color: _gray),
|
||||
@@ -181,7 +232,9 @@ class _FindRobotSheet extends StatelessWidget {
|
||||
borderRadius: BorderRadius.circular(9),
|
||||
),
|
||||
child: Text(
|
||||
_online ? '在线' : '离线',
|
||||
_online
|
||||
? l10n.translate('device_list_v2.online')
|
||||
: l10n.translate('device_list_v2.offline'),
|
||||
style: TextStyle(
|
||||
fontSize: 10.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
@@ -219,22 +272,25 @@ class _FindRobotSheet extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Expanded(
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'在地图中查看机器人',
|
||||
style: TextStyle(
|
||||
l10n.translate('device_list_v2.fr_map_entry'),
|
||||
style: const TextStyle(
|
||||
fontSize: 14.5,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 4),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'定位位置与最后更新时间',
|
||||
style: TextStyle(fontSize: 12, color: _gray),
|
||||
l10n.translate('device_list_v2.fr_map_entry_sub'),
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: _gray,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -260,25 +316,32 @@ class _FindRobotSheet extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'声光寻车',
|
||||
style: TextStyle(
|
||||
Text(
|
||||
l10n.translate('device_list_v2.fr_sound_title'),
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
const Text(
|
||||
'触发蜂鸣与指示灯,帮助现场人员找到设备;默认自动停止。',
|
||||
style: TextStyle(fontSize: 12, height: 1.5, color: _gray),
|
||||
Text(
|
||||
l10n.translate('device_list_v2.fr_sound_desc'),
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
height: 1.5,
|
||||
color: _gray,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
const Text(
|
||||
'自动结束',
|
||||
style: TextStyle(fontSize: 12.5, color: _gray),
|
||||
Text(
|
||||
l10n.translate('device_list_v2.fr_auto_stop'),
|
||||
style: const TextStyle(
|
||||
fontSize: 12.5,
|
||||
color: _gray,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
Container(
|
||||
@@ -290,9 +353,9 @@ class _FindRobotSheet extends StatelessWidget {
|
||||
color: _softBlue,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: const Text(
|
||||
'10秒(示例)',
|
||||
style: TextStyle(
|
||||
child: Text(
|
||||
l10n.translate('device_list_v2.fr_auto_stop_value'),
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: _blue,
|
||||
@@ -324,18 +387,18 @@ class _FindRobotSheet extends StatelessWidget {
|
||||
]
|
||||
: null,
|
||||
),
|
||||
child: const Row(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
const Icon(
|
||||
Icons.volume_up_rounded,
|
||||
size: 19,
|
||||
color: Colors.white,
|
||||
),
|
||||
SizedBox(width: 8),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'启动寻车提示',
|
||||
style: TextStyle(
|
||||
l10n.translate('device_list_v2.fr_start'),
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Colors.white,
|
||||
@@ -345,38 +408,43 @@ class _FindRobotSheet extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// 停止寻车
|
||||
GestureDetector(
|
||||
onTap: _handleStop,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
height: 48,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: _blue, width: 1.2),
|
||||
),
|
||||
child: const Text(
|
||||
'停止寻车',
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: _blue,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
// 停止寻车:一次性下发无停止语义,按需求注释掉该按钮。
|
||||
// const SizedBox(height: 10),
|
||||
// GestureDetector(
|
||||
// onTap: () => _handleStop(context),
|
||||
// behavior: HitTestBehavior.opaque,
|
||||
// child: Container(
|
||||
// height: 48,
|
||||
// alignment: Alignment.center,
|
||||
// decoration: BoxDecoration(
|
||||
// color: Colors.white,
|
||||
// borderRadius: BorderRadius.circular(12),
|
||||
// border: Border.all(color: _blue, width: 1.2),
|
||||
// ),
|
||||
// child: Text(
|
||||
// l10n.translate('device_list_v2.fr_stop'),
|
||||
// style: const TextStyle(
|
||||
// fontSize: 15,
|
||||
// fontWeight: FontWeight.w700,
|
||||
// color: _blue,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
const SizedBox(height: 12),
|
||||
const Text(
|
||||
'设备离线时不可触发声光寻车,只能查看最后已知位置。',
|
||||
style: TextStyle(fontSize: 11.5, height: 1.5, color: _hint),
|
||||
Text(
|
||||
l10n.translate('device_list_v2.fr_note'),
|
||||
style: const TextStyle(
|
||||
fontSize: 11.5,
|
||||
height: 1.5,
|
||||
color: _hint,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user