This commit is contained in:
wyf
2025-06-06 09:23:23 +08:00
parent bc86cf7d78
commit 54ad7c18e6
7 changed files with 543 additions and 244 deletions

View File

@@ -246,7 +246,7 @@ class _SleepDataModuleWidgetState extends State<SleepDataModuleWidget> {
'date': widget.data['time'] != null
? int.parse(widget.data['time'].toString())
: DateTime.now().millisecondsSinceEpoch,
"mac": 'aaaaaaeeeeeq',
"mac": widget.data['mac'] != null && widget.data['mac'].isNotEmpty? widget.data['mac']:'aaaaaaeeeeeq',
'type': 1,
'name': 'sleep', //'sleep', 'heartRate' 或 'breathe'
'itemName': widget.data['id'],

View File

@@ -61,25 +61,25 @@ class BlueteethBindController extends GetControllerEx<BlueteethBindModel> {
Timer? _statusTimer;
THapp? currentDevice;
RxInt wifiStatus = 0.obs;//wifi连接状态 0未连接 1已连接
RxInt wifiStatus = 0.obs; //wifi连接状态 0未连接 1已连接
RxList wifiList = [].obs;
RxMap connect_wifi = {}.obs;
RxString scanMac = "".obs;
RxString currentDeviceMac = "".obs;//当前选中的设备mac地址
RxString currentDeviceMac = "".obs; //当前选中的设备mac地址
RxString? cid = "".obs;
RxString search = "".obs; //搜索关键字
RxBool bluetoothStatus = false.obs;//蓝牙开启状态
RxInt connectStatus = 0.obs;//当前wifi连接状态 0未连接 1已连接
RxInt blueConnectFlag = 0.obs;//当前蓝牙连接状态 0.正在连接 1.未连接 2.已连接
RxInt netType = 0.obs;//当前网络类型 0.正在检测 1.wifi 2.4g设备 3.未知
RxInt wifiConnectStatus = 1.obs;//获取wifi状态 0.正在检测 1.已检测完
RxBool bluetoothStatus = false.obs; //蓝牙开启状态
RxInt connectStatus = 0.obs; //当前wifi连接状态 0未连接 1已连接
RxInt blueConnectFlag = 0.obs; //当前蓝牙连接状态 0.正在连接 1.未连接 2.已连接
RxInt netType = 0.obs; //当前网络类型 0.正在检测 1.wifi 2.4g设备 3.未知
RxInt wifiConnectStatus = 1.obs; //获取wifi状态 0.正在检测 1.已检测完
RxMap selectWifi = {}.obs; //正在连接wifi信息
int returnPage = 0;//0返回首页 1.返回设备列表
int returnPage = 0; //0返回首页 1.返回设备列表
// 安全展示 TopSlideNotification
void safeShowNotification(String msg) {
@@ -174,32 +174,72 @@ class BlueteethBindController extends GetControllerEx<BlueteethBindModel> {
if (response.data['data'] != null && response.data['data'] is List) {
List<dynamic> responseList = response.data['data'];
// 构建 mac -> 设备的映射
Map<String, BleDeviceData> deviceMap = {
for (var d in model.devicelist!)
if (d.mac != null) d.mac!: d
if (d.mac != null) d.mac!.toLowerCase(): d,
};
List<String> slaveMacsToRemove = [];
// 用于记录已经设置过主从关系的 mac避免重复
Set<String> processedMacs = {};
for (var item in responseList) {
String mac = item['mac'];
String? bindMac = item['bindMac'];
String mac = item['mac'].toLowerCase();
String? bindMac = item['bindMac']?.toLowerCase();
bool? bind = item['bind'];
if (deviceMap.containsKey(mac)) {
BleDeviceData currentDevice = deviceMap[mac]!;
currentDevice.bind = bind;
if (bindMac != null && deviceMap.containsKey(bindMac)) {
BleDeviceData masterDevice = deviceMap[bindMac]!;
masterDevice.slave = currentDevice;
slaveMacsToRemove.add(mac);
if (!deviceMap.containsKey(mac)) continue;
BleDeviceData currentDevice = deviceMap[mac]!;
currentDevice.bind = bind;
if (bindMac != null && deviceMap.containsKey(bindMac)) {
final isMutualBind = responseList.any((e) =>
e['mac']?.toString().toLowerCase() == bindMac &&
e['bindMac']?.toString().toLowerCase() == mac);
if (isMutualBind) {
if (processedMacs.contains(mac) ||
processedMacs.contains(bindMac)) {
continue;
}
final masterMac = (mac.compareTo(bindMac) < 0) ? mac : bindMac;
final slaveMac = (mac.compareTo(bindMac) < 0) ? bindMac : mac;
if (deviceMap.containsKey(masterMac) &&
deviceMap.containsKey(slaveMac)) {
deviceMap[masterMac]!.slave = deviceMap[slaveMac];
processedMacs.add(masterMac);
processedMacs.add(slaveMac);
}
} else {
if (!processedMacs.contains(mac)) {
BleDeviceData masterDevice = deviceMap[bindMac]!;
masterDevice.slave = currentDevice;
processedMacs.add(mac);
processedMacs.add(bindMac);
}
}
}
}
model.devicelist!
.removeWhere((device) => slaveMacsToRemove.contains(device.mac));
model.betDevicelist = model.devicelist!;
// 获取所有被作为 slave 的 mac用于排除掉
final Set<String> allSlaveMacs = {
for (var d in deviceMap.values)
if (d.slave?.mac != null) d.slave!.mac!.toLowerCase()
};
// 构造最终列表,只保留主设备和未被作为 slave 的独立设备
final List<BleDeviceData> finalList = deviceMap.values.where((d) {
final mac = d.mac?.toLowerCase();
if (mac == null) return false;
if (d.slave != null) return true; // 主设备
return !allSlaveMacs.contains(mac); // 不是别人 slave 的独立设备
}).toList();
model.betDevicelist = finalList;
} else {
model.betDevicelist = [];
}
@@ -235,6 +275,7 @@ class BlueteethBindController extends GetControllerEx<BlueteethBindModel> {
queryUrl += "?lang=$language";
}
}
//todo 双人版的话根据slave取到mac
var data = {
"deviceType": 1,
"mac": d.mac,

View File

@@ -136,7 +136,6 @@ class _BlueteethDevicePageState extends State<BlueteethDevicePage> {
});
await FlutterBluePlus.startScan(timeout: Duration(seconds: 10));
_scanSubscription = FlutterBluePlus.scanResults.listen((results) {
if (!mounted) return;
@@ -147,7 +146,8 @@ class _BlueteethDevicePageState extends State<BlueteethDevicePage> {
final filteredResults = results.where((r) {
final isTarget = r.rssi > signalThreshold &&
r.advertisementData.localName == "AITH-V2" &&
(r.advertisementData.localName == "AITH-V2" ||
r.advertisementData.localName == "SLAVE") &&
r.advertisementData.manufacturerData.containsKey(0xFFED);
if (!isTarget) return false;
@@ -622,7 +622,7 @@ class _BlueteethDevicePageState extends State<BlueteethDevicePage> {
// '匹配出的外围设备'.tr +
// "${blueteethBindController.model.betDevicelist!.length}",
'匹配出的外围设备'.tr +
"${blueteethBindController.model.blelist!.length}",
"${blueteethBindController.model.betDevicelist!.length}",
style: FlutterFlowTheme.of(context)
.bodyMedium
.override(
@@ -647,11 +647,12 @@ class _BlueteethDevicePageState extends State<BlueteethDevicePage> {
mainAxisSize: MainAxisSize.max,
children: [
...blueteethBindController.model.blelist!
.map((device) =>
SingleBlueteethDeviceCompoentWidget(
// device: device,
bleDevice: device,
))
.map((device) {
return SingleBlueteethDeviceCompoentWidget(
// device: device,
bleDevice: device,
);
})
.toList()
.divide(SizedBox(height: 30.rpx))
.addToEnd(SizedBox(height: 30.rpx)),

View File

@@ -300,5 +300,6 @@ class _DoubleBlueteethDeviceCompoentWidgetState
),
),
);
}
}

View File

@@ -53,206 +53,267 @@ class _SingleBlueteethDeviceCompoentWidgetState
return Container();
}
device = match;
return ClickableContainer(
backgroundColor: themeController.currentColor.sc5,
highlightColor: themeController.currentColor.sc21,
borderRadius: 20.rpx,
padding: EdgeInsetsDirectional.fromSTEB(30.rpx, 36.rpx, 0, 52.rpx),
onTap: () async {
try {
//1.先判斷当前是否有别的设备处于连接中,没有处于连接,判断是否绑定;
//2.如果没有绑定,直接连接;如果绑定,弹出提示框,提示是否解绑
if (blueteethBindController.currentDeviceMac?.value != null &&
blueteethBindController.currentDeviceMac!.value.isNotEmpty) {
if (blueteethBindController.currentDeviceMac?.value != device.mac) {
showConfirmDialog(
context, Container(), "其他设备正在绑定中,是否终止其他设备绑定?".tr,
onConfirm: () {
blueteethBindController.currentDeviceMac.value = "";
blueteethBindController.updateAll();
}, onCancel: () {});
}
} else {
blueteethBindController.currentDeviceMac?.value = device.mac!;
blueteethBindController.updateAll();
}
if (device.bind == true) {
await showHaveBindDialog(context);
blueteethBindController.currentDeviceMac.value = "";
blueteethBindController.updateAll();
} else {
showConfirmDialog(
context,
Container(),
'蓝牙绑定.确定绑定提示'.tr,
onConfirm: () async {
ApiResponse response =
await blueteethBindController.bindDeviceAndMAC(device);
TopSlideNotification.show(context, text: response.msg!);
if (response.code == HttpStatusCodes.ok) {
//更新设备绑定流程
updateDeviceBindStatus(device);
Get.toNamed("/wifiPage");
THapp bledevice = THapp(device: widget.bleDevice.device);
blueteethBindController.currentDevice = bledevice;
// blueteethBindController.currentDeviceMac.value = "";
} else {
if (device.slave == null) {
return ClickableContainer(
backgroundColor: themeController.currentColor.sc5,
highlightColor: themeController.currentColor.sc21,
borderRadius: 20.rpx,
padding: EdgeInsetsDirectional.fromSTEB(30.rpx, 36.rpx, 0, 52.rpx),
onTap: () async {
try {
//1.先判斷当前是否有别的设备处于连接中,没有处于连接,判断是否绑定
//2.如果没有绑定,直接连接;如果绑定,弹出提示框,提示是否解绑;
if (blueteethBindController.currentDeviceMac?.value != null &&
blueteethBindController.currentDeviceMac!.value.isNotEmpty) {
if (blueteethBindController.currentDeviceMac?.value !=
device.mac) {
showConfirmDialog(
context, Container(), "其他设备正在绑定中,是否终止其他设备绑定?".tr,
onConfirm: () {
blueteethBindController.currentDeviceMac.value = "";
blueteethBindController.updateAll();
TopSlideNotification.show(
context,
text: response.msg ?? "蓝牙绑定.连接异常".tr,
textColor: themeController.currentColor.sc9,
);
}
},
onCancel: () {
print('用户点击了取消');
blueteethBindController.currentDeviceMac.value = "";
blueteethBindController.updateAll();
},
}, onCancel: () {});
}
} else {
blueteethBindController.currentDeviceMac?.value = device.mac!;
blueteethBindController.updateAll();
}
if (device.bind == true) {
await showHaveBindDialog(context);
blueteethBindController.currentDeviceMac.value = "";
blueteethBindController.updateAll();
} else {
showConfirmDialog(
context,
Container(),
'蓝牙绑定.确定绑定提示'.tr,
onConfirm: () async {
ApiResponse response =
await blueteethBindController.bindDeviceAndMAC(device);
TopSlideNotification.show(context, text: response.msg!);
if (response.code == HttpStatusCodes.ok) {
//更新设备绑定流程
updateDeviceBindStatus(device);
Get.toNamed("/wifiPage");
THapp bledevice = THapp(device: widget.bleDevice.device);
blueteethBindController.currentDevice = bledevice;
// blueteethBindController.currentDeviceMac.value = "";
} else {
blueteethBindController.currentDeviceMac.value = "";
blueteethBindController.updateAll();
TopSlideNotification.show(
context,
text: response.msg ?? "蓝牙绑定.连接异常".tr,
textColor: themeController.currentColor.sc9,
);
}
},
onCancel: () {
print('用户点击了取消');
blueteethBindController.currentDeviceMac.value = "";
blueteethBindController.updateAll();
},
);
}
} catch (e) {
Navigator.pop(context);
TopSlideNotification.show(
context,
text: "蓝牙绑定.连接异常".tr,
textColor: themeController.currentColor.sc9,
);
edm.EasyDartModule.logger.info("蓝牙绑定.连接异常: $e");
DailyLogUtils.writeLog("蓝牙绑定.连接异常: $e");
}
} catch (e) {
Navigator.pop(context);
TopSlideNotification.show(
context,
text: "蓝牙绑定.连接异常".tr,
textColor: themeController.currentColor.sc9,
);
edm.EasyDartModule.logger.info("蓝牙绑定.连接异常: $e");
DailyLogUtils.writeLog("蓝牙绑定.连接异常: $e");
}
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [
Padding(
padding:
EdgeInsetsDirectional.fromSTEB(0.rpx, 0.rpx, 30.rpx, 0.rpx),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [
Padding(
padding:
EdgeInsetsDirectional.fromSTEB(0.rpx, 0.rpx, 30.rpx, 0.rpx),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
device.name ?? '蓝牙绑定.默认设备名称'.tr,
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
color: const Color(0xFFF6FAFD),
fontSize: 30.rpx,
letterSpacing: 0.0,
),
),
Obx(() {
if (blueteethBindController.currentDeviceMac.value ==
device.mac) {
return SizedBox(
width: 24.rpx,
height: 24.rpx,
child: CircularProgressIndicator(
strokeWidth: 1,
valueColor:
AlwaysStoppedAnimation<Color>(Colors.white),
),
);
}
return Container();
}),
],
),
),
Row(
children: [
Text(
device.name ?? '蓝牙绑定.默认设备名称'.tr,
"蓝牙绑定.信号强度".tr + '${device.rssi ?? '-'}dBm',
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
color: const Color(0xFFF6FAFD),
fontSize: 30.rpx,
color: const Color(0xFFEBF2F8),
fontSize: 26.rpx,
letterSpacing: 0.0,
),
),
Obx(() {
if (blueteethBindController.currentDeviceMac.value ==
device.mac) {
return SizedBox(
width: 24.rpx,
height: 24.rpx,
child: CircularProgressIndicator(
strokeWidth: 1,
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
SizedBox(width: 40.rpx),
Text(
"蓝牙绑定.SN".tr + '${device.sn ?? '-'}',
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
color: const Color(0xFFF5F9FD),
fontSize: 26.rpx,
letterSpacing: 0.0,
),
);
}
return Container();
}),
),
],
),
),
Row(
children: [
Text(
"蓝牙绑定.信号强度".tr + '${device.rssi ?? '-'}dBm',
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
color: const Color(0xFFEBF2F8),
fontSize: 26.rpx,
letterSpacing: 0.0,
),
),
SizedBox(width: 40.rpx),
Text(
"蓝牙绑定.SN".tr + '${device.sn ?? '-'}',
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
color: const Color(0xFFF5F9FD),
fontSize: 26.rpx,
letterSpacing: 0.0,
),
),
],
),
Text(
"蓝牙绑定.蓝牙地址".tr + '${device.deviceId ?? '-'}',
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
color: const Color(0xFFF6FAFD),
fontSize: 26.rpx,
letterSpacing: 0.0,
),
),
Text(
"蓝牙绑定.mac".tr + '${device.mac ?? '-'}',
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
color: const Color(0xFFF6FAFD),
fontSize: 26.rpx,
letterSpacing: 0.0,
),
),
Row(
children: [
Text(
"蓝牙绑定.网络".tr +
'${device.isOnline == true ? '蓝牙绑定.在线'.tr : '蓝牙绑定.离线'.tr}',
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
color: const Color(0xFFEBF2F8),
fontSize: 26.rpx,
letterSpacing: 0.0,
),
),
SizedBox(width: 145.rpx),
Row(
children: [
Text(
"蓝牙绑定.传感器".tr + "",
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
color: const Color(0xFFEBF2F8),
fontSize: 26.rpx,
letterSpacing: 0.0,
),
Text(
"蓝牙绑定.蓝牙地址".tr + '${device.deviceId ?? '-'}',
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
color: const Color(0xFFF6FAFD),
fontSize: 26.rpx,
letterSpacing: 0.0,
),
Text(
device.bind == false ? '蓝牙绑定.可绑定'.tr : '蓝牙绑定.已被绑定'.tr,
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
color: device.bind == false
? const Color(0xFF1AD2B5)
: themeController.currentColor.sc9,
fontSize: 26.rpx,
letterSpacing: 0.0,
),
),
Text(
"蓝牙绑定.mac".tr + '${device.mac ?? '-'}',
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
color: const Color(0xFFF6FAFD),
fontSize: 26.rpx,
letterSpacing: 0.0,
),
],
),
],
),
Text(
"版本".tr + '${device.version ?? '-'}',
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
color: const Color(0xFFF6FAFD),
fontSize: 26.rpx,
letterSpacing: 0.0,
),
Row(
children: [
Text(
"蓝牙绑定.网络".tr +
'${device.isOnline == true ? '蓝牙绑定.在线'.tr : '蓝牙绑定.离线'.tr}',
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
color: const Color(0xFFEBF2F8),
fontSize: 26.rpx,
letterSpacing: 0.0,
),
),
),
].divide(SizedBox(height: 37.rpx)),
),
);
SizedBox(width: 145.rpx),
Row(
children: [
Text(
"蓝牙绑定.传感器".tr + "",
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
color: const Color(0xFFEBF2F8),
fontSize: 26.rpx,
letterSpacing: 0.0,
),
),
Text(
device.bind == false ? '蓝牙绑定.可绑定'.tr : '蓝牙绑定.已被绑定'.tr,
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
color: device.bind == false
? const Color(0xFF1AD2B5)
: themeController.currentColor.sc9,
fontSize: 26.rpx,
letterSpacing: 0.0,
),
),
],
),
],
),
Text(
"版本".tr + '${device.version ?? '-'}',
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
color: const Color(0xFFF6FAFD),
fontSize: 26.rpx,
letterSpacing: 0.0,
),
),
].divide(SizedBox(height: 37.rpx)),
),
);
} else {
List<BleDeviceData> devices = [];
devices.add(device);
devices.add(device.slave!);
return ClickableContainer(
backgroundColor: themeController.currentColor.sc5,
highlightColor: themeController.currentColor.sc21,
borderRadius: 20.rpx,
padding: EdgeInsetsDirectional.fromSTEB(30.rpx, 36.rpx, 30.rpx, 52.rpx),
onTap: () async {
showBindDoubleDialog(
context,
devices,
onConfirm: (int selectedIndex) {
// selectedIndex 是 0全选或 1或 2
bool flag1 = devices[0].bind!;
bool flag2 = devices[1].bind!;
if (selectedIndex == 0) {
// 全选
if (flag1 == true || flag2 == true) {
showHaveBindDialog(context);
return;
} else {}
} else if (selectedIndex == 1) {
// 主
if (flag1 == true) {
showHaveBindDialog(context);
return;
} else {}
} else if (selectedIndex == 2) {
if (flag2 == true) {
showHaveBindDialog(context);
return;
} else {}
}
TopSlideNotification.show(context,text: "双人版绑定修复中");
print('选中了设备索引:$selectedIndex');
//配置wifi
},
onCancel: () {
print("用户取消绑定");
},
);
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [
_buildDeviceInfoSection(device, context),
Divider(
thickness: 1.rpx,
color: themeController.currentColor.sc3,
),
_buildDeviceInfoSection(device.slave!, context),
].divide(SizedBox(height: 37.rpx)),
),
);
}
}
//更新设备绑定状态
@@ -280,4 +341,134 @@ class _SingleBlueteethDeviceCompoentWidgetState
onFailure: (res) {},
);
}
Widget _buildDeviceInfoSection(device, BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: EdgeInsetsDirectional.fromSTEB(0.rpx, 0.rpx, 30.rpx, 0.rpx),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
device.name ?? '蓝牙绑定.默认设备名称'.tr,
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
color: const Color(0xFFF6FAFD),
fontSize: 30.rpx,
letterSpacing: 0.0,
),
),
Obx(() {
if (blueteethBindController.currentDeviceMac.value ==
device.mac) {
return SizedBox(
width: 24.rpx,
height: 24.rpx,
child: CircularProgressIndicator(
strokeWidth: 1,
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
),
);
}
return Container();
}),
],
),
),
Row(
children: [
Text(
"蓝牙绑定.信号强度".tr + '${device.rssi ?? '-'}dBm',
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
color: const Color(0xFFEBF2F8),
fontSize: 26.rpx,
letterSpacing: 0.0,
),
),
SizedBox(width: 40.rpx),
Text(
"蓝牙绑定.SN".tr + '${device.sn ?? '-'}',
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
color: const Color(0xFFF5F9FD),
fontSize: 26.rpx,
letterSpacing: 0.0,
),
),
],
),
Text(
"蓝牙绑定.蓝牙地址".tr + '${device.deviceId ?? '-'}',
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
color: const Color(0xFFF6FAFD),
fontSize: 26.rpx,
letterSpacing: 0.0,
),
),
Text(
"蓝牙绑定.mac".tr + '${device.mac ?? '-'}',
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
color: const Color(0xFFF6FAFD),
fontSize: 26.rpx,
letterSpacing: 0.0,
),
),
Row(
children: [
Text(
"蓝牙绑定.网络".tr +
'${device.isOnline == true ? '蓝牙绑定.在线'.tr : '蓝牙绑定.离线'.tr}',
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
color: const Color(0xFFEBF2F8),
fontSize: 26.rpx,
letterSpacing: 0.0,
),
),
SizedBox(width: 145.rpx),
Row(
children: [
Text(
"蓝牙绑定.传感器".tr + "",
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
color: const Color(0xFFEBF2F8),
fontSize: 26.rpx,
letterSpacing: 0.0,
),
),
Text(
device.bind == false ? '蓝牙绑定.可绑定'.tr : '蓝牙绑定.已被绑定'.tr,
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
color: device.bind == false
? const Color(0xFF1AD2B5)
: themeController.currentColor.sc9,
fontSize: 26.rpx,
letterSpacing: 0.0,
),
),
],
),
],
),
Text(
"版本".tr + '${device.version ?? '-'}',
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
color: const Color(0xFFF6FAFD),
fontSize: 26.rpx,
letterSpacing: 0.0,
),
),
].divide(SizedBox(
height: 37.rpx,
)),
);
}
}

