绑定设备+覆盖模式+控制显示bug+在线更新
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import '../../../../../core/consts/http_api_consts.dart';
|
||||
import '../../domain/entities/device_entity.dart';
|
||||
import '../../domain/entities/device_status_entity.dart';
|
||||
@@ -12,6 +13,7 @@ abstract class DeviceRemoteDataSource {
|
||||
int? siteId,
|
||||
String? typeFilter,
|
||||
});
|
||||
Future<List<DeviceDataModel>> getAllDevices();
|
||||
}
|
||||
|
||||
/// 设备远程数据源实现类 - 从真实 API 获取数据
|
||||
@@ -64,6 +66,37 @@ class DeviceRemoteDataSourceImpl implements DeviceRemoteDataSource {
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<DeviceDataModel>> getAllDevices() async {
|
||||
try {
|
||||
final response = await dio.get(
|
||||
HttpApiConsts.getDeviceList,
|
||||
queryParameters: {'pageNum': 1, 'pageSize': 9999},
|
||||
);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('网络请求失败: ${response.statusCode}');
|
||||
}
|
||||
|
||||
final responseData = response.data;
|
||||
if (responseData['code'] != 200) {
|
||||
throw Exception(responseData['msg'] ?? '业务异常');
|
||||
}
|
||||
|
||||
final List<dynamic> rows = responseData['rows'] ?? [];
|
||||
debugPrint(
|
||||
'>>> [DeviceRemoteDataSource] getAllDevices 返回 ${rows.length} 条设备',
|
||||
);
|
||||
for (int i = 0; i < rows.length && i < 10; i++) {
|
||||
debugPrint('>>> [DeviceRemoteDataSource] rows[$i]: ${rows[i]}');
|
||||
}
|
||||
return rows.map((item) => _parseDeviceFromJson(item)).toList();
|
||||
} catch (e) {
|
||||
debugPrint('>>> [DeviceRemoteDataSource] getAllDevices error: $e');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<DeviceDataModel>> _fetchDevicesFromAPI(int siteId) async {
|
||||
final response = await dio.get(
|
||||
HttpApiConsts.getSiteDeviceList,
|
||||
@@ -107,10 +140,19 @@ class DeviceRemoteDataSourceImpl implements DeviceRemoteDataSource {
|
||||
DeviceDataModel _parseDeviceFromJson(Map<String, dynamic> json) {
|
||||
// 在线状态:使用 onlineStatus 字段(1=在线, 0=离线)
|
||||
final onlineStatus = json['onlineStatus'] ?? 0;
|
||||
final deviceId = json['deviceId']?.toString() ?? '';
|
||||
final name = json['deviceName'] ?? json['name'] ?? '';
|
||||
final type = json['deviceTypeName'] ?? json['type'] ?? '未知设备';
|
||||
final isRobot = _isRobotDevice(type, name, deviceId);
|
||||
|
||||
debugPrint(
|
||||
'🔍 [DeviceListDataSource] deviceId=$deviceId name=$name type=$type isRobot=$isRobot',
|
||||
);
|
||||
|
||||
return DeviceDataModel(
|
||||
deviceId: json['deviceId']?.toString() ?? '',
|
||||
name: json['deviceName'] ?? json['name'] ?? '',
|
||||
type: json['deviceTypeName'] ?? json['type'] ?? '未知设备',
|
||||
deviceId: deviceId,
|
||||
name: name,
|
||||
type: type,
|
||||
status: onlineStatus == 1 ? '在线' : '离线',
|
||||
power: (json['power'] as num?)?.toDouble() ?? 0,
|
||||
todayEnergy: (json['todayEnergy'] as num?)?.toDouble() ?? 0,
|
||||
@@ -118,6 +160,7 @@ class DeviceRemoteDataSourceImpl implements DeviceRemoteDataSource {
|
||||
current: (json['current'] as num?)?.toDouble(),
|
||||
voltage: (json['voltage'] as num?)?.toDouble(),
|
||||
radiation: (json['radiation'] as num?)?.toDouble(),
|
||||
isRobot: isRobot,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -131,9 +174,32 @@ class DeviceRemoteDataSourceImpl implements DeviceRemoteDataSource {
|
||||
power: (json['capacity_percent'] as num?)?.toDouble() ?? 0,
|
||||
todayEnergy: 0,
|
||||
temperature: (json['environment_temperature'] as num?)?.toDouble(),
|
||||
isRobot: false,
|
||||
);
|
||||
}
|
||||
|
||||
/// 🔥 通用判断:是否机器人(型号前缀 + 中文关键字双重匹配,新型号也能自动识别)
|
||||
bool _isRobotDevice(String type, String name, String deviceId) {
|
||||
final haystacks = [
|
||||
type.toLowerCase(),
|
||||
name.toLowerCase(),
|
||||
deviceId.toLowerCase(),
|
||||
];
|
||||
// 型号家族前缀(MC700/MC700STD/MC700PLUS/MC700AIR/MC700PRO 等;RCHWD/RCHETD 等)
|
||||
const prefixes = ['mc', 'rch', 'rcetd', 'rchetd'];
|
||||
// 中文类型关键字
|
||||
const keywords = ['除草', '巡检', '清洗', '割草', '机器人'];
|
||||
for (final s in haystacks) {
|
||||
for (final p in prefixes) {
|
||||
if (s.startsWith(p)) return true;
|
||||
}
|
||||
}
|
||||
for (final k in keywords) {
|
||||
if (type.contains(k) || name.contains(k)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
String _getStatusText(int status) {
|
||||
switch (status) {
|
||||
case 1:
|
||||
|
||||
@@ -12,6 +12,7 @@ class DeviceDataModel {
|
||||
final double? current;
|
||||
final double? voltage;
|
||||
final double? radiation;
|
||||
final bool isRobot;
|
||||
|
||||
const DeviceDataModel({
|
||||
required this.deviceId,
|
||||
@@ -24,6 +25,7 @@ class DeviceDataModel {
|
||||
this.current,
|
||||
this.voltage,
|
||||
this.radiation,
|
||||
this.isRobot = false,
|
||||
});
|
||||
|
||||
/// 从 JSON 创建数据模型
|
||||
@@ -71,6 +73,7 @@ class DeviceDataModel {
|
||||
current: current,
|
||||
voltage: voltage,
|
||||
radiation: radiation,
|
||||
isRobot: isRobot,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,4 +20,10 @@ class DeviceRepositoryImpl implements DeviceRepository {
|
||||
final dataModels = await remoteDataSource.getDeviceList(siteId: siteId, typeFilter: typeFilter);
|
||||
return dataModels.map((model) => model.toEntity()).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<DeviceEntity>> getAllDevices() async {
|
||||
final dataModels = await remoteDataSource.getAllDevices();
|
||||
return dataModels.map((model) => model.toEntity()).toList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ class DeviceEntity {
|
||||
final double? current;
|
||||
final double? voltage;
|
||||
final double? radiation;
|
||||
final bool isRobot;
|
||||
|
||||
const DeviceEntity({
|
||||
required this.deviceId,
|
||||
@@ -22,5 +23,6 @@ class DeviceEntity {
|
||||
this.current,
|
||||
this.voltage,
|
||||
this.radiation,
|
||||
this.isRobot = false,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5,4 +5,5 @@ import '../entities/device_status_entity.dart';
|
||||
abstract class DeviceRepository {
|
||||
Future<DeviceStatusEntity> getDeviceStatus();
|
||||
Future<List<DeviceEntity>> getDeviceList({int? siteId, String? typeFilter});
|
||||
Future<List<DeviceEntity>> getAllDevices();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import '../entities/device_entity.dart';
|
||||
import '../repositories/device_repository.dart';
|
||||
|
||||
/// 获取全部设备列表用例(用于蓝牙绑定匹配)
|
||||
class GetAllDevicesUseCase {
|
||||
final DeviceRepository repository;
|
||||
|
||||
const GetAllDevicesUseCase({required this.repository});
|
||||
|
||||
Future<List<DeviceEntity>> execute() async {
|
||||
return await repository.getAllDevices();
|
||||
}
|
||||
}
|
||||
@@ -10,15 +10,15 @@ class FloatBarSettingService {
|
||||
/// 🔥 静态实例引用
|
||||
static FloatBarSettingService? _instance;
|
||||
|
||||
/// 🔥 静态状态变量 - 所有组件共享
|
||||
static bool _isEnabled = true;
|
||||
/// 🔥 静态状态变量 - 所有组件共享(默认关闭)
|
||||
static bool _isEnabled = false;
|
||||
|
||||
/// 🔥 静态 ValueNotifier - 用于通知UI变化
|
||||
static final ValueNotifier<bool> _settingNotifier = ValueNotifier<bool>(true);
|
||||
/// 🔥 静态 ValueNotifier - 用于通知UI变化(默认关闭)
|
||||
static final ValueNotifier<bool> _settingNotifier = ValueNotifier<bool>(false);
|
||||
|
||||
FloatBarSettingService(this._prefs) {
|
||||
_instance = this;
|
||||
_isEnabled = _prefs.getBool(_key) ?? true;
|
||||
_isEnabled = _prefs.getBool(_key) ?? false;
|
||||
_settingNotifier.value = _isEnabled;
|
||||
debugPrint('✅ [FloatBarSettingService] 初始化完成,初始状态: $_isEnabled');
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import '../../../../../../core/network/mqtt/data/datasources/drone_osd_datasourc
|
||||
enum SimulationMode {
|
||||
circle, // 圆形路径
|
||||
polygon, // 多边形路径(六边形)
|
||||
bow, // 弓字形路径(Zigzag)
|
||||
bow, // 覆盖模式路径(Coverage)
|
||||
rectangle, // 矩形路径
|
||||
}
|
||||
|
||||
@@ -524,7 +524,7 @@ class FloatBarWidgetState extends State<FloatBarWidget> {
|
||||
return path;
|
||||
}
|
||||
|
||||
/// 生成弓字形路径(Zigzag)
|
||||
/// 生成覆盖模式路径(Coverage)
|
||||
List<LatLng> _generateBowPath(double centerLat, double centerLng, int points) {
|
||||
final List<LatLng> path = [];
|
||||
const double width = 0.004; // 宽度约400米
|
||||
@@ -544,7 +544,7 @@ class FloatBarWidgetState extends State<FloatBarWidget> {
|
||||
}
|
||||
}
|
||||
|
||||
debugPrint('〰️ 生成弓字形路径: ${path.length}个点, $rows行');
|
||||
debugPrint('〰️ 生成覆盖模式路径: ${path.length}个点, $rows行');
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:maibu_satabot_v2/core/theme/AppTheme.dart';
|
||||
import 'dart:developer' as developer;
|
||||
import 'dart:typed_data';
|
||||
@@ -11,6 +12,9 @@ import '../../../../../core/bluetooth/protocol_parser.dart';
|
||||
import '../../../../../core/protocol/machine_protocol_constants.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import '../../../../../core/services/device_permission_service.dart';
|
||||
import '../../domain/entities/device_entity.dart';
|
||||
import '../../domain/usecases/get_all_devices_usecase.dart';
|
||||
import 'bind_device_page.dart';
|
||||
|
||||
class BleDeviceDetailPage extends StatefulWidget {
|
||||
final BluetoothDevice device;
|
||||
@@ -34,6 +38,7 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
StreamSubscription<BluetoothDevice?>? _connectingSubscription;
|
||||
StreamSubscription<BlePacket>? _packetSubscription;
|
||||
final List<_ReceivedPacket> _receivedPackets = [];
|
||||
|
||||
/// 按命令类型分组的最新推送:command → 最新数据
|
||||
final Map<int, _ReceivedPacket> _latestPushByCommand = {};
|
||||
bool _pushExpanded = false; // 数据推送默认折叠
|
||||
@@ -44,6 +49,7 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
|
||||
/// 等待设备返回 0x06 写配置应答
|
||||
Completer<bool>? _writeRespCompleter;
|
||||
|
||||
/// 等待回读 0x05 应答,携带期望字段值用于对比
|
||||
Completer<Uint8List?>? _readbackCompleter;
|
||||
Map<String, String>? _expectedFieldValues;
|
||||
@@ -247,6 +253,107 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
await BleManager.instance.disconnect();
|
||||
}
|
||||
|
||||
/// 获取当前蓝牙设备的显示名称
|
||||
String get _bleDeviceName {
|
||||
final advData = widget.scanResult?.advertisementData;
|
||||
return _resolvedName ??
|
||||
(advData?.advName.isNotEmpty == true
|
||||
? advData!.advName
|
||||
: (widget.device.platformName.isNotEmpty
|
||||
? widget.device.platformName
|
||||
: (advData?.localName?.isNotEmpty == true
|
||||
? advData!.localName!
|
||||
: (widget.device.advName.isNotEmpty
|
||||
? widget.device.advName
|
||||
: ''))));
|
||||
}
|
||||
|
||||
/// 绑定设备:调接口获取设备列表,用蓝牙名(时间戳)匹配后跳转绑定页
|
||||
Future<void> _bindDevice() async {
|
||||
final bleName = _bleDeviceName;
|
||||
if (bleName.isEmpty) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('无法获取蓝牙设备名称')));
|
||||
return;
|
||||
}
|
||||
|
||||
// 显示 loading
|
||||
BuildContext? loadingCtx;
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (ctx) {
|
||||
loadingCtx = ctx;
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
},
|
||||
);
|
||||
|
||||
try {
|
||||
final getAllDevicesUseCase = GetIt.instance<GetAllDevicesUseCase>();
|
||||
final devices = await getAllDevicesUseCase.execute();
|
||||
|
||||
if (loadingCtx != null && Navigator.canPop(loadingCtx!)) {
|
||||
Navigator.pop(loadingCtx!);
|
||||
}
|
||||
|
||||
debugPrint(
|
||||
'>>> [BindDevice] bleName=$bleName, devices=${devices.length}',
|
||||
);
|
||||
for (int i = 0; i < devices.length && i < 10; i++) {
|
||||
debugPrint(
|
||||
'>>> [BindDevice] device[$i]: id=${devices[i].deviceId}, name=${devices[i].name}',
|
||||
);
|
||||
}
|
||||
|
||||
// 用蓝牙名(时间戳)匹配设备名中包含该时间戳的设备
|
||||
DeviceEntity? matchedDevice;
|
||||
for (final device in devices) {
|
||||
if (device.name.contains(bleName)) {
|
||||
matchedDevice = device;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (matchedDevice == null) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text('未找到名称包含「$bleName」的设备')));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (matchedDevice.deviceId.isEmpty) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('匹配到的设备缺少设备ID')));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mounted) return;
|
||||
// 复用扫一扫的绑定页面流程
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => BindDevicePage(scanResult: matchedDevice!.deviceId),
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
if (loadingCtx != null && Navigator.canPop(loadingCtx!)) {
|
||||
Navigator.pop(loadingCtx!);
|
||||
}
|
||||
debugPrint('>>> [BindDevice] error: $e');
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text('绑定设备失败: $e')));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_connSubscription?.cancel();
|
||||
@@ -348,8 +455,8 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
final hex = payload.isEmpty
|
||||
? ''
|
||||
: payload
|
||||
.map((b) => b.toRadixString(16).toUpperCase().padLeft(2, '0'))
|
||||
.join(' ');
|
||||
.map((b) => b.toRadixString(16).toUpperCase().padLeft(2, '0'))
|
||||
.join(' ');
|
||||
setState(() {
|
||||
_receivedPackets.insert(
|
||||
0,
|
||||
@@ -372,7 +479,6 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
await _sendAndLog(MachineProtocolConstants.cmdReadConfig, []);
|
||||
}
|
||||
|
||||
|
||||
String _bytesToHex(List<int> bytes) {
|
||||
if (bytes.isEmpty) return '';
|
||||
return bytes
|
||||
@@ -382,16 +488,26 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
|
||||
String _commandName(int command) {
|
||||
switch (command) {
|
||||
case MachineProtocolConstants.cmdRemoteControl: return '远程遥控';
|
||||
case MachineProtocolConstants.cmdPathPlanning: return '路径规划';
|
||||
case MachineProtocolConstants.cmdStatusInfo: return '状态信息';
|
||||
case MachineProtocolConstants.cmdGetId: return '查询ID';
|
||||
case MachineProtocolConstants.cmdGetAuth: return '获取授权';
|
||||
case MachineProtocolConstants.cmdReadConfig: return '读配置';
|
||||
case MachineProtocolConstants.cmdWriteConfig: return '写配置';
|
||||
case MachineProtocolConstants.cmdObstacleAvoid: return '避障';
|
||||
case MachineProtocolConstants.cmdHeartbeat: return '心跳包';
|
||||
default: return '未知(0x${command.toRadixString(16).toUpperCase().padLeft(2, '0')})';
|
||||
case MachineProtocolConstants.cmdRemoteControl:
|
||||
return '远程遥控';
|
||||
case MachineProtocolConstants.cmdPathPlanning:
|
||||
return '路径规划';
|
||||
case MachineProtocolConstants.cmdStatusInfo:
|
||||
return '状态信息';
|
||||
case MachineProtocolConstants.cmdGetId:
|
||||
return '查询ID';
|
||||
case MachineProtocolConstants.cmdGetAuth:
|
||||
return '获取授权';
|
||||
case MachineProtocolConstants.cmdReadConfig:
|
||||
return '读配置';
|
||||
case MachineProtocolConstants.cmdWriteConfig:
|
||||
return '写配置';
|
||||
case MachineProtocolConstants.cmdObstacleAvoid:
|
||||
return '避障';
|
||||
case MachineProtocolConstants.cmdHeartbeat:
|
||||
return '心跳包';
|
||||
default:
|
||||
return '未知(0x${command.toRadixString(16).toUpperCase().padLeft(2, '0')})';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -586,13 +702,19 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
width: 80,
|
||||
child: Text(
|
||||
label,
|
||||
style: TextStyle(fontSize: 13, color: context.appColors.textTertiary),
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: context.appColors.textTertiary,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
value,
|
||||
style: TextStyle(fontSize: 13, color: context.appColors.textPrimary),
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: context.appColors.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -626,33 +748,66 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: _isConnecting
|
||||
? null
|
||||
: (_isConnected ? _disconnect : _connect),
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
backgroundColor: _isConnected
|
||||
? context.appColors.danger
|
||||
: context.appColors.primary,
|
||||
foregroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
Row(
|
||||
children: [
|
||||
// 连接/断开 按钮
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
onPressed: _isConnecting
|
||||
? null
|
||||
: (_isConnected ? _disconnect : _connect),
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
backgroundColor: _isConnected
|
||||
? context.appColors.danger
|
||||
: context.appColors.primary,
|
||||
foregroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: _isConnecting
|
||||
? Text(
|
||||
'连接中 ${_connectingCountdown}s',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
)
|
||||
: Text(_isConnected ? '断开连接' : '连接设备'),
|
||||
),
|
||||
),
|
||||
child: _isConnecting
|
||||
? Text(
|
||||
'连接中 ${_connectingCountdown}s',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
)
|
||||
: Text(_isConnected ? '断开连接' : '连接设备'),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
// 绑定设备 按钮(未连接时灰色禁用)
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
onPressed: _isConnected ? _bindDevice : null,
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
backgroundColor: _isConnected
|
||||
? context.appColors.primary
|
||||
: context.appColors.fillBackground,
|
||||
foregroundColor: _isConnected
|
||||
? Colors.white
|
||||
: context.appColors.textTertiary,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
'绑定设备',
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: _isConnected
|
||||
? Colors.white
|
||||
: context.appColors.textTertiary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -785,7 +940,10 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
),
|
||||
child: Text(
|
||||
p,
|
||||
style: TextStyle(fontSize: 10, color: context.appColors.primary),
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
color: context.appColors.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
@@ -871,14 +1029,21 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
if (pushes.isNotEmpty) ...[
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 6,
|
||||
vertical: 2,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: context.appColors.primary,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Text(
|
||||
'${pushes.length}',
|
||||
style: const TextStyle(fontSize: 11, color: Colors.white, fontWeight: FontWeight.w600),
|
||||
style: const TextStyle(
|
||||
fontSize: 11,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -894,7 +1059,10 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
},
|
||||
child: Text(
|
||||
'清空',
|
||||
style: TextStyle(fontSize: 13, color: context.appColors.primary),
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: context.appColors.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -906,16 +1074,23 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
child: Center(
|
||||
child: Text(
|
||||
'等待接收数据...',
|
||||
style: TextStyle(fontSize: 13, color: context.appColors.textTertiary),
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: context.appColors.textTertiary,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
Column(
|
||||
children: pushes.map((p) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: _buildPushCard(p),
|
||||
)).toList(),
|
||||
children: pushes
|
||||
.map(
|
||||
(p) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: _buildPushCard(p),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -970,35 +1145,46 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
'${p.time.hour.toString().padLeft(2, '0')}:'
|
||||
'${p.time.minute.toString().padLeft(2, '0')}:'
|
||||
'${p.time.second.toString().padLeft(2, '0')}',
|
||||
style: TextStyle(fontSize: 11, color: context.appColors.textTertiary),
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: context.appColors.textTertiary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (hasParsed) ...[
|
||||
const SizedBox(height: 8),
|
||||
...p.parsedFields!.map((f) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 2),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 68,
|
||||
child: Text(
|
||||
f.label,
|
||||
style: TextStyle(fontSize: 11, color: context.appColors.textTertiary),
|
||||
...p.parsedFields!.map(
|
||||
(f) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 2),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 68,
|
||||
child: Text(
|
||||
f.label,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: context.appColors.textTertiary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
f.value,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(fontSize: 11, color: context.appColors.textPrimary),
|
||||
Expanded(
|
||||
child: Text(
|
||||
f.value,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: context.appColors.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
)),
|
||||
),
|
||||
] else if (p.hex.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
@@ -1019,12 +1205,7 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
}
|
||||
|
||||
/// 可编辑的字段白名单:仅这四个增益属性可修改
|
||||
static const _editableFields = {
|
||||
'左轮前进增益',
|
||||
'左轮后退增益',
|
||||
'右轮前进增益',
|
||||
'右轮后退增益',
|
||||
};
|
||||
static const _editableFields = {'左轮前进增益', '左轮后退增益', '右轮前进增益', '右轮后退增益'};
|
||||
|
||||
bool _isEditableField(String label) => _editableFields.contains(label);
|
||||
|
||||
@@ -1156,7 +1337,9 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
),
|
||||
TextSpan(
|
||||
text: ' | ',
|
||||
style: TextStyle(color: context.appColors.divider),
|
||||
style: TextStyle(
|
||||
color: context.appColors.divider,
|
||||
),
|
||||
),
|
||||
TextSpan(
|
||||
text: mod.newValue,
|
||||
@@ -1219,7 +1402,10 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
hintText: '输入新值',
|
||||
border: const OutlineInputBorder(),
|
||||
suffixText: '当前: $currentValue',
|
||||
suffixStyle: TextStyle(fontSize: 11, color: context.appColors.textTertiary),
|
||||
suffixStyle: TextStyle(
|
||||
fontSize: 11,
|
||||
color: context.appColors.textTertiary,
|
||||
),
|
||||
errorText: errorText,
|
||||
),
|
||||
),
|
||||
@@ -1236,7 +1422,9 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
Navigator.pop(ctx);
|
||||
return;
|
||||
}
|
||||
final pkt = _latestPushByCommand[MachineProtocolConstants.cmdReadConfig];
|
||||
final pkt =
|
||||
_latestPushByCommand[MachineProtocolConstants
|
||||
.cmdReadConfig];
|
||||
final entity = pkt?.configEntity;
|
||||
if (entity == null) {
|
||||
Navigator.pop(ctx);
|
||||
@@ -1269,7 +1457,8 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
|
||||
try {
|
||||
// 🔐 前置权限校验:使用读配置(0x05)中的芯片序列号(chipUid)作为设备ID
|
||||
final readConfigPacket = _latestPushByCommand[MachineProtocolConstants.cmdReadConfig];
|
||||
final readConfigPacket =
|
||||
_latestPushByCommand[MachineProtocolConstants.cmdReadConfig];
|
||||
final chipUid = readConfigPacket?.configEntity?.chipUid ?? '';
|
||||
if (chipUid.isEmpty) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
@@ -1305,7 +1494,11 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
builder: (dialogCtx) => AlertDialog(
|
||||
title: Row(
|
||||
children: [
|
||||
Icon(Icons.check_circle, color: context.appColors.success, size: 28),
|
||||
Icon(
|
||||
Icons.check_circle,
|
||||
color: context.appColors.success,
|
||||
size: 28,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const Text('权限通过'),
|
||||
],
|
||||
@@ -1343,7 +1536,10 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
|
||||
// 2. 发送 0x06 并等待设备应答
|
||||
_writeRespCompleter = Completer<bool>();
|
||||
developer.log('[WriteConfig] ⏳ 发送 0x06, 等待应答...', name: 'BleDeviceDetail');
|
||||
developer.log(
|
||||
'[WriteConfig] ⏳ 发送 0x06, 等待应答...',
|
||||
name: 'BleDeviceDetail',
|
||||
);
|
||||
await BleManager.instance.sendCommand(
|
||||
MachineProtocolConstants.cmdWriteConfig,
|
||||
configBytes.toList(),
|
||||
@@ -1363,7 +1559,9 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
if (!mounted) return;
|
||||
|
||||
// 3. 记录期望值,自动回读对比(无论是否收到显式确认都回读)
|
||||
_expectedFieldValues = Map<String, String>.from(p.configEntity!.toFieldMap());
|
||||
_expectedFieldValues = Map<String, String>.from(
|
||||
p.configEntity!.toFieldMap(),
|
||||
);
|
||||
|
||||
// 4. 自动回读配置
|
||||
_readbackCompleter = Completer<Uint8List?>();
|
||||
@@ -1430,14 +1628,13 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
rawPayload: readbackPayload,
|
||||
configEntity: newEntity,
|
||||
);
|
||||
_latestPushByCommand[MachineProtocolConstants.cmdReadConfig] = updatedEntry;
|
||||
_latestPushByCommand[MachineProtocolConstants.cmdReadConfig] =
|
||||
updatedEntry;
|
||||
});
|
||||
}
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
'校验不一致: ${mismatched.join('、')},已恢复为设备实际值',
|
||||
),
|
||||
content: Text('校验不一致: ${mismatched.join('、')},已恢复为设备实际值'),
|
||||
backgroundColor: context.appColors.warning,
|
||||
duration: const Duration(seconds: 3),
|
||||
),
|
||||
@@ -1462,7 +1659,8 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
rawPayload: readbackPayload,
|
||||
configEntity: newEntity,
|
||||
);
|
||||
_latestPushByCommand[MachineProtocolConstants.cmdReadConfig] = updatedEntry;
|
||||
_latestPushByCommand[MachineProtocolConstants.cmdReadConfig] =
|
||||
updatedEntry;
|
||||
_configModifications = {};
|
||||
});
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
|
||||
@@ -119,15 +119,29 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
|
||||
}
|
||||
}
|
||||
|
||||
/// 🔥 机器人设备名称前缀,用于从通用设备列表中过滤掉机器人
|
||||
static const _robotPrefixes = [
|
||||
'RCHETD-CN',
|
||||
'MC700PLUS-CN',
|
||||
'MC700-CN',
|
||||
'MC700PRO-CN',
|
||||
'RCETD-CN',
|
||||
'MC700AIR-CN',
|
||||
];
|
||||
/// 🔥 机器人型号家族前缀(小写,startsWith 匹配,覆盖 MC700/MC700STD/MC700PLUS/MCAIR/RCHWD/RCHETD 等全系列)
|
||||
static const _robotPrefixes = ['mc', 'rch', 'rcetd', 'rchetd'];
|
||||
|
||||
/// 🔥 机器人类型中文名关键字(接口 deviceTypeName 可能是纯中文)
|
||||
static const _robotTypeKeywords = ['除草', '巡检', '清洗', '割草', '机器人'];
|
||||
|
||||
/// 🔥 通用判断:是否机器人(型号前缀 + 中文关键字双重匹配,新型号也能自动识别)
|
||||
static bool _isRobotDevice(String type, String name, String deviceId) {
|
||||
final haystacks = [
|
||||
type.toLowerCase(),
|
||||
name.toLowerCase(),
|
||||
deviceId.toLowerCase(),
|
||||
];
|
||||
for (final s in haystacks) {
|
||||
for (final p in _robotPrefixes) {
|
||||
if (s.startsWith(p)) return true;
|
||||
}
|
||||
}
|
||||
for (final k in _robotTypeKeywords) {
|
||||
if (type.contains(k) || name.contains(k)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -186,7 +200,11 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
|
||||
children: [
|
||||
const Flexible(child: SiteSelectorWidget(compact: true)),
|
||||
const SizedBox(width: 8),
|
||||
Container(width: 1, height: 20, color: context.appColors.divider),
|
||||
Container(
|
||||
width: 1,
|
||||
height: 20,
|
||||
color: context.appColors.divider,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
AppLocalizations.of(
|
||||
@@ -310,7 +328,10 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
|
||||
vertical: 12,
|
||||
),
|
||||
),
|
||||
style: TextStyle(fontSize: 14, color: context.appColors.textPrimary),
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: context.appColors.textPrimary,
|
||||
),
|
||||
onSubmitted: (value) {
|
||||
context.read<DeviceListBloc.DeviceStatusBloc>().add(
|
||||
DeviceListEvent.DeviceStatusSearch(value),
|
||||
@@ -490,13 +511,16 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
|
||||
} else {
|
||||
// 🔥 "全部"模式下,排除已由专用组件渲染的类型,避免重复展示
|
||||
// drone_station 已通过 _buildDroneStationList 渲染
|
||||
// 机器人(通过名称前缀识别)已通过 _buildEmbeddedRobotList 渲染
|
||||
// 机器人通过下面的 _isRobotDevice 通用匹配识别,已由 _buildEmbeddedRobotList 渲染
|
||||
filteredByType = state.devices.where((device) {
|
||||
if (device.type == 'drone_station') return false;
|
||||
final isRobot = _robotPrefixes.any(
|
||||
(prefix) =>
|
||||
device.name.startsWith(prefix) ||
|
||||
device.deviceId.startsWith(prefix),
|
||||
final isRobot = _isRobotDevice(
|
||||
device.type,
|
||||
device.name,
|
||||
device.deviceId,
|
||||
);
|
||||
debugPrint(
|
||||
'🔍 [全部-过滤] deviceId=${device.deviceId} type=${device.type} name=${device.name} → isRobot=$isRobot ${isRobot ? '✅排除' : ''}',
|
||||
);
|
||||
return !isRobot;
|
||||
}).toList();
|
||||
@@ -722,7 +746,9 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
|
||||
builder: (context, state) {
|
||||
if (state is DroneStationLoading) {
|
||||
return Center(
|
||||
child: CircularProgressIndicator(color: context.appColors.primary),
|
||||
child: CircularProgressIndicator(
|
||||
color: context.appColors.primary,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1042,9 +1068,8 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
|
||||
debugPrint('🔍 [DeviceStatusPage] 设备ID: $deviceId');
|
||||
debugPrint('🔍 [DeviceStatusPage] 设备类型: $deviceType');
|
||||
|
||||
// 🔥 判断是否为机器人(根据设备类型前缀)
|
||||
final robotPrefixes = _robotPrefixes;
|
||||
bool isRobot = robotPrefixes.any((prefix) => deviceType.startsWith(prefix));
|
||||
// 🔥 判断是否为机器人:用通用匹配(型号前缀 + 中文关键字)
|
||||
bool isRobot = _isRobotDevice(deviceType, deviceName, deviceId);
|
||||
|
||||
// 🔥 判断是否为无人机机场(根据设备类型包含关键字)
|
||||
final droneStationKeywords = [
|
||||
@@ -1065,22 +1090,8 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
|
||||
(deviceType.isEmpty || deviceType == '未知设备' || deviceType == '未知类型')) {
|
||||
debugPrint('⚠️ [DeviceStatusPage] type 字段无效,使用设备名称进行二次判断');
|
||||
|
||||
// 检查每个机器人前缀是否匹配
|
||||
for (final prefix in robotPrefixes) {
|
||||
final nameMatch = deviceName.startsWith(prefix);
|
||||
final idMatch = deviceId.startsWith(prefix);
|
||||
if (nameMatch || idMatch) {
|
||||
debugPrint(
|
||||
'🔍 [DeviceStatusPage] 机器人前缀匹配: "$prefix" -> 名称匹配=$nameMatch, ID匹配=$idMatch',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 根据设备名称前缀判断机器人
|
||||
isRobot = robotPrefixes.any(
|
||||
(prefix) =>
|
||||
deviceName.startsWith(prefix) || deviceId.startsWith(prefix),
|
||||
);
|
||||
// 根据通用匹配重新判断(已统一用 lowercase)
|
||||
isRobot = _isRobotDevice(deviceType, deviceName, deviceId);
|
||||
|
||||
// 检查每个无人机关键字是否匹配
|
||||
for (final keyword in droneStationKeywords) {
|
||||
|
||||
@@ -1460,7 +1460,7 @@ class _DroneVideoControlPageState extends State<DroneVideoControlPage> {
|
||||
try {
|
||||
final dio = DioClient.create();
|
||||
final response = await dio.post(
|
||||
'http://1.95.137.212:59003/iot/UAV/flightTaskCommand',
|
||||
'${HttpApiConsts.baseUrl}/iot/UAV/flightTaskCommand',
|
||||
data: {'command': command, 'deviceSn': widget.droneSn},
|
||||
);
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ class _BluetoothScanModalState extends State<BluetoothScanModal> {
|
||||
int _connectingCountdown = 15;
|
||||
Timer? _connectingTimer;
|
||||
bool _isStartingScan = false;
|
||||
String _searchQuery = '';
|
||||
|
||||
StreamSubscription<BluetoothAdapterState>? _stateSubscription;
|
||||
StreamSubscription<List<ScanResult>>? _scanSubscription;
|
||||
@@ -123,7 +124,7 @@ class _BluetoothScanModalState extends State<BluetoothScanModal> {
|
||||
await BleManager.instance.openBluetooth();
|
||||
}
|
||||
|
||||
/// 排序:已连接设备排第一,有名称设备优先
|
||||
/// 排序:已连接设备排第一,纯数字名称(时间戳样式)置顶,有名称设备优先
|
||||
List<ScanResult> _sortResults(List<ScanResult> results) {
|
||||
final mgrConnected = BleManager.instance.connectedDevice;
|
||||
final sorted = List<ScanResult>.from(results);
|
||||
@@ -133,7 +134,12 @@ class _BluetoothScanModalState extends State<BluetoothScanModal> {
|
||||
final bConnected = b.device.remoteId == mgrConnected?.remoteId;
|
||||
if (aConnected && !bConnected) return -1;
|
||||
if (!aConnected && bConnected) return 1;
|
||||
// 第二级:有名称的排前面
|
||||
// 第二级:纯数字名称(时间戳样式,如 17xxxx)排前面
|
||||
final aIsNumeric = _isNumericName(a);
|
||||
final bIsNumeric = _isNumericName(b);
|
||||
if (aIsNumeric && !bIsNumeric) return -1;
|
||||
if (!aIsNumeric && bIsNumeric) return 1;
|
||||
// 第三级:有名称的排前面
|
||||
final aHasName = _hasDeviceName(a);
|
||||
final bHasName = _hasDeviceName(b);
|
||||
if (aHasName && !bHasName) return -1;
|
||||
@@ -152,6 +158,27 @@ class _BluetoothScanModalState extends State<BluetoothScanModal> {
|
||||
r.device.advName.isNotEmpty;
|
||||
}
|
||||
|
||||
/// 获取设备显示名称
|
||||
String _getDeviceName(ScanResult r) {
|
||||
final advData = r.advertisementData;
|
||||
return advData.advName.isNotEmpty
|
||||
? advData.advName
|
||||
: (r.device.platformName.isNotEmpty
|
||||
? r.device.platformName
|
||||
: (advData.localName?.isNotEmpty == true
|
||||
? advData.localName!
|
||||
: (r.device.advName.isNotEmpty
|
||||
? r.device.advName
|
||||
: '${r.device.remoteId}')));
|
||||
}
|
||||
|
||||
/// 判断设备名称是否为纯数字(时间戳样式,如 1777272534998)
|
||||
bool _isNumericName(ScanResult r) {
|
||||
final name = _getDeviceName(r);
|
||||
if (name.isEmpty) return false;
|
||||
return RegExp(r'^\d+$').hasMatch(name);
|
||||
}
|
||||
|
||||
/// 从详情页返回时同步连接状态(包括连接中和已连接)
|
||||
void _syncConnectedDevice() {
|
||||
final mgrConnected = BleManager.instance.connectedDevice;
|
||||
@@ -448,12 +475,22 @@ class _BluetoothScanModalState extends State<BluetoothScanModal> {
|
||||
|
||||
Widget _buildDeviceList() {
|
||||
// 过滤掉已连接设备(它已在状态卡片下方单独显示)
|
||||
final otherResults = _connectedDevice != null
|
||||
var otherResults = _connectedDevice != null
|
||||
? _scanResults
|
||||
.where((r) => r.device.remoteId != _connectedDevice!.remoteId)
|
||||
.toList()
|
||||
.where((r) => r.device.remoteId != _connectedDevice!.remoteId)
|
||||
.toList()
|
||||
: _scanResults;
|
||||
|
||||
// 按搜索关键词过滤
|
||||
if (_searchQuery.isNotEmpty) {
|
||||
final query = _searchQuery.toLowerCase();
|
||||
otherResults = otherResults.where((r) {
|
||||
final name = _getDeviceName(r).toLowerCase();
|
||||
final mac = r.device.remoteId.toString().toLowerCase();
|
||||
return name.contains(query) || mac.contains(query);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -466,6 +503,53 @@ class _BluetoothScanModalState extends State<BluetoothScanModal> {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
// 搜索框
|
||||
Container(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF2F3F5),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.search, size: 18, color: Color(0xFF86909C)),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
onChanged: (value) {
|
||||
setState(() => _searchQuery = value);
|
||||
},
|
||||
decoration: const InputDecoration(
|
||||
hintText: '搜索设备名称或MAC',
|
||||
hintStyle: TextStyle(
|
||||
fontSize: 13,
|
||||
color: Color(0xFF86909C),
|
||||
),
|
||||
border: InputBorder.none,
|
||||
isDense: true,
|
||||
contentPadding: EdgeInsets.symmetric(vertical: 10),
|
||||
),
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
color: Color(0xFF1D2129),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (_searchQuery.isNotEmpty)
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
setState(() => _searchQuery = '');
|
||||
},
|
||||
child: const Icon(
|
||||
Icons.close,
|
||||
size: 16,
|
||||
color: Color(0xFF86909C),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (!_isBluetoothOn)
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 24),
|
||||
@@ -487,20 +571,20 @@ class _BluetoothScanModalState extends State<BluetoothScanModal> {
|
||||
),
|
||||
)
|
||||
else if (otherResults.isEmpty)
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 24),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 24),
|
||||
child: Center(
|
||||
child: Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 24,
|
||||
height: 24,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
child: const CircularProgressIndicator(strokeWidth: 2),
|
||||
),
|
||||
SizedBox(height: 12),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'正在扫描附近设备...',
|
||||
style: TextStyle(color: Color(0xFF86909C)),
|
||||
_searchQuery.isNotEmpty ? '未找到匹配的设备' : '正在扫描附近设备...',
|
||||
style: const TextStyle(color: Color(0xFF86909C)),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -581,10 +665,7 @@ class _BluetoothScanModalState extends State<BluetoothScanModal> {
|
||||
),
|
||||
child: const Text(
|
||||
'已连接',
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
color: Colors.white,
|
||||
),
|
||||
style: TextStyle(fontSize: 10, color: Colors.white),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -57,7 +57,7 @@ class MyRemoteDataSourceImpl implements MyRemoteDataSource {
|
||||
id: 'about_us',
|
||||
title: '关于我们',
|
||||
icon: 'info',
|
||||
subTitle: 'V2.1.0',
|
||||
subTitle: 'V1.0.1',
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
@@ -10,6 +11,8 @@ import 'package:maibu_satabot_v2/core/storage/user_storage.dart';
|
||||
import 'package:maibu_satabot_v2/features/auth/presentation/bloc/auth_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/main_container/presentation/cubit/tab_config_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/device_list/presentation/float_bar/cubit/float_bar_setting_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/core/update/update_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/core/update/update_state.dart';
|
||||
|
||||
/// 系统设置综合页面
|
||||
class SystemSettingsPage extends StatefulWidget {
|
||||
@@ -20,6 +23,25 @@ class SystemSettingsPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _SystemSettingsPageState extends State<SystemSettingsPage> {
|
||||
String _currentVersion = '';
|
||||
int _currentVersionCode = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadVersion();
|
||||
}
|
||||
|
||||
Future<void> _loadVersion() async {
|
||||
try {
|
||||
final String versionString = await rootBundle.loadString('pubspec.yaml');
|
||||
final versionMatch = RegExp(r'version:\s*(\d+\.\d+\.\d+)\+(\d+)').firstMatch(versionString);
|
||||
setState(() {
|
||||
_currentVersion = versionMatch?.group(1) ?? '1.0.0';
|
||||
_currentVersionCode = int.tryParse(versionMatch?.group(2) ?? '1') ?? 1;
|
||||
});
|
||||
} catch (_) {}
|
||||
}
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -52,6 +74,9 @@ class _SystemSettingsPageState extends State<SystemSettingsPage> {
|
||||
// 语言设置
|
||||
_buildLanguageSection(),
|
||||
const SizedBox(height: 12),
|
||||
// 版本更新
|
||||
_buildUpdateSection(),
|
||||
const SizedBox(height: 12),
|
||||
// 退出登录
|
||||
_buildLogoutButton(context),
|
||||
const SizedBox(height: 20),
|
||||
@@ -297,6 +322,105 @@ class _SystemSettingsPageState extends State<SystemSettingsPage> {
|
||||
);
|
||||
}
|
||||
|
||||
/// 版本更新
|
||||
Widget _buildUpdateSection() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: context.appColors.cardBackground,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: context.appColors.cardShadow,
|
||||
blurRadius: 8,
|
||||
offset: Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: BlocConsumer<UpdateCubit, UpdateState>(
|
||||
listener: (context, state) {
|
||||
if (state is UpdateUpToDate) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: const Text('当前已是最新版本'),
|
||||
backgroundColor: context.appColors.success,
|
||||
duration: const Duration(seconds: 2),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
final isChecking = state is UpdateChecking;
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'版本更新',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: context.appColors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'当前版本: $_currentVersion ($_currentVersionCode)',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: context.appColors.textTertiary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
isChecking ? '正在检查更新...' : '点击检查是否有新版本',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: context.appColors.textTertiary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (isChecking)
|
||||
const SizedBox(
|
||||
width: 24,
|
||||
height: 24,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
else
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
context.read<UpdateCubit>().checkUpdate();
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 8,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF165DFF),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: const Text(
|
||||
'检查更新',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 退出登录按钮
|
||||
Widget _buildLogoutButton(BuildContext context) {
|
||||
return GestureDetector(
|
||||
|
||||
Reference in New Issue
Block a user