更新眠花糖兼容wifi配置

This commit is contained in:
wyf
2025-10-28 14:51:28 +08:00
parent 7cfd3bf8f5
commit 3c5db3bdf2
14 changed files with 1259 additions and 882 deletions

View File

@@ -106,53 +106,53 @@ class _VitalSignsSensorState extends State<VitalSignsSensorPage> {
left: 0.rpx,
child: returnIconButtomNew(),
),
Positioned(
right: 0.rpx,
child: ClickableContainer(
backgroundColor: Colors.transparent,
highlightColor: Colors.transparent,
padding: EdgeInsets.symmetric(
horizontal: 30.rpx, vertical: 30.rpx),
onTap: () {
// TopSlideNotification.show(context);
//检测蓝牙是否开启,没有开启提示开启蓝牙
//如果已经开启则进行x秒的蓝牙扫描
BluetoothHelper.listenBluetoothState((isOn) {
mhtBlueToothController.model.bluetooth = isOn;
mhtBlueToothController.updateAll();
if (!isOn) {
mhtBlueToothController.model.blueRawData = [];
mhtBlueToothController
.model.deviceDataStatus = [];
mhtBlueToothController.updateAll();
_showBluetoothNotEnabledDialog();
}
});
_checkBluetoothPermission();
},
child: Obx(() {
return SizedBox(
width: 34.rpx,
height: mhtBlueToothController.isScanning.value
? 34.rpx
: 24.rpx,
child: mhtBlueToothController.isScanning.value
? CircularProgressIndicator(
strokeWidth: 2,
valueColor:
AlwaysStoppedAnimation<Color>(
themeController.currentColor.sc3,
),
)
: SvgPicture.asset(
'assets/img/icon/upgrade.svg',
fit: BoxFit.cover,
color: Colors.white,
),
);
}),
),
),
// Positioned(
// right: 0.rpx,
// child: ClickableContainer(
// backgroundColor: Colors.transparent,
// highlightColor: Colors.transparent,
// padding: EdgeInsets.symmetric(
// horizontal: 30.rpx, vertical: 30.rpx),
// onTap: () {
// // TopSlideNotification.show(context);
// //检测蓝牙是否开启,没有开启提示开启蓝牙
// //如果已经开启则进行x秒的蓝牙扫描
// BluetoothHelper.listenBluetoothState((isOn) {
// mhtBlueToothController.model.bluetooth = isOn;
// mhtBlueToothController.updateAll();
// if (!isOn) {
// mhtBlueToothController.model.blueRawData = [];
// mhtBlueToothController
// .model.deviceDataStatus = [];
// mhtBlueToothController.updateAll();
// _showBluetoothNotEnabledDialog();
// }
// });
// _checkBluetoothPermission();
// },
// child: Obx(() {
// return SizedBox(
// width: 34.rpx,
// height: mhtBlueToothController.isScanning.value
// ? 34.rpx
// : 24.rpx,
// child: mhtBlueToothController.isScanning.value
// ? CircularProgressIndicator(
// strokeWidth: 2,
// valueColor:
// AlwaysStoppedAnimation<Color>(
// themeController.currentColor.sc3,
// ),
// )
// : SvgPicture.asset(
// 'assets/img/icon/upgrade.svg',
// fit: BoxFit.cover,
// color: Colors.white,
// ),
// );
// }),
// ),
// ),
],
),
),
@@ -279,12 +279,16 @@ class _VitalSignsSensorState extends State<VitalSignsSensorPage> {
.toList();
//todo 过滤,跟远程的版本信息比对
// return macList.contains(d.mac) && d.version != null;
if (formatString(d.mac) == "48CA43B2E0B4") {
ef.log("");
if (macList.contains(formatString(d.mac))) {
ef.log("[待升级设备]:${d.mac}, 版本:${d.version}");
}
return macList.contains(formatString(d.mac));
// return macList.contains(formatString(d.mac)) &&
// d.version != null &&
// judgeNeedUpgrade(d.version);
return macList.contains(formatString(d.mac)) &&
judgeNeedUpgrade(d.version);
}).toList();
print("$filteredResults");
for (var item in filteredResults) {
// 如果不存在才加入,初始进度设为-1代表未开始升级
mhtBlueToothController.localUpgradeMac.putIfAbsent(
@@ -436,6 +440,42 @@ class _VitalSignsSensorState extends State<VitalSignsSensorPage> {
/// 格式化字符串:移除所有空格和冒号,并将小写字母转换为大写
return input.replaceAll(' ', '').replaceAll(':', '').toUpperCase();
}
bool judgeNeedUpgrade(int? version) {
return true;
try {
if (version == null) {
ef.log("[升级判断] 本地版本为空,不需要升级");
return false;
}
String? newestVersionStr = mhtBlueToothController.currentUpgradeVersion;
if (newestVersionStr == null || newestVersionStr.isEmpty) {
ef.log("[升级判断] 远程最新版本为空,不需要升级");
return false;
}
// 转为整数比较
int? newestVersion = int.tryParse(newestVersionStr);
if (newestVersion == null) {
ef.log("[升级判断] 远程版本格式错误: $newestVersionStr");
return false;
}
ef.log("[升级判断] 当前版本: $version,远程版本: $newestVersion");
if (newestVersion > version) {
ef.log("[升级判断] 检测到新版本,需要升级");
return true;
} else {
ef.log("[升级判断] 已是最新版本,无需升级");
return false;
}
} catch (e) {
ef.log("[升级判断] 异常: $e");
return false;
}
}
}
class VitalWidget extends StatelessWidget {
@@ -843,6 +883,7 @@ class VitalWidget extends StatelessWidget {
mac: data['mac'],
firmwareUrl: firmwareUrl,
);
} catch (e) {
print("升级失败: $e");
TopSlideNotification.show(context,
@@ -960,520 +1001,6 @@ class VitalWidget extends StatelessWidget {
}
}
// class VitalWidget extends StatelessWidget {
// final String title;
// final Map<String, dynamic> data;
// const VitalWidget({
// super.key,
// required this.title,
// required this.data,
// });
// @override
// Widget build(BuildContext context) {
// MHTBlueToothController mhtBlueToothController = Get.find();
// final String id = data['mac'.tr] ?? '--';
// final int? timestamp = data['status']['updateTime'];
// final String time = (timestamp != null)
// ? DateFormat('yyyy-MM-dd HH:mm')
// .format(DateTime.fromMillisecondsSinceEpoch(timestamp))
// : '--';
// return ClickableContainer(
// backgroundColor: Color(0xFF003058),
// highlightColor: Color(0xFF055466),
// borderRadius: 20.rpx,
// padding: EdgeInsetsDirectional.fromSTEB(30.rpx, 30.rpx, 30.rpx, 40.rpx),
// onTap: () {},
// child: Column(
// mainAxisSize: MainAxisSize.max,
// children: [
// Container(
// width: double.infinity,
// child: Align(
// alignment: AlignmentDirectional(-1, 0),
// child: Text(
// title,
// style: TextStyle(
// fontFamily: 'Inter',
// fontSize: 30.rpx,
// letterSpacing: 0.0,
// color: themeController.currentColor.sc3,
// ),
// ),
// ),
// ),
// Row(
// mainAxisAlignment: MainAxisAlignment.start,
// children: [
// Container(
// width: MediaQuery.sizeOf(context).width * 0.14,
// constraints: BoxConstraints(minWidth: 110.rpx),
// child: Text(
// "设备ID".tr,
// style: TextStyle(
// color: stringToColor("#929699"),
// fontSize: 26.rpx,
// ),
// maxLines: 2,
// overflow: TextOverflow.ellipsis,
// ),
// ),
// Text(
// id,
// style: TextStyle(fontSize: 26.rpx, color: Color(0xFFFFFFFF)),
// ),
// ].divide(SizedBox(width: 33.rpx)),
// ),
// Row(
// mainAxisAlignment: MainAxisAlignment.start,
// children: [
// Container(
// width: MediaQuery.sizeOf(context).width * 0.14,
// constraints: BoxConstraints(minWidth: 110.rpx),
// child: Text(
// "更新时间".tr,
// style: TextStyle(
// color: stringToColor("#929699"),
// fontSize: 26.rpx,
// ),
// maxLines: 2,
// overflow: TextOverflow.ellipsis,
// ),
// ),
// Text(
// time,
// style: TextStyle(fontSize: 26.rpx, color: Color(0xFFFFFFFF)),
// ),
// ].divide(SizedBox(width: 33.rpx)),
// ),
// Row(
// mainAxisSize: MainAxisSize.max,
// children: [
// Container(
// width: MediaQuery.sizeOf(context).width * 0.14,
// constraints: BoxConstraints(minWidth: 110.rpx),
// child: Text(
// "设备状态".tr,
// style: TextStyle(
// color: stringToColor("#929699"),
// fontSize: 26.rpx,
// ),
// maxLines: 2,
// overflow: TextOverflow.ellipsis,
// ),
// ),
// Expanded(
// child: Row(
// mainAxisSize: MainAxisSize.max,
// children: [
// if (data['status']['signal'] != null &&
// data['status']['signal'] != -1 &&
// data['status']['status'] != null &&
// data['status']['status'] == 1)
// ClickableContainer(
// backgroundColor: Colors.transparent,
// highlightColor: Colors.grey,
// padding: EdgeInsets.zero,
// borderRadius: 0,
// onTap: () {
// showTipDialog(
// context,
// Container(
// child: RichText(
// text: TextSpan(
// text: "信号强度".tr,
// style: TextStyle(
// color: Colors.black,
// fontSize:
// AppConstants().title_text_fontSize,
// ),
// children: [
// TextSpan(
// text: getBedSignal(
// data['status']['signal']),
// style: TextStyle(
// color: themeController.currentColor.sc2,
// fontSize:
// AppConstants().title_text_fontSize,
// ),
// ),
// ],
// ),
// ),
// ),
// backgroundColor: Color(0xFFFFFFFF),
// colors: [
// Color(0XFF1592AA),
// Color(0xFF0C83A7),
// Color(0xFF006FA3)
// ],
// );
// },
// child: Container(
// width: 30.rpx,
// height: 24.rpx,
// child: Image.asset(
// 'assets/img/signal${_getSignalLevel(data['status']['signal'])}.png'),
// ),
// ),
// if (data['status']['inBed'] != null &&
// data['status']['status'] != null &&
// data['status']['status'] == 1)
// ClickableContainer(
// backgroundColor: Colors.transparent,
// highlightColor: Colors.grey,
// padding: EdgeInsetsDirectional.fromSTEB(0, 0.rpx, 0, 0),
// borderRadius: 0,
// onTap: () {
// showTipDialog(
// context,
// Container(
// child: RichText(
// text: TextSpan(
// text: "是否在床".tr,
// style: TextStyle(
// color: Colors.black,
// fontSize:
// AppConstants().title_text_fontSize,
// ),
// children: [
// TextSpan(
// text:
// getBedStatus(data['status']['inBed']),
// style: TextStyle(
// color: themeController.currentColor.sc2,
// fontSize:
// AppConstants().title_text_fontSize,
// ),
// ),
// ],
// ),
// ),
// ),
// backgroundColor: Color(0xFFFFFFFF),
// colors: [
// Color(0XFF1592AA),
// Color(0xFF0C83A7),
// Color(0xFF006FA3)
// ],
// );
// },
// child: SizedBox(
// width: 16.rpx,
// height: 36.rpx,
// child: SvgPicture.asset(
// data['status']['inBed'] == 0
// ? 'assets/img/icon/not_bed.svg'
// : 'assets/img/icon/in_bed.svg',
// fit: BoxFit.fill,
// ),
// ),
// ),
// if (data['status']['failure'] != 0 &&
// data['status']['status'] != null &&
// data['status']['status'] == 1)
// ClickableContainer(
// backgroundColor: Colors.transparent,
// highlightColor: Colors.grey,
// padding: EdgeInsetsDirectional.fromSTEB(0, 0.rpx, 0, 0),
// borderRadius: 0,
// onTap: () {
// showTipDialog(
// context,
// Container(
// child: RichText(
// text: TextSpan(
// text: "设备故障".tr,
// style: TextStyle(
// color: Colors.black,
// fontSize:
// AppConstants().title_text_fontSize,
// ),
// children: const [],
// ),
// ),
// ),
// backgroundColor: Color(0xFFFFFFFF),
// colors: [
// Color(0XFF1592AA),
// Color(0xFF0C83A7),
// Color(0xFF006FA3)
// ],
// );
// },
// child: SizedBox(
// width: 27.rpx,
// height: 27.rpx,
// child: SvgPicture.asset(
// 'assets/img/icon/device_issue.svg',
// fit: BoxFit.cover,
// ),
// ),
// ),
// if (data['status']['status'] != null &&
// data['status']['status'] == 0)
// ClickableContainer(
// backgroundColor: Colors.transparent,
// highlightColor: Colors.grey,
// padding: EdgeInsetsDirectional.fromSTEB(0, 0.rpx, 0, 0),
// borderRadius: 0,
// onTap: () {
// showTipDialog(
// context,
// Container(
// child: RichText(
// text: TextSpan(
// text: "网络状态".tr,
// style: TextStyle(
// color: Colors.black,
// fontSize:
// AppConstants().title_text_fontSize,
// ),
// children: [
// TextSpan(
// text: data['status']['status'] == 1
// ? "在线".tr
// : "离线".tr,
// style: TextStyle(
// color: themeController.currentColor.sc2,
// fontSize:
// AppConstants().title_text_fontSize,
// ),
// ),
// ],
// ),
// ),
// ),
// backgroundColor: Color(0xFFFFFFFF),
// colors: [
// Color(0XFF1592AA),
// Color(0xFF0C83A7),
// Color(0xFF006FA3)
// ],
// );
// },
// child: SizedBox(
// width: 27.rpx,
// height: 27.rpx,
// child: SvgPicture.asset(
// 'assets/img/icon/device_issue.svg',
// fit: BoxFit.cover,
// ),
// ),
// ),
// Obx(() {
// final upgradeInfo =
// mhtBlueToothController.localUpgradeMac[data['mac']];
// if (upgradeInfo == null) {
// return Container();
// }
// final int progress = upgradeInfo?['progress'] ?? -1;
// final String status = upgradeInfo?['status'] ?? '';
// // 只有在有升级信息时才显示
// if (mhtBlueToothController.localUpgradeMac
// .containsKey(data['mac'])) {
// return ClickableContainer(
// backgroundColor: Colors.transparent,
// highlightColor: Colors.grey,
// padding:
// EdgeInsetsDirectional.fromSTEB(0, 0.rpx, 0, 0),
// borderRadius: 0,
// onTap: () {
// if (progress == -1) {
// _showUpgradeDialog(context, data['mac']);
// } else {
// _showCancelDialog(context, data['mac']);
// }
// },
// child: Row(
// children: [
// // 升级图标
// SizedBox(
// width: 34.rpx,
// height: 24.rpx,
// child: SvgPicture.asset(
// 'assets/img/icon/upgrade.svg',
// fit: BoxFit.cover,
// color: _getUpgradeIconColor(status),
// ),
// ),
// SizedBox(width: 10.rpx),
// // 进度数字和状态指示
// Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// mainAxisSize: MainAxisSize.min,
// children: [
// // 进度百分比
// if (progress >= 0 && progress <= 100)
// Text(
// "$progress%",
// style: TextStyle(
// color: _getProgressTextColor(progress),
// fontSize: 26.rpx,
// fontWeight: FontWeight.bold,
// ),
// ),
// ],
// ),
// ],
// ),
// );
// }
// return Container();
// }),
// ].divide(SizedBox(width: 50.rpx)), // 减少图标间距
// ),
// ),
// ].divide(SizedBox(width: 34.rpx)),
// ),
// ].divide(SizedBox(height: 20.rpx)),
// ),
// );
// }
// // 获取状态文本
// String _getStatusText(String status) {
// switch (status) {
// case 'waiting':
// return '等待'.tr;
// case 'downloading':
// return '下载'.tr;
// case 'upgrading':
// return '升级'.tr;
// case 'completed':
// return '完成'.tr;
// case 'failed':
// return '失败'.tr;
// case 'cancelled':
// return '取消'.tr;
// default:
// return status;
// }
// }
// // 获取状态文字颜色
// Color _getStatusTextColor(String status) {
// switch (status) {
// case 'completed':
// return Colors.green;
// case 'failed':
// return Colors.red;
// case 'cancelled':
// return Colors.orange;
// default:
// return Colors.blue;
// }
// }
// // 获取进度文字颜色
// Color _getProgressTextColor(int progress) {
// if (progress == 100) return Colors.green;
// if (progress < 0) return Colors.red;
// return Colors.white;
// }
// // 获取升级图标颜色
// Color _getUpgradeIconColor(String status) {
// switch (status) {
// case 'completed':
// return Colors.green;
// case 'failed':
// return Colors.red;
// case 'cancelled':
// return Colors.orange;
// default:
// return themeController.currentColor.sc3;
// }
// }
// // 显示升级对话框
// void _showUpgradeDialog(BuildContext context, String mac) {
// MHTBlueToothController mhtBlueToothController = Get.find();
// showConfirmUpDialog(
// context,
// Column(
// children: [
// SizedBox(
// width: 94.rpx,
// height: 70.rpx,
// child: SvgPicture.asset(
// 'assets/img/icon/upgrade.svg',
// fit: BoxFit.cover,
// ),
// ),
// Text(
// "设备升级".tr,
// style: TextStyle(
// color: stringToColor("#333333"),
// fontSize: AppConstants().title_text_fontSize,
// ),
// ),
// ].divide(SizedBox(height: 37.rpx)),
// ),
// "", onConfirm: () async {
// final deviceData = mhtBlueToothController.localUpgradeMac[mac]!;
// final firmwareUrl = mhtBlueToothController.currentUpgradeUrl;
// if (firmwareUrl == null) {
// TopSlideNotification.show(context, text: "未获取到固件下载地址".tr);
// return;
// }
// try {
// final scanResult = deviceData['device'].scanResult;
// final thapp = THapp(device: scanResult.device);
// if (!thapp.isConnected) {
// await thapp.device.connect();
// }
// await MultiDeviceFirmwareUpdater().startUpgrade(
// thapp: thapp,
// mac: mac,
// firmwareUrl: firmwareUrl,
// );
// } catch (e) {
// TopSlideNotification.show(context,
// text: "升级失败: ${e.toString()}".tr, textColor: Colors.red);
// }
// },
// onCancel: () {},
// backgroundColor: Colors.white,
// confirmText: "立即升级".tr,
// cancelText: "下次再说".tr);
// }
// // 显示取消对话框
// void _showCancelDialog(BuildContext context, String mac) {
// showConfirmCancelDialog(
// context,
// Column(
// children: [
// Text(
// "确认取消升级".tr,
// style: TextStyle(
// color: stringToColor("#333333"),
// fontSize: AppConstants().title_text_fontSize,
// ),
// ),
// Text(
// "确定要取消设备 $mac 的升级吗?".tr,
// style: TextStyle(
// color: stringToColor("#333333"),
// fontSize: AppConstants().normal_text_fontSize,
// ),
// ),
// ],
// ),
// "", onConfirm: () {
// MultiDeviceFirmwareUpdater().cancelUpgrade(mac);
// },
// onCancel: () {},
// backgroundColor: Colors.white,
// confirmText: "确认取消".tr,
// cancelText: "继续升级".tr,
// confirmButtonColor: Colors.red);
// }
// }
getBedSignal(signal) {
if (signal <= 1) {
return "较弱".tr;