远程遥控相关

This commit is contained in:
2026-11-06 08:34:19 +08:00
parent eb8dec2868
commit d882db7995
42 changed files with 5023 additions and 631 deletions

View File

@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
import 'package:permission_handler/permission_handler.dart';
import '../../../../../core/bluetooth/ble_manager.dart';
import '../../../../../core/localization/app_localizations.dart';
import '../pages/ble_device_detail_page.dart';
class BluetoothScanModal extends StatefulWidget {
@@ -203,15 +204,21 @@ class _BluetoothScanModalState extends State<BluetoothScanModal> {
? currentConnected.platformName
: '${currentConnected.remoteId}';
if (!mounted) return;
final l10n = AppLocalizations.of(context);
showDialog(
context: context,
builder: (ctx) => AlertDialog(
title: const Text('已有设备连接'),
content: Text('当前已连接设备:$connName\n\n请先断开当前设备后再连接新设备。'),
title: Text(l10n.translate('ble_v2.already_connected_title')),
content: Text(
l10n.translate('ble_v2.already_connected_msg').replaceAll(
'%s',
connName,
),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx),
child: const Text('知道了'),
child: Text(l10n.translate('ble_v2.got_it')),
),
],
),
@@ -258,7 +265,14 @@ class _BluetoothScanModalState extends State<BluetoothScanModal> {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
'已连接 ${result.device.platformName.isEmpty ? result.device.remoteId : result.device.platformName}',
AppLocalizations.of(context)
.translate('ble_v2.connected_toast')
.replaceAll(
'%s',
result.device.platformName.isEmpty
? result.device.remoteId.toString()
: result.device.platformName,
),
),
),
);
@@ -339,6 +353,7 @@ class _BluetoothScanModalState extends State<BluetoothScanModal> {
}
Widget _buildHeader(BuildContext context) {
final l10n = AppLocalizations.of(context);
return Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
decoration: const BoxDecoration(
@@ -355,9 +370,9 @@ class _BluetoothScanModalState extends State<BluetoothScanModal> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'蓝牙设备',
style: TextStyle(
Text(
l10n.translate('ble_v2.title'),
style: const TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold,
@@ -366,10 +381,15 @@ class _BluetoothScanModalState extends State<BluetoothScanModal> {
const SizedBox(height: 4),
Text(
_connectedDevice != null
? '当前已连接: ${_connectedDevice!.platformName.isEmpty ? _connectedDevice!.remoteId : _connectedDevice!.platformName}'
? l10n.translate('ble_v2.connected_current').replaceAll(
'%s',
_connectedDevice!.platformName.isEmpty
? _connectedDevice!.remoteId.toString()
: _connectedDevice!.platformName,
)
: _isBluetoothOn
? '正在扫描周边设备...'
: '请先打开蓝牙',
? l10n.translate('ble_v2.scanning_nearby')
: l10n.translate('ble_v2.turn_on_bt_first'),
style: const TextStyle(color: Colors.white70, fontSize: 12),
),
],
@@ -392,6 +412,7 @@ class _BluetoothScanModalState extends State<BluetoothScanModal> {
}
Widget _buildStatusCard() {
final l10n = AppLocalizations.of(context);
final isOn = _isBluetoothOn;
final hasConnected = _connectedDevice != null;
return Container(
@@ -416,7 +437,9 @@ class _BluetoothScanModalState extends State<BluetoothScanModal> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
isOn ? '蓝牙已开启' : '蓝牙未打开',
isOn
? l10n.translate('ble_v2.bt_on')
: l10n.translate('ble_v2.bt_off'),
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
@@ -426,10 +449,10 @@ class _BluetoothScanModalState extends State<BluetoothScanModal> {
const SizedBox(height: 4),
Text(
hasConnected
? '已连接设备'
? l10n.translate('ble_v2.connected_device')
: isOn
? '正在扫描周边设备'
: '请打开蓝牙以扫描附近设备',
? l10n.translate('ble_v2.scanning_nearby_short')
: l10n.translate('ble_v2.turn_on_bt_to_scan'),
style: const TextStyle(
fontSize: 12,
color: Color(0xFF86909C),
@@ -458,9 +481,9 @@ class _BluetoothScanModalState extends State<BluetoothScanModal> {
color: const Color(0xFF165DFF),
borderRadius: BorderRadius.circular(6),
),
child: const Text(
'去打开',
style: TextStyle(
child: Text(
l10n.translate('ble_v2.go_turn_on'),
style: const TextStyle(
color: Colors.white,
fontSize: 13,
fontWeight: FontWeight.w500,
@@ -474,6 +497,7 @@ class _BluetoothScanModalState extends State<BluetoothScanModal> {
}
Widget _buildDeviceList() {
final l10n = AppLocalizations.of(context);
// 过滤掉已连接设备(它已在状态卡片下方单独显示)
var otherResults = _connectedDevice != null
? _scanResults
@@ -494,9 +518,9 @@ class _BluetoothScanModalState extends State<BluetoothScanModal> {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'附近设备',
style: TextStyle(
Text(
l10n.translate('ble_v2.nearby_devices'),
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Color(0xFF1D2129),
@@ -520,15 +544,15 @@ class _BluetoothScanModalState extends State<BluetoothScanModal> {
onChanged: (value) {
setState(() => _searchQuery = value);
},
decoration: const InputDecoration(
hintText: '搜索设备名称或MAC',
hintStyle: TextStyle(
decoration: InputDecoration(
hintText: l10n.translate('ble_v2.search_hint'),
hintStyle: const TextStyle(
fontSize: 13,
color: Color(0xFF86909C),
),
border: InputBorder.none,
isDense: true,
contentPadding: EdgeInsets.symmetric(vertical: 10),
contentPadding: const EdgeInsets.symmetric(vertical: 10),
),
style: const TextStyle(
fontSize: 13,
@@ -551,20 +575,20 @@ class _BluetoothScanModalState extends State<BluetoothScanModal> {
),
),
if (!_isBluetoothOn)
const Padding(
padding: EdgeInsets.symmetric(vertical: 24),
Padding(
padding: const EdgeInsets.symmetric(vertical: 24),
child: Center(
child: Column(
children: [
Icon(
const Icon(
Icons.bluetooth_disabled,
size: 48,
color: Color(0xFF86909C),
),
SizedBox(height: 12),
const SizedBox(height: 12),
Text(
'蓝牙未开启,无法扫描设备',
style: TextStyle(color: Color(0xFF86909C)),
l10n.translate('ble_v2.bt_off_cannot_scan'),
style: const TextStyle(color: Color(0xFF86909C)),
),
],
),
@@ -583,7 +607,9 @@ class _BluetoothScanModalState extends State<BluetoothScanModal> {
),
const SizedBox(height: 12),
Text(
_searchQuery.isNotEmpty ? '未找到匹配的设备' : '正在扫描附近设备...',
_searchQuery.isNotEmpty
? l10n.translate('ble_v2.no_match')
: l10n.translate('ble_v2.scanning_dots'),
style: const TextStyle(color: Color(0xFF86909C)),
),
],
@@ -601,6 +627,7 @@ class _BluetoothScanModalState extends State<BluetoothScanModal> {
/// 已连接设备卡片(始终显示在状态卡片下方,不依赖扫描结果)
Widget _buildConnectedDeviceCard() {
final l10n = AppLocalizations.of(context);
final device = _connectedDevice!;
final name = device.platformName.isNotEmpty
? device.platformName
@@ -663,9 +690,12 @@ class _BluetoothScanModalState extends State<BluetoothScanModal> {
color: const Color(0xFF00B42A),
borderRadius: BorderRadius.circular(4),
),
child: const Text(
'已连接',
style: TextStyle(fontSize: 10, color: Colors.white),
child: Text(
l10n.translate('ble_v2.connected'),
style: const TextStyle(
fontSize: 10,
color: Colors.white,
),
),
),
],
@@ -692,9 +722,9 @@ class _BluetoothScanModalState extends State<BluetoothScanModal> {
color: const Color(0xFF00B42A),
borderRadius: BorderRadius.circular(6),
),
child: const Text(
'断开',
style: TextStyle(
child: Text(
l10n.translate('ble_v2.disconnect'),
style: const TextStyle(
color: Colors.white,
fontSize: 13,
fontWeight: FontWeight.w500,
@@ -709,6 +739,7 @@ class _BluetoothScanModalState extends State<BluetoothScanModal> {
}
Widget _buildDeviceItem(ScanResult result) {
final l10n = AppLocalizations.of(context);
final device = result.device;
final advData = result.advertisementData;
// 优先使用广告数据中的名称(含扫描响应),手机蓝牙列表也是这样显示的
@@ -808,7 +839,9 @@ class _BluetoothScanModalState extends State<BluetoothScanModal> {
),
)
: Text(
isConnected ? '已连接' : '连接',
isConnected
? l10n.translate('ble_v2.connected')
: l10n.translate('ble_v2.connect'),
style: const TextStyle(
color: Colors.white,
fontSize: 13,
@@ -830,14 +863,17 @@ class _BluetoothScanModalState extends State<BluetoothScanModal> {
color: const Color(0xFFFFF7E6),
borderRadius: BorderRadius.circular(8),
),
child: const Row(
child: Row(
children: [
Icon(Icons.info_outline, color: Color(0xFFFF7D00), size: 16),
SizedBox(width: 8),
const Icon(Icons.info_outline, color: Color(0xFFFF7D00), size: 16),
const SizedBox(width: 8),
Expanded(
child: Text(
'请选择现场本机设备,避免连接无关设备',
style: TextStyle(fontSize: 12, color: Color(0xFFFF7D00)),
AppLocalizations.of(context).translate('ble_v2.tip'),
style: const TextStyle(
fontSize: 12,
color: Color(0xFFFF7D00),
),
),
),
],

View File

@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
/// 设备状态 V2 —— 卡片视图设计稿组件。
///
@@ -16,23 +17,36 @@ enum DeviceV2Status { working, online, offline }
class DeviceV2Display {
DeviceV2Display._();
static const _editions = ['PLUS 智能版', 'STD 标准版', 'PRO 旗舰版'];
/// 版本代码:plus / std / pro,文案由调用方取 device_list_v2.edition_<code>
static const _editionCodes = ['plus', 'std', 'pro'];
static int _seed(String key) => key.hashCode & 0x7FFFFFFF;
/// 版本后缀:PLUS 智能版 / STD 标准版 / PRO 旗舰版
static String editionOf(String key) =>
_editions[_seed(key) % _editions.length];
///
/// 列表卡已改用后端 productModel 真值(RobotDataModel.modelLabel),
/// 此处仅详情页/全功能页临时兜底,待这两处也接入机型字段后删除。
static String editionOf(String key, AppLocalizations l10n) {
final code = _editionCodes[_seed(key) % _editionCodes.length];
return l10n.translate('device_list_v2.edition_$code');
}
/// 版本占位:v2.x.y(后端暂无版本字段,集中概览表格用)
static String versionOf(String key) =>
'v2.${_seed(key) % 4}.${_seed(key) ~/ 4 % 10}';
// Deleted:static String versionOf(String key) =>
// Deleted: 'v2.${_seed(key) % 4}.${_seed(key) ~/ 4 % 10}';
static const _locations = ['1号厂房', '2号厂房', '原料区', '综合楼'];
/// 位置代码:plant_1 / plant_2 / raw_material / office_building
static const _locationCodes = [
'plant_1',
'plant_2',
'raw_material',
'office_building',
];
/// 位置占位:后端暂无位置字段,集中概览表格用
static String locationOf(String key) =>
_locations[_seed(key) % _locations.length];
static String locationOf(String key, AppLocalizations l10n) {
final code = _locationCodes[_seed(key) % _locationCodes.length];
return l10n.translate('device_list_v2.location_$code');
}
/// SN 掩码展示:前4 · · · 后2
static String maskedSn(String key) {
@@ -42,11 +56,15 @@ class DeviceV2Display {
}
/// 底部作业态文案
static String workTextOf(DeviceV2Status status) {
static String workTextOf(AppLocalizations l10n, DeviceV2Status status) {
return switch (status) {
DeviceV2Status.working => '自主作业中',
DeviceV2Status.online => '待机',
DeviceV2Status.offline => '暂时无法连接',
DeviceV2Status.working => l10n.translate(
'device_list_v2.work_text_working',
),
DeviceV2Status.online => l10n.translate('device_list_v2.work_text_online'),
DeviceV2Status.offline => l10n.translate(
'device_list_v2.work_text_offline',
),
};
}
}
@@ -102,6 +120,7 @@ class DeviceCardV2 extends StatelessWidget {
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context);
final offline = status == DeviceV2Status.offline;
final battery = offline ? null : batteryLevel;
@@ -147,15 +166,19 @@ class DeviceCardV2 extends StatelessWidget {
),
),
// 编辑(改名):默认未开发,由外部注入(如修改设备名称弹窗)
// 热区撑到 31x31:原来只包 15px 图标,手指经常点不中
GestureDetector(
onTap:
onRename ??
() => CapsuleToast.show(
'功能暂未开发',
l10n.translate(
'device_list_v2.feature_todo',
),
showCheck: false,
),
behavior: HitTestBehavior.opaque,
child: const Padding(
padding: EdgeInsets.symmetric(horizontal: 6),
padding: EdgeInsets.fromLTRB(9, 8, 9, 8),
child: Icon(
Icons.edit_outlined,
size: 15,
@@ -163,7 +186,7 @@ class DeviceCardV2 extends StatelessWidget {
),
),
),
_buildBadge(),
_buildBadge(l10n),
],
),
const SizedBox(height: 6),
@@ -191,7 +214,9 @@ class DeviceCardV2 extends StatelessWidget {
await Clipboard.setData(
ClipboardData(text: snKey),
);
CapsuleToast.show('SN 已复制到剪贴板');
CapsuleToast.show(
l10n.translate('device_list_v2.sn_copied'),
);
},
child: const Padding(
padding: EdgeInsets.symmetric(horizontal: 6),
@@ -213,7 +238,10 @@ class DeviceCardV2 extends StatelessWidget {
GestureDetector(
onTap:
onMore ??
() => CapsuleToast.show('功能暂未开发', showCheck: false),
() => CapsuleToast.show(
l10n.translate('device_list_v2.feature_todo'),
showCheck: false,
),
child: Container(
width: 32,
height: 32,
@@ -251,7 +279,7 @@ class DeviceCardV2 extends StatelessWidget {
),
const SizedBox(width: 6),
Text(
DeviceV2Display.workTextOf(status),
DeviceV2Display.workTextOf(l10n, status),
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w500,
@@ -308,11 +336,23 @@ class DeviceCardV2 extends StatelessWidget {
}
/// 状态徽章:作业中(橙) / 在线(绿) / 离线(灰)
Widget _buildBadge() {
Widget _buildBadge(AppLocalizations l10n) {
final (color, bg, label) = switch (status) {
DeviceV2Status.working => (_workingOrange, _workingBg, '作业中'),
DeviceV2Status.online => (_onlineGreen, _onlineBg, '在线'),
DeviceV2Status.offline => (_offlineGray, _offlineBg, '离线'),
DeviceV2Status.working => (
_workingOrange,
_workingBg,
l10n.translate('device_list_v2.stat_working'),
),
DeviceV2Status.online => (
_onlineGreen,
_onlineBg,
l10n.translate('device_list_v2.online'),
),
DeviceV2Status.offline => (
_offlineGray,
_offlineBg,
l10n.translate('device_list_v2.offline'),
),
};
return Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),

View File

@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
/// 通用设备操作确认弹窗(设计稿:远程开机确认 / 关机确认 / 急停确认等)
///
@@ -21,10 +22,11 @@ Future<bool> showDeviceConfirmDialog(
required String title,
required String message,
String? note,
String confirmText = '确认',
String cancelText = '取消',
String? confirmText,
String? cancelText,
bool danger = false,
}) async {
final l10n = AppLocalizations.of(context);
final result = await showDialog<bool>(
context: context,
barrierColor: const Color(0x8C0B1B2B),
@@ -34,8 +36,9 @@ Future<bool> showDeviceConfirmDialog(
title: title,
message: message,
note: note,
confirmText: confirmText,
cancelText: cancelText,
confirmText:
confirmText ?? l10n.translate('device_list_v2.action_confirm'),
cancelText: cancelText ?? l10n.translate('device_list_v2.action_cancel'),
danger: danger,
);
},

View File

@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import '../../domain/entities/device_entity.dart';
import '../../domain/entities/device_model_info.dart';
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
import 'package:maibu_satabot_v2/core/theme/AppTheme.dart';
@@ -14,6 +15,13 @@ class DeviceItemWidget extends StatelessWidget {
required this.onTap,
});
/// 型号文案:productModel 解析优先(MC700 · PRO 旗舰版),
/// productModel 为 null / 空串时统一显示「未知」
String _modelTextOf(BuildContext context) =>
DeviceModelInfo.parse(device.productModel).labelOf(
AppLocalizations.of(context),
);
@override
Widget build(BuildContext context) {
return GestureDetector(
@@ -64,6 +72,16 @@ class DeviceItemWidget extends StatelessWidget {
color: context.appColors.textTertiary,
),
),
const SizedBox(height: 2),
Text(
_modelTextOf(context),
style: TextStyle(
fontSize: 12,
color: context.appColors.textSecondary,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
),
),