View File

@@ -14,10 +14,16 @@ import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
import 'package:vbvs_app/model/BleDeviceData.dart';
import 'package:vbvs_app/pages/device_bind/componnet/FancyCircleCheckbox.dart';
void showBindDoubleDialog(BuildContext context, List<BleDeviceData> devices) {
void showBindDoubleDialog(
BuildContext context,
List<BleDeviceData> devices, {
required void Function(int selectedIndex) onConfirm,
required VoidCallback onCancel,
}) {
ThemeController themeController = Get.find();
BlueteethBindController blueteethBindController = Get.find();
// 初始化默认选中 deviceIndex0 为 true
blueteethBindController.model.deviceIndex0 = true;
blueteethBindController.model.deviceIndex1 = false;
blueteethBindController.model.deviceIndex2 = false;
@@ -25,7 +31,7 @@ void showBindDoubleDialog(BuildContext context, List<BleDeviceData> devices) {
showDialog(
context: context,
barrierDismissible: true,
barrierColor: Colors.black.withOpacity(0.5), // 建议加个背景模糊色
barrierColor: Colors.black.withOpacity(0.5),
builder: (BuildContext context) {
return FrostedDialog(
blurSigma: 3.0,
@@ -34,7 +40,7 @@ void showBindDoubleDialog(BuildContext context, List<BleDeviceData> devices) {
color: themeController.currentColor.sc17,
borderRadius: BorderRadius.circular(20.0),
),
padding: EdgeInsetsDirectional.fromSTEB(60.rpx, 0, 60.rpx, 0),
padding: EdgeInsetsDirectional.fromSTEB(0.rpx, 0, 0.rpx, 0),
child: Container(
width: double.infinity,
constraints: BoxConstraints(
@@ -47,8 +53,7 @@ void showBindDoubleDialog(BuildContext context, List<BleDeviceData> devices) {
Align(
alignment: AlignmentDirectional(0, 0),
child: Padding(
padding:
EdgeInsetsDirectional.fromSTEB(0.rpx, 93.rpx, 0, 0),
padding: EdgeInsetsDirectional.fromSTEB(0.rpx, 93.rpx, 0, 0),
child: Text(
'蓝牙绑定.双人版绑定标题'.tr,
style: FlutterFlowTheme.of(context).bodyMedium.override(
@@ -67,9 +72,9 @@ void showBindDoubleDialog(BuildContext context, List<BleDeviceData> devices) {
value: () => blueteethBindController.model.deviceIndex0!,
onChanged: (v) {
if (!blueteethBindController.model.deviceIndex0!) {
blueteethBindController.model.deviceIndex0 = v;
blueteethBindController.model.deviceIndex1 = !v;
blueteethBindController.model.deviceIndex2 = !v;
blueteethBindController.model.deviceIndex0 = true;
blueteethBindController.model.deviceIndex1 = false;
blueteethBindController.model.deviceIndex2 = false;
blueteethBindController.updateAll();
}
},
@@ -77,13 +82,15 @@ void showBindDoubleDialog(BuildContext context, List<BleDeviceData> devices) {
// 主设备
_buildCheckboxRow(
context,
title: '蓝牙绑定.主设备'.tr + "asasasasasas(已被绑定)",
title: '蓝牙绑定.主设备'.tr +
"${devices[0].mac}" +
(devices[0].bind == false ? "可绑定".tr : "已被绑定".tr),
value: () => blueteethBindController.model.deviceIndex1!,
onChanged: (v) {
if (!blueteethBindController.model.deviceIndex1!) {
blueteethBindController.model.deviceIndex1 = v;
blueteethBindController.model.deviceIndex0 = !v;
blueteethBindController.model.deviceIndex2 = !v;
blueteethBindController.model.deviceIndex0 = false;
blueteethBindController.model.deviceIndex1 = true;
blueteethBindController.model.deviceIndex2 = false;
blueteethBindController.updateAll();
}
},
@@ -91,36 +98,46 @@ void showBindDoubleDialog(BuildContext context, List<BleDeviceData> devices) {
// 从设备
_buildCheckboxRow(
context,
title: '蓝牙绑定.从设备'.tr,
title: '蓝牙绑定.从设备'.tr +
"${devices[1].mac}" +
(devices[1].bind == false ? "可绑定".tr : "已被绑定".tr),
value: () => blueteethBindController.model.deviceIndex2!,
onChanged: (v) {
if (!blueteethBindController.model.deviceIndex2!) {
blueteethBindController.model.deviceIndex2 = v;
blueteethBindController.model.deviceIndex0 = !v;
blueteethBindController.model.deviceIndex1 = !v;
blueteethBindController.model.deviceIndex0 = false;
blueteethBindController.model.deviceIndex1 = false;
blueteethBindController.model.deviceIndex2 = true;
blueteethBindController.updateAll();
}
},
),
// 确定按钮
Padding(
padding: EdgeInsetsDirectional.fromSTEB(0, 100.rpx, 0, 0),
padding: EdgeInsetsDirectional.fromSTEB(60.rpx, 100.rpx, 60.rpx, 0),
child: _buildActionButton(
context,
text: '蓝牙绑定.确定'.tr,
onTap: () {
Get.back();
int selectedIndex = blueteethBindController.model.deviceIndex0!
? 0
: (blueteethBindController.model.deviceIndex1! ? 1 : 2);
onConfirm(selectedIndex);
},
),
),
// 取消按钮
Padding(
padding: EdgeInsetsDirectional.fromSTEB(0, 19.rpx, 0, 60.rpx),
padding: EdgeInsetsDirectional.fromSTEB(60.rpx, 19.rpx, 60.rpx, 60.rpx),
child: _buildActionButton(
context,
text: '蓝牙绑定.取消'.tr,
onTap: () {
Get.back();
onCancel();
},
),
),
@@ -133,6 +150,7 @@ void showBindDoubleDialog(BuildContext context, List<BleDeviceData> devices) {
);
}
Future<void> showHaveBindDialog(BuildContext context) async {
ThemeController themeController = Get.find();
@@ -339,7 +357,7 @@ Widget _buildCheckboxRow(
}) {
ThemeController themeController = Get.find();
return Padding(
padding: EdgeInsetsDirectional.fromSTEB(20.rpx, 64.rpx, 0.rpx, 0.rpx),
padding: EdgeInsetsDirectional.fromSTEB(60.rpx, 64.rpx, 0.rpx, 0.rpx),
child: Row(
mainAxisSize: MainAxisSize.max,
children: [
@@ -350,14 +368,47 @@ Widget _buildCheckboxRow(
onChanged: onChanged,
)),
Expanded(
child: Text(
title,
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
letterSpacing: 0.0,
fontSize: AppConstants().normal_text_fontSize,
color: themeController.currentColor.sc3,
child: Builder(
builder: (_) {
final bool isBindable = title.contains('可绑定'.tr);
final bool isBound = title.contains('已被绑定'.tr);
// 提取主文本部分
final String mainText =
title.replaceAll('可绑定'.tr, '').replaceAll('已被绑定'.tr, '');
return RichText(
text: TextSpan(
children: [
TextSpan(
text: mainText,
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
letterSpacing: 0.0,
fontSize: AppConstants().normal_text_fontSize,
color: themeController.currentColor.sc3,
),
),
if (isBindable)
TextSpan(
text: "(" + '可绑定'.tr + ")",
style: TextStyle(
fontSize: AppConstants().normal_text_fontSize,
color: themeController.currentColor.sc1,
),
),
if (isBound)
TextSpan(
text: "(" + '已被绑定'.tr + ")",
style: TextStyle(
fontSize: AppConstants().normal_text_fontSize,
color: themeController.currentColor.sc9,
),
),
],
),
);
},
),
),
].divide(SizedBox(width: 21.rpx)),
@@ -374,10 +425,12 @@ Widget _buildActionButton(
return CustomCard(
borderRadius: AppConstants().button_container_radius,
onTap: onTap,
colors: [
themeController.currentColor.sc1,
themeController.currentColor.sc2,
],
colors: '蓝牙绑定.确定'.tr == text
? [
themeController.currentColor.sc1,
themeController.currentColor.sc2,
]
: [Colors.transparent],
child: Container(
width: MediaQuery.sizeOf(context).width,
height: MediaQuery.sizeOf(context).height * 0.055,
@@ -385,6 +438,15 @@ Widget _buildActionButton(
minWidth: 500.rpx,
minHeight: 90.rpx,
),
decoration: '蓝牙绑定.确定'.tr == text
? BoxDecoration()
: BoxDecoration(
border: Border.all(
color: themeController.currentColor.sc3, // 你可以换成指定颜色
width: 1.0.rpx,
),
borderRadius: BorderRadius.circular(50.rpx), // 可选:加圆角
),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,

View File

@@ -1040,6 +1040,7 @@ class _HomePageState extends State<HomePage> {
);
List stateModule = [];
String currentTime = "";
String goalMac = targetDevice?['mac'];
return DynamicReportDetailWidget(
key: ValueKey(
'${targetDevice!['mac']}_${homeController.model.type}'), // 添加唯一key
@@ -1086,6 +1087,8 @@ class _HomePageState extends State<HomePage> {
stateModule[j]['onto'] = true;
stateModule[j]['time'] =
currentTime;
stateModule[j]['mac'] =
goalMac;
return SleepDataModuleWidget(
data: stateModule[j],
);