This commit is contained in:
wyf
2025-05-20 14:00:44 +08:00
parent 75ddfca402
commit 0a8cffa4c6
48 changed files with 5221 additions and 1733 deletions

View File

@@ -13,7 +13,9 @@ import 'package:vbvs_app/common/util/FitTool.dart';
import 'package:vbvs_app/common/util/MyUtils.dart';
import 'package:vbvs_app/component/tool/ClickableContainer.dart';
import 'package:vbvs_app/component/tool/CustomCard.dart';
import 'package:vbvs_app/component/tool/ToggleColorContainer.dart';
import 'package:vbvs_app/component/tool/TopSlideNotification.dart';
import 'package:vbvs_app/component/tool/cmd.dart';
import 'package:vbvs_app/controller/device/blueteeth_bind_controller.dart';
import 'package:vbvs_app/controller/device/body_device_controller.dart';
import 'package:vbvs_app/controller/person/person_controller.dart';
@@ -41,6 +43,9 @@ class _DeviceDataComponentWidgetState extends State<DeviceDataComponentWidget> {
OverlayEntry? _popupEntry;
BodyDeviceController bodyDeviceController = Get.find();
PersonController personController = Get.find();
bool _isPopupOpen = false;
var lisObj;
@override
void dispose() {
@@ -48,7 +53,15 @@ class _DeviceDataComponentWidgetState extends State<DeviceDataComponentWidget> {
super.dispose();
}
@override
void initState() {
super.initState();
}
void _showPopup() {
setState(() {
_isPopupOpen = true;
});
final RenderBox? renderBox =
_arrowKey.currentContext?.findRenderObject() as RenderBox?;
if (renderBox == null) return;
@@ -67,7 +80,7 @@ class _DeviceDataComponentWidgetState extends State<DeviceDataComponentWidget> {
final textStyle = TextStyle(
fontSize: AppConstants().normal_text_fontSize,
color: themeController.currentColor.sc3, // 你也可以传 sc2
color: themeController.currentColor.sc3,
);
final allTexts = [
@@ -126,11 +139,17 @@ class _DeviceDataComponentWidgetState extends State<DeviceDataComponentWidget> {
popupLeft = screenWidth - popupWidth - paddingOffset;
}
// setState(() {
// _isPopupOpen = false;
// });
_popupEntry?.remove();
_popupEntry = OverlayEntry(
builder: (context) => GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
setState(() {
_isPopupOpen = false;
});
_popupEntry?.remove();
_popupEntry = null;
},
@@ -222,6 +241,9 @@ class _DeviceDataComponentWidgetState extends State<DeviceDataComponentWidget> {
: null,
text: "体征检测设备.首页展示".tr,
onTap: () async {
setState(() {
_isPopupOpen = false;
});
_popupEntry?.remove();
_popupEntry = null;
ApiResponse apiResponse =
@@ -245,6 +267,9 @@ class _DeviceDataComponentWidgetState extends State<DeviceDataComponentWidget> {
_buildMenuItem(
text: "体征检测设备.设备详情".tr,
onTap: () {
setState(() {
_isPopupOpen = false;
});
_popupEntry?.remove();
_popupEntry = null;
Get.toNamed("/deviceDetail", arguments: widget.device);
@@ -254,18 +279,12 @@ class _DeviceDataComponentWidgetState extends State<DeviceDataComponentWidget> {
if (widget.device['bind_type'] == BindType.active.code) {
items.addAll([
// _buildMenuItem(
// text: "WIFI配置".tr,
// onTap: () {
// _popupEntry?.remove();
// _popupEntry = null;
// // Get.toNamed("/deviceDetail", arguments: widget.device);
// dealWifi(widget.device['mac']);
// },
// ),
_buildMenuItem(
text: "WIFI配置".tr,
onTap: () {
setState(() {
_isPopupOpen = false;
});
_popupEntry?.remove();
_popupEntry = null;
dealWifi(widget.device['mac']);
@@ -274,6 +293,9 @@ class _DeviceDataComponentWidgetState extends State<DeviceDataComponentWidget> {
_buildMenuItem(
text: "设备校准".tr,
onTap: () {
setState(() {
_isPopupOpen = false;
});
_popupEntry?.remove();
_popupEntry = null;
BlueteethBindController blueteethBindController = Get.find();
@@ -284,6 +306,9 @@ class _DeviceDataComponentWidgetState extends State<DeviceDataComponentWidget> {
_buildMenuItem(
text: "分享设备".tr,
onTap: () {
setState(() {
_isPopupOpen = false;
});
_popupEntry?.remove();
_popupEntry = null;
Get.toNamed("/deviceSharePage", arguments: widget.device);
@@ -292,6 +317,9 @@ class _DeviceDataComponentWidgetState extends State<DeviceDataComponentWidget> {
_buildMenuItem(
text: "消息设置".tr,
onTap: () {
setState(() {
_isPopupOpen = false;
});
_popupEntry?.remove();
_popupEntry = null;
// Get.toNamed("/deviceDetail", arguments: widget.device);
@@ -305,6 +333,9 @@ class _DeviceDataComponentWidgetState extends State<DeviceDataComponentWidget> {
_buildMenuItem(
text: "体征检测设备.重命名".tr,
onTap: () {
setState(() {
_isPopupOpen = false;
});
_popupEntry?.remove();
_popupEntry = null;
_showRenameDialog();
@@ -313,6 +344,9 @@ class _DeviceDataComponentWidgetState extends State<DeviceDataComponentWidget> {
_buildMenuItem(
text: "体征检测设备.删除".tr,
onTap: () {
setState(() {
_isPopupOpen = false;
});
_popupEntry?.remove();
_popupEntry = null;
_showUnbindConfirmDialog();
@@ -494,14 +528,37 @@ class _DeviceDataComponentWidgetState extends State<DeviceDataComponentWidget> {
color: themeController.currentColor.sc3,
),
),
ClickableContainer(
// ClickableContainer(
// key: _arrowKey,
// padding: EdgeInsetsDirectional.fromSTEB(
// 16.rpx, 16.rpx, 14.rpx, 16.rpx),
// backgroundColor: Colors.transparent,
// highlightColor: Colors.black.withOpacity(0.1),
// borderRadius: 8.rpx,
// onTap: _showPopup,
// child: Container(
// width: 15.rpx,
// height: 8.rpx,
// child: SvgPicture.asset(
// 'assets/img/icon/arrow_down.svg',
// fit: BoxFit.cover,
// color: Colors.white,
// ),
// ),
// ),
ToggleColorContainer(
key: _arrowKey,
padding: EdgeInsetsDirectional.fromSTEB(
16.rpx, 16.rpx, 14.rpx, 16.rpx),
backgroundColor: Colors.transparent,
highlightColor: Colors.black.withOpacity(0.1),
16.rpx,
16.rpx,
14.rpx,
16.rpx,
),
initialColor: Colors.transparent,
toggledColor: Colors.black.withOpacity(0.5),
borderRadius: 8.rpx,
onTap: _showPopup,
onToggle: _showPopup,
toggled: _isPopupOpen,
child: Container(
width: 15.rpx,
height: 8.rpx,
@@ -1167,6 +1224,9 @@ class _DeviceDataComponentWidgetState extends State<DeviceDataComponentWidget> {
}
Future<void> dealWifi(String mac) async {
bodyDeviceController.wifiMac = mac;
Get.toNamed("/wifiPage", arguments: mac);
return;
final blueteethBindController = Get.find<BlueteethBindController>();
final themeController = Get.find<ThemeController>();
@@ -1179,18 +1239,24 @@ class _DeviceDataComponentWidgetState extends State<DeviceDataComponentWidget> {
try {
// 开始扫描蓝牙设备
await FlutterBluePlus.startScan(timeout: Duration(seconds: 20));
await FlutterBluePlus.startScan(timeout: Duration(seconds: 10));
// 设置超时20秒
timeoutTimer = Timer(Duration(seconds: 20), () {
if (!isConnected) {
Navigator.of(Get.context!).pop(); // 关闭加载对话框
TopSlideNotification.show(
Get.context!,
text: "设备连接超时,请重试".tr,
textColor: themeController.currentColor.sc9,
);
FlutterBluePlus.stopScan();
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);
}
});
@@ -1198,23 +1264,20 @@ class _DeviceDataComponentWidgetState extends State<DeviceDataComponentWidget> {
StreamSubscription<List<ScanResult>>? scanSubscription;
scanSubscription = FlutterBluePlus.scanResults.listen((results) async {
// 过滤出符合条件的设备
final targetDevice = results.firstWhere(
(r) {
try {
if (r.advertisementData.manufacturerData.containsKey(0xFFED)) {
List<int> rawData =
r.advertisementData.manufacturerData[0xFFED]!;
BleDeviceData deviceData = parseBleData(rawData);
String deviceMac =
deviceData.deviceId.replaceAll(':', '').toLowerCase();
return deviceMac == mac.toLowerCase();
}
return false;
} catch (e) {
return false;
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;
}
},
);
}
}
if (targetDevice != null && !isConnected) {
isConnected = true;
@@ -1236,8 +1299,40 @@ class _DeviceDataComponentWidgetState extends State<DeviceDataComponentWidget> {
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});
Get.toNamed("/wifiPage", arguments: 1);
} else {
Navigator.pop(context);
TopSlideNotification.show(
@@ -1256,6 +1351,7 @@ class _DeviceDataComponentWidgetState extends State<DeviceDataComponentWidget> {
}
}
});
// 等待扫描完成
await Future.delayed(Duration(seconds: 20));
} catch (e) {