更新
This commit is contained in:
@@ -291,12 +291,12 @@ class _DeviceDataComponentWidgetState extends State<DeviceDataComponentWidget> {
|
||||
});
|
||||
_popupEntry?.remove();
|
||||
_popupEntry = null;
|
||||
dealWifi(widget.device['mac']);
|
||||
dealWifi(widget.device);
|
||||
},
|
||||
),
|
||||
_buildMenuItem(
|
||||
text: "设备校准".tr,
|
||||
onTap: () {
|
||||
onTap: () async {
|
||||
setState(() {
|
||||
_isPopupOpen = false;
|
||||
});
|
||||
@@ -305,7 +305,7 @@ class _DeviceDataComponentWidgetState extends State<DeviceDataComponentWidget> {
|
||||
BlueteethBindController blueteethBindController = Get.find();
|
||||
blueteethBindController.currentDeviceMac?.value =
|
||||
widget.device['mac'];
|
||||
Get.toNamed("/calibrationPage", arguments: 2);
|
||||
await Get.toNamed("/calibrationPage", arguments: 2);
|
||||
},
|
||||
),
|
||||
_buildMenuItem(
|
||||
@@ -848,11 +848,12 @@ class _DeviceDataComponentWidgetState extends State<DeviceDataComponentWidget> {
|
||||
),
|
||||
);
|
||||
},
|
||||
child: SvgPicture.asset(
|
||||
'assets/img/icon/signal${widget.device['status']['wifi']}.svg',
|
||||
width: 25.rpx,
|
||||
height: 25.rpx,
|
||||
fit: BoxFit.fill,
|
||||
|
||||
child: Container(
|
||||
width: 30.rpx,
|
||||
height: 24.rpx,
|
||||
child: Image.asset(
|
||||
'assets/img/signal${_getSignalLevel(widget.device['status']['signal'])}.png'),
|
||||
),
|
||||
),
|
||||
if (widget.device['status']['inBed'] != null &&
|
||||
@@ -860,10 +861,10 @@ class _DeviceDataComponentWidgetState extends State<DeviceDataComponentWidget> {
|
||||
widget.device['status']['status'] == 1)
|
||||
ClickableContainer(
|
||||
backgroundColor: Colors.transparent,
|
||||
highlightColor: Colors.grey, // 可根据需要更换颜色
|
||||
highlightColor: Colors.grey,
|
||||
padding:
|
||||
EdgeInsetsDirectional.fromSTEB(0, 0.rpx, 0, 0),
|
||||
borderRadius: 0, // 如果你希望圆角可修改
|
||||
borderRadius: 0,
|
||||
onTap: () {
|
||||
showTipDialog(
|
||||
context,
|
||||
@@ -1285,149 +1286,149 @@ class _DeviceDataComponentWidgetState extends State<DeviceDataComponentWidget> {
|
||||
return "未知数据".tr;
|
||||
}
|
||||
|
||||
Future<void> dealWifi(String mac) async {
|
||||
bodyDeviceController.wifiMac = mac;
|
||||
Get.toNamed("/wifiPage", arguments: mac);
|
||||
Future<void> dealWifi(device) async {
|
||||
bodyDeviceController.wifiMac = device['mac'];
|
||||
Get.toNamed("/wifiPage", arguments: device);
|
||||
return;
|
||||
final blueteethBindController = Get.find<BlueteethBindController>();
|
||||
final themeController = Get.find<ThemeController>();
|
||||
// final blueteethBindController = Get.find<BlueteethBindController>();
|
||||
// final themeController = Get.find<ThemeController>();
|
||||
|
||||
// 显示加载对话框
|
||||
showLoadingDialog(Get.context!, title: "连接中...".tr);
|
||||
// // 显示加载对话框
|
||||
// showLoadingDialog(Get.context!, title: "连接中...".tr);
|
||||
|
||||
// 设置超时定时器
|
||||
Timer? timeoutTimer;
|
||||
bool isConnected = false;
|
||||
// // 设置超时定时器
|
||||
// Timer? timeoutTimer;
|
||||
// bool isConnected = false;
|
||||
|
||||
try {
|
||||
// 开始扫描蓝牙设备
|
||||
await FlutterBluePlus.startScan(timeout: Duration(seconds: 10));
|
||||
// try {
|
||||
// // 开始扫描蓝牙设备
|
||||
// await FlutterBluePlus.startScan(timeout: Duration(seconds: 10));
|
||||
|
||||
// 设置超时(20秒)
|
||||
timeoutTimer = Timer(Duration(seconds: 20), () {
|
||||
try {
|
||||
if (!isConnected) {
|
||||
Navigator.of(context).pop(); // 先关闭 dialog
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
TopSlideNotification.show(
|
||||
context,
|
||||
text: "设备连接超时,请重试".tr,
|
||||
textColor: themeController.currentColor.sc9,
|
||||
);
|
||||
});
|
||||
FlutterBluePlus.stopScan();
|
||||
}
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
});
|
||||
// // 设置超时(20秒)
|
||||
// timeoutTimer = Timer(Duration(seconds: 20), () {
|
||||
// try {
|
||||
// if (!isConnected) {
|
||||
// Navigator.of(context).pop(); // 先关闭 dialog
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// TopSlideNotification.show(
|
||||
// context,
|
||||
// text: "设备连接超时,请重试".tr,
|
||||
// textColor: themeController.currentColor.sc9,
|
||||
// );
|
||||
// });
|
||||
// FlutterBluePlus.stopScan();
|
||||
// }
|
||||
// } catch (e) {
|
||||
// print(e);
|
||||
// }
|
||||
// });
|
||||
|
||||
// 监听扫描结果
|
||||
StreamSubscription<List<ScanResult>>? scanSubscription;
|
||||
scanSubscription = FlutterBluePlus.scanResults.listen((results) async {
|
||||
// 过滤出符合条件的设备
|
||||
ScanResult? targetDevice;
|
||||
// // 监听扫描结果
|
||||
// StreamSubscription<List<ScanResult>>? scanSubscription;
|
||||
// scanSubscription = FlutterBluePlus.scanResults.listen((results) async {
|
||||
// // 过滤出符合条件的设备
|
||||
// ScanResult? targetDevice;
|
||||
|
||||
for (var r in results) {
|
||||
if (r.advertisementData.manufacturerData.containsKey(0xFFED)) {
|
||||
List<int> rawData = r.advertisementData.manufacturerData[0xFFED]!;
|
||||
BleDeviceData deviceData = parseBleData(rawData);
|
||||
String deviceMac =
|
||||
deviceData.deviceId.replaceAll(':', '').toLowerCase();
|
||||
if (deviceMac == mac.toLowerCase()) {
|
||||
targetDevice = r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// for (var r in results) {
|
||||
// if (r.advertisementData.manufacturerData.containsKey(0xFFED)) {
|
||||
// List<int> rawData = r.advertisementData.manufacturerData[0xFFED]!;
|
||||
// BleDeviceData deviceData = parseBleData(rawData);
|
||||
// String deviceMac =
|
||||
// deviceData.deviceId.replaceAll(':', '').toLowerCase();
|
||||
// if (deviceMac == mac.toLowerCase()) {
|
||||
// targetDevice = r;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
if (targetDevice != null && !isConnected) {
|
||||
isConnected = true;
|
||||
FlutterBluePlus.stopScan();
|
||||
scanSubscription?.cancel();
|
||||
timeoutTimer?.cancel();
|
||||
// if (targetDevice != null && !isConnected) {
|
||||
// isConnected = true;
|
||||
// FlutterBluePlus.stopScan();
|
||||
// scanSubscription?.cancel();
|
||||
// timeoutTimer?.cancel();
|
||||
|
||||
try {
|
||||
// 连接设备
|
||||
// await targetDevice.device.connect();
|
||||
THapp bledevice = THapp(device: targetDevice.device);
|
||||
await bledevice.device.connect();
|
||||
var res2 = bledevice.isConnected;
|
||||
if (res2) {
|
||||
Navigator.pop(context);
|
||||
TopSlideNotification.show(
|
||||
context,
|
||||
text: "蓝牙绑定.连接成功".tr,
|
||||
textColor: themeController.currentColor.sc2,
|
||||
);
|
||||
blueteethBindController.currentDevice = bledevice;
|
||||
if (lisObj != null) {
|
||||
lisObj!.cancel();
|
||||
}
|
||||
var aa;
|
||||
lisObj = blueteethBindController.currentDevice!.statusStream
|
||||
.listen((onData) async {
|
||||
if (onData.status == BleEventType.recvLineLog) {
|
||||
final line = onData.val;
|
||||
print("[bleee]:" + line);
|
||||
}
|
||||
if (onData.status == BleEventType.ready) {
|
||||
aa = await getDeviceNetVersion(
|
||||
blueteethBindController.currentDevice!, 1);
|
||||
if (aa == "4g") {
|
||||
// TopSlideNotification.show(
|
||||
// Get.context!,
|
||||
// text: "4g设备配置wifi提示".tr,
|
||||
// textColor: themeController.currentColor.sc9,
|
||||
// );
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
TopSlideNotification.show(
|
||||
context,
|
||||
text: "4g设备配置wifi提示".tr,
|
||||
textColor: themeController.currentColor.sc9,
|
||||
);
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
Get.toNamed("/wifiPage", arguments: 2);
|
||||
}
|
||||
}
|
||||
});
|
||||
// try {
|
||||
// // 连接设备
|
||||
// // await targetDevice.device.connect();
|
||||
// THapp bledevice = THapp(device: targetDevice.device);
|
||||
// await bledevice.device.connect();
|
||||
// var res2 = bledevice.isConnected;
|
||||
// if (res2) {
|
||||
// Navigator.pop(context);
|
||||
// TopSlideNotification.show(
|
||||
// context,
|
||||
// text: "蓝牙绑定.连接成功".tr,
|
||||
// textColor: themeController.currentColor.sc2,
|
||||
// );
|
||||
// blueteethBindController.currentDevice = bledevice;
|
||||
// if (lisObj != null) {
|
||||
// lisObj!.cancel();
|
||||
// }
|
||||
// var aa;
|
||||
// lisObj = blueteethBindController.currentDevice!.statusStream
|
||||
// .listen((onData) async {
|
||||
// if (onData.status == BleEventType.recvLineLog) {
|
||||
// final line = onData.val;
|
||||
// print("[bleee]:" + line);
|
||||
// }
|
||||
// if (onData.status == BleEventType.ready) {
|
||||
// aa = await getDeviceNetVersion(
|
||||
// blueteethBindController.currentDevice!, 1);
|
||||
// if (aa == "4g") {
|
||||
// // TopSlideNotification.show(
|
||||
// // Get.context!,
|
||||
// // text: "4g设备配置wifi提示".tr,
|
||||
// // textColor: themeController.currentColor.sc9,
|
||||
// // );
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// TopSlideNotification.show(
|
||||
// context,
|
||||
// text: "4g设备配置wifi提示".tr,
|
||||
// textColor: themeController.currentColor.sc9,
|
||||
// );
|
||||
// });
|
||||
// return;
|
||||
// } else {
|
||||
// Get.toNamed("/wifiPage", arguments: 2);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
|
||||
// Get.toNamed("/wifiPage", arguments: {bledevice});
|
||||
} else {
|
||||
Navigator.pop(context);
|
||||
TopSlideNotification.show(
|
||||
context,
|
||||
text: "蓝牙绑定.连接失败".tr,
|
||||
textColor: themeController.currentColor.sc9,
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
Navigator.of(Get.context!).pop(); // 关闭加载对话框
|
||||
TopSlideNotification.show(
|
||||
Get.context!,
|
||||
text: "设备连接失败".tr,
|
||||
textColor: themeController.currentColor.sc9,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
// // Get.toNamed("/wifiPage", arguments: {bledevice});
|
||||
// } else {
|
||||
// Navigator.pop(context);
|
||||
// TopSlideNotification.show(
|
||||
// context,
|
||||
// text: "蓝牙绑定.连接失败".tr,
|
||||
// textColor: themeController.currentColor.sc9,
|
||||
// );
|
||||
// }
|
||||
// } catch (e) {
|
||||
// Navigator.of(Get.context!).pop(); // 关闭加载对话框
|
||||
// TopSlideNotification.show(
|
||||
// Get.context!,
|
||||
// text: "设备连接失败".tr,
|
||||
// textColor: themeController.currentColor.sc9,
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
|
||||
// 等待扫描完成
|
||||
await Future.delayed(Duration(seconds: 20));
|
||||
} catch (e) {
|
||||
timeoutTimer?.cancel();
|
||||
Navigator.of(Get.context!).pop(); // 关闭加载对话框
|
||||
TopSlideNotification.show(
|
||||
Get.context!,
|
||||
text: "扫描过程中发生错误".tr,
|
||||
textColor: themeController.currentColor.sc9,
|
||||
);
|
||||
} finally {
|
||||
timeoutTimer?.cancel();
|
||||
await FlutterBluePlus.stopScan();
|
||||
}
|
||||
// // 等待扫描完成
|
||||
// await Future.delayed(Duration(seconds: 20));
|
||||
// } catch (e) {
|
||||
// timeoutTimer?.cancel();
|
||||
// Navigator.of(Get.context!).pop(); // 关闭加载对话框
|
||||
// TopSlideNotification.show(
|
||||
// Get.context!,
|
||||
// text: "扫描过程中发生错误".tr,
|
||||
// textColor: themeController.currentColor.sc9,
|
||||
// );
|
||||
// } finally {
|
||||
// timeoutTimer?.cancel();
|
||||
// await FlutterBluePlus.stopScan();
|
||||
// }
|
||||
}
|
||||
|
||||
double _calculateMaxMenuItemWidth(List<String> texts, TextStyle style) {
|
||||
@@ -1448,6 +1449,18 @@ class _DeviceDataComponentWidgetState extends State<DeviceDataComponentWidget> {
|
||||
|
||||
return iconWidth + spacing + maxTextWidth + horizontalPadding;
|
||||
}
|
||||
|
||||
int _getSignalLevel(int signal) {
|
||||
if (signal <= 25) {
|
||||
return 1;
|
||||
} else if (signal <= 50) {
|
||||
return 2;
|
||||
} else if (signal <= 75) {
|
||||
return 3;
|
||||
} else {
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_showBluetoothNotEnabledDialog() async {
|
||||
|
||||
Reference in New Issue
Block a user