蓝牙增强+个更换绑定逻辑接口
This commit is contained in:
@@ -13,7 +13,7 @@ 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 '../../domain/usecases/get_device_by_spilt_code_usecase.dart';
|
||||
import 'bind_device_page.dart';
|
||||
|
||||
class BleDeviceDetailPage extends StatefulWidget {
|
||||
@@ -290,32 +290,22 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
);
|
||||
|
||||
try {
|
||||
final getAllDevicesUseCase = GetIt.instance<GetAllDevicesUseCase>();
|
||||
final devices = await getAllDevicesUseCase.execute();
|
||||
// 用蓝牙名(时间戳)作为 code,调 getDeviceBySpiltCode 精确查询设备
|
||||
final getDeviceBySpiltCodeUseCase =
|
||||
GetIt.instance<GetDeviceBySpiltCodeUseCase>();
|
||||
final DeviceEntity? matchedDevice =
|
||||
await getDeviceBySpiltCodeUseCase.execute(bleName);
|
||||
|
||||
if (loadingCtx != null && Navigator.canPop(loadingCtx!)) {
|
||||
Navigator.pop(loadingCtx!);
|
||||
}
|
||||
|
||||
debugPrint(
|
||||
'>>> [BindDevice] bleName=$bleName, devices=${devices.length}',
|
||||
'>>> [BindDevice] bleName=$bleName, matched=${matchedDevice == null ? "未查到" : matchedDevice.name}',
|
||||
);
|
||||
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) {
|
||||
// 接口未查到(返回无 data)→ 与之前一致弹窗提示
|
||||
if (matchedDevice == null || matchedDevice.name.isEmpty) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
@@ -334,11 +324,11 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
}
|
||||
|
||||
if (!mounted) return;
|
||||
// 复用扫一扫的绑定页面流程
|
||||
// 复用扫一扫的绑定页面流程(scanResult 传序列号 serialNumber)
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => BindDevicePage(scanResult: matchedDevice!.name),
|
||||
builder: (_) => BindDevicePage(scanResult: matchedDevice.name),
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user