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 'date': widget.data['time'] != null
? int.parse(widget.data['time'].toString()) ? int.parse(widget.data['time'].toString())
: DateTime.now().millisecondsSinceEpoch, : DateTime.now().millisecondsSinceEpoch,
"mac": 'aaaaaaeeeeeq', "mac": widget.data['mac'] != null && widget.data['mac'].isNotEmpty? widget.data['mac']:'aaaaaaeeeeeq',
'type': 1, 'type': 1,
'name': 'sleep', //'sleep', 'heartRate' 或 'breathe' 'name': 'sleep', //'sleep', 'heartRate' 或 'breathe'
'itemName': widget.data['id'], 'itemName': widget.data['id'],

View File

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

View File

@@ -137,7 +137,6 @@ class _BlueteethDevicePageState extends State<BlueteethDevicePage> {
await FlutterBluePlus.startScan(timeout: Duration(seconds: 10)); await FlutterBluePlus.startScan(timeout: Duration(seconds: 10));
_scanSubscription = FlutterBluePlus.scanResults.listen((results) { _scanSubscription = FlutterBluePlus.scanResults.listen((results) {
if (!mounted) return; if (!mounted) return;
@@ -147,7 +146,8 @@ class _BlueteethDevicePageState extends State<BlueteethDevicePage> {
final filteredResults = results.where((r) { final filteredResults = results.where((r) {
final isTarget = r.rssi > signalThreshold && final isTarget = r.rssi > signalThreshold &&
r.advertisementData.localName == "AITH-V2" && (r.advertisementData.localName == "AITH-V2" ||
r.advertisementData.localName == "SLAVE") &&
r.advertisementData.manufacturerData.containsKey(0xFFED); r.advertisementData.manufacturerData.containsKey(0xFFED);
if (!isTarget) return false; if (!isTarget) return false;
@@ -622,7 +622,7 @@ class _BlueteethDevicePageState extends State<BlueteethDevicePage> {
// '匹配出的外围设备'.tr + // '匹配出的外围设备'.tr +
// "${blueteethBindController.model.betDevicelist!.length}", // "${blueteethBindController.model.betDevicelist!.length}",
'匹配出的外围设备'.tr + '匹配出的外围设备'.tr +
"${blueteethBindController.model.blelist!.length}", "${blueteethBindController.model.betDevicelist!.length}",
style: FlutterFlowTheme.of(context) style: FlutterFlowTheme.of(context)
.bodyMedium .bodyMedium
.override( .override(
@@ -647,11 +647,12 @@ class _BlueteethDevicePageState extends State<BlueteethDevicePage> {
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
children: [ children: [
...blueteethBindController.model.blelist! ...blueteethBindController.model.blelist!
.map((device) => .map((device) {
SingleBlueteethDeviceCompoentWidget( return SingleBlueteethDeviceCompoentWidget(
// device: device, // device: device,
bleDevice: device, bleDevice: device,
)) );
})
.toList() .toList()
.divide(SizedBox(height: 30.rpx)) .divide(SizedBox(height: 30.rpx))
.addToEnd(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(); return Container();
} }
device = match; device = match;
return ClickableContainer( if (device.slave == null) {
backgroundColor: themeController.currentColor.sc5, return ClickableContainer(
highlightColor: themeController.currentColor.sc21, backgroundColor: themeController.currentColor.sc5,
borderRadius: 20.rpx, highlightColor: themeController.currentColor.sc21,
padding: EdgeInsetsDirectional.fromSTEB(30.rpx, 36.rpx, 0, 52.rpx), borderRadius: 20.rpx,
onTap: () async { padding: EdgeInsetsDirectional.fromSTEB(30.rpx, 36.rpx, 0, 52.rpx),
try { onTap: () async {
//1.先判斷当前是否有别的设备处于连接中,没有处于连接,判断是否绑定; try {
//2.如果没有绑定,直接连接;如果绑定,弹出提示框,提示是否解绑 //1.先判斷当前是否有别的设备处于连接中,没有处于连接,判断是否绑定
if (blueteethBindController.currentDeviceMac?.value != null && //2.如果没有绑定,直接连接;如果绑定,弹出提示框,提示是否解绑;
blueteethBindController.currentDeviceMac!.value.isNotEmpty) { if (blueteethBindController.currentDeviceMac?.value != null &&
if (blueteethBindController.currentDeviceMac?.value != device.mac) { blueteethBindController.currentDeviceMac!.value.isNotEmpty) {
showConfirmDialog( if (blueteethBindController.currentDeviceMac?.value !=
context, Container(), "其他设备正在绑定中,是否终止其他设备绑定?".tr, device.mac) {
onConfirm: () { showConfirmDialog(
blueteethBindController.currentDeviceMac.value = ""; context, Container(), "其他设备正在绑定中,是否终止其他设备绑定?".tr,
blueteethBindController.updateAll(); onConfirm: () {
}, 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.currentDeviceMac.value = "";
blueteethBindController.updateAll(); blueteethBindController.updateAll();
TopSlideNotification.show( }, onCancel: () {});
context, }
text: response.msg ?? "蓝牙绑定.连接异常".tr, } else {
textColor: themeController.currentColor.sc9, blueteethBindController.currentDeviceMac?.value = device.mac!;
); blueteethBindController.updateAll();
} }
},
onCancel: () { if (device.bind == true) {
print('用户点击了取消'); await showHaveBindDialog(context);
blueteethBindController.currentDeviceMac.value = ""; blueteethBindController.currentDeviceMac.value = "";
blueteethBindController.updateAll(); 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); child: Column(
TopSlideNotification.show( crossAxisAlignment: CrossAxisAlignment.start,
context, mainAxisSize: MainAxisSize.max,
text: "蓝牙绑定.连接异常".tr, children: [
textColor: themeController.currentColor.sc9, Padding(
); padding:
edm.EasyDartModule.logger.info("蓝牙绑定.连接异常: $e"); EdgeInsetsDirectional.fromSTEB(0.rpx, 0.rpx, 30.rpx, 0.rpx),
DailyLogUtils.writeLog("蓝牙绑定.连接异常: $e"); child: Row(
} mainAxisAlignment: MainAxisAlignment.spaceBetween,
}, children: [
child: Column( Text(
crossAxisAlignment: CrossAxisAlignment.start, device.name ?? '蓝牙绑定.默认设备名称'.tr,
mainAxisSize: MainAxisSize.max, style: FlutterFlowTheme.of(context).bodyMedium.override(
children: [ fontFamily: 'Inter',
Padding( color: const Color(0xFFF6FAFD),
padding: fontSize: 30.rpx,
EdgeInsetsDirectional.fromSTEB(0.rpx, 0.rpx, 30.rpx, 0.rpx), letterSpacing: 0.0,
child: Row( ),
mainAxisAlignment: MainAxisAlignment.spaceBetween, ),
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: [ children: [
Text( Text(
device.name ?? '蓝牙绑定.默认设备名称'.tr, "蓝牙绑定.信号强度".tr + '${device.rssi ?? '-'}dBm',
style: FlutterFlowTheme.of(context).bodyMedium.override( style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter', fontFamily: 'Inter',
color: const Color(0xFFF6FAFD), color: const Color(0xFFEBF2F8),
fontSize: 30.rpx, fontSize: 26.rpx,
letterSpacing: 0.0, letterSpacing: 0.0,
), ),
), ),
Obx(() { SizedBox(width: 40.rpx),
if (blueteethBindController.currentDeviceMac.value == Text(
device.mac) { "蓝牙绑定.SN".tr + '${device.sn ?? '-'}',
return SizedBox( style: FlutterFlowTheme.of(context).bodyMedium.override(
width: 24.rpx, fontFamily: 'Inter',
height: 24.rpx, color: const Color(0xFFF5F9FD),
child: CircularProgressIndicator( fontSize: 26.rpx,
strokeWidth: 1, letterSpacing: 0.0,
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
), ),
); ),
}
return Container();
}),
], ],
), ),
), Text(
Row( "蓝牙绑定.蓝牙地址".tr + '${device.deviceId ?? '-'}',
children: [ style: FlutterFlowTheme.of(context).bodyMedium.override(
Text( fontFamily: 'Inter',
"蓝牙绑定.信号强度".tr + '${device.rssi ?? '-'}dBm', color: const Color(0xFFF6FAFD),
style: FlutterFlowTheme.of(context).bodyMedium.override( fontSize: 26.rpx,
fontFamily: 'Inter', letterSpacing: 0.0,
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, Text(
style: FlutterFlowTheme.of(context).bodyMedium.override( "蓝牙绑定.mac".tr + '${device.mac ?? '-'}',
fontFamily: 'Inter', style: FlutterFlowTheme.of(context).bodyMedium.override(
color: device.bind == false fontFamily: 'Inter',
? const Color(0xFF1AD2B5) color: const Color(0xFFF6FAFD),
: themeController.currentColor.sc9, fontSize: 26.rpx,
fontSize: 26.rpx, letterSpacing: 0.0,
letterSpacing: 0.0,
),
), ),
], ),
), Row(
], children: [
), Text(
Text( "蓝牙绑定.网络".tr +
"版本".tr + '${device.version ?? '-'}', '${device.isOnline == true ? '蓝牙绑定.在线'.tr : '蓝牙绑定.离线'.tr}',
style: FlutterFlowTheme.of(context).bodyMedium.override( style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter', fontFamily: 'Inter',
color: const Color(0xFFF6FAFD), color: const Color(0xFFEBF2F8),
fontSize: 26.rpx, fontSize: 26.rpx,
letterSpacing: 0.0, letterSpacing: 0.0,
),
), ),
), SizedBox(width: 145.rpx),
].divide(SizedBox(height: 37.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) {}, 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/model/BleDeviceData.dart';
import 'package:vbvs_app/pages/device_bind/componnet/FancyCircleCheckbox.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(); ThemeController themeController = Get.find();
BlueteethBindController blueteethBindController = Get.find(); BlueteethBindController blueteethBindController = Get.find();
// 初始化默认选中 deviceIndex0 为 true
blueteethBindController.model.deviceIndex0 = true; blueteethBindController.model.deviceIndex0 = true;
blueteethBindController.model.deviceIndex1 = false; blueteethBindController.model.deviceIndex1 = false;
blueteethBindController.model.deviceIndex2 = false; blueteethBindController.model.deviceIndex2 = false;
@@ -25,7 +31,7 @@ void showBindDoubleDialog(BuildContext context, List<BleDeviceData> devices) {
showDialog( showDialog(
context: context, context: context,
barrierDismissible: true, barrierDismissible: true,
barrierColor: Colors.black.withOpacity(0.5), // 建议加个背景模糊色 barrierColor: Colors.black.withOpacity(0.5),
builder: (BuildContext context) { builder: (BuildContext context) {
return FrostedDialog( return FrostedDialog(
blurSigma: 3.0, blurSigma: 3.0,
@@ -34,7 +40,7 @@ void showBindDoubleDialog(BuildContext context, List<BleDeviceData> devices) {
color: themeController.currentColor.sc17, color: themeController.currentColor.sc17,
borderRadius: BorderRadius.circular(20.0), 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( child: Container(
width: double.infinity, width: double.infinity,
constraints: BoxConstraints( constraints: BoxConstraints(
@@ -47,8 +53,7 @@ void showBindDoubleDialog(BuildContext context, List<BleDeviceData> devices) {
Align( Align(
alignment: AlignmentDirectional(0, 0), alignment: AlignmentDirectional(0, 0),
child: Padding( child: Padding(
padding: padding: EdgeInsetsDirectional.fromSTEB(0.rpx, 93.rpx, 0, 0),
EdgeInsetsDirectional.fromSTEB(0.rpx, 93.rpx, 0, 0),
child: Text( child: Text(
'蓝牙绑定.双人版绑定标题'.tr, '蓝牙绑定.双人版绑定标题'.tr,
style: FlutterFlowTheme.of(context).bodyMedium.override( style: FlutterFlowTheme.of(context).bodyMedium.override(
@@ -67,9 +72,9 @@ void showBindDoubleDialog(BuildContext context, List<BleDeviceData> devices) {
value: () => blueteethBindController.model.deviceIndex0!, value: () => blueteethBindController.model.deviceIndex0!,
onChanged: (v) { onChanged: (v) {
if (!blueteethBindController.model.deviceIndex0!) { if (!blueteethBindController.model.deviceIndex0!) {
blueteethBindController.model.deviceIndex0 = v; blueteethBindController.model.deviceIndex0 = true;
blueteethBindController.model.deviceIndex1 = !v; blueteethBindController.model.deviceIndex1 = false;
blueteethBindController.model.deviceIndex2 = !v; blueteethBindController.model.deviceIndex2 = false;
blueteethBindController.updateAll(); blueteethBindController.updateAll();
} }
}, },
@@ -77,13 +82,15 @@ void showBindDoubleDialog(BuildContext context, List<BleDeviceData> devices) {
// 主设备 // 主设备
_buildCheckboxRow( _buildCheckboxRow(
context, context,
title: '蓝牙绑定.主设备'.tr + "asasasasasas(已被绑定)", title: '蓝牙绑定.主设备'.tr +
"${devices[0].mac}" +
(devices[0].bind == false ? "可绑定".tr : "已被绑定".tr),
value: () => blueteethBindController.model.deviceIndex1!, value: () => blueteethBindController.model.deviceIndex1!,
onChanged: (v) { onChanged: (v) {
if (!blueteethBindController.model.deviceIndex1!) { if (!blueteethBindController.model.deviceIndex1!) {
blueteethBindController.model.deviceIndex1 = v; blueteethBindController.model.deviceIndex0 = false;
blueteethBindController.model.deviceIndex0 = !v; blueteethBindController.model.deviceIndex1 = true;
blueteethBindController.model.deviceIndex2 = !v; blueteethBindController.model.deviceIndex2 = false;
blueteethBindController.updateAll(); blueteethBindController.updateAll();
} }
}, },
@@ -91,36 +98,46 @@ void showBindDoubleDialog(BuildContext context, List<BleDeviceData> devices) {
// 从设备 // 从设备
_buildCheckboxRow( _buildCheckboxRow(
context, context,
title: '蓝牙绑定.从设备'.tr, title: '蓝牙绑定.从设备'.tr +
"${devices[1].mac}" +
(devices[1].bind == false ? "可绑定".tr : "已被绑定".tr),
value: () => blueteethBindController.model.deviceIndex2!, value: () => blueteethBindController.model.deviceIndex2!,
onChanged: (v) { onChanged: (v) {
if (!blueteethBindController.model.deviceIndex2!) { if (!blueteethBindController.model.deviceIndex2!) {
blueteethBindController.model.deviceIndex2 = v; blueteethBindController.model.deviceIndex0 = false;
blueteethBindController.model.deviceIndex0 = !v; blueteethBindController.model.deviceIndex1 = false;
blueteethBindController.model.deviceIndex1 = !v; blueteethBindController.model.deviceIndex2 = true;
blueteethBindController.updateAll(); blueteethBindController.updateAll();
} }
}, },
), ),
// 确定按钮 // 确定按钮
Padding( Padding(
padding: EdgeInsetsDirectional.fromSTEB(0, 100.rpx, 0, 0), padding: EdgeInsetsDirectional.fromSTEB(60.rpx, 100.rpx, 60.rpx, 0),
child: _buildActionButton( child: _buildActionButton(
context, context,
text: '蓝牙绑定.确定'.tr, text: '蓝牙绑定.确定'.tr,
onTap: () { onTap: () {
Get.back(); Get.back();
int selectedIndex = blueteethBindController.model.deviceIndex0!
? 0
: (blueteethBindController.model.deviceIndex1! ? 1 : 2);
onConfirm(selectedIndex);
}, },
), ),
), ),
// 取消按钮 // 取消按钮
Padding( Padding(
padding: EdgeInsetsDirectional.fromSTEB(0, 19.rpx, 0, 60.rpx), padding: EdgeInsetsDirectional.fromSTEB(60.rpx, 19.rpx, 60.rpx, 60.rpx),
child: _buildActionButton( child: _buildActionButton(
context, context,
text: '蓝牙绑定.取消'.tr, text: '蓝牙绑定.取消'.tr,
onTap: () { onTap: () {
Get.back(); Get.back();
onCancel();
}, },
), ),
), ),
@@ -133,6 +150,7 @@ void showBindDoubleDialog(BuildContext context, List<BleDeviceData> devices) {
); );
} }
Future<void> showHaveBindDialog(BuildContext context) async { Future<void> showHaveBindDialog(BuildContext context) async {
ThemeController themeController = Get.find(); ThemeController themeController = Get.find();
@@ -339,7 +357,7 @@ Widget _buildCheckboxRow(
}) { }) {
ThemeController themeController = Get.find(); ThemeController themeController = Get.find();
return Padding( 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( child: Row(
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
children: [ children: [
@@ -350,14 +368,47 @@ Widget _buildCheckboxRow(
onChanged: onChanged, onChanged: onChanged,
)), )),
Expanded( Expanded(
child: Text( child: Builder(
title, builder: (_) {
style: FlutterFlowTheme.of(context).bodyMedium.override( final bool isBindable = title.contains('可绑定'.tr);
fontFamily: 'Inter', final bool isBound = title.contains('已被绑定'.tr);
letterSpacing: 0.0,
fontSize: AppConstants().normal_text_fontSize, // 提取主文本部分
color: themeController.currentColor.sc3, 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)), ].divide(SizedBox(width: 21.rpx)),
@@ -374,10 +425,12 @@ Widget _buildActionButton(
return CustomCard( return CustomCard(
borderRadius: AppConstants().button_container_radius, borderRadius: AppConstants().button_container_radius,
onTap: onTap, onTap: onTap,
colors: [ colors: '蓝牙绑定.确定'.tr == text
themeController.currentColor.sc1, ? [
themeController.currentColor.sc2, themeController.currentColor.sc1,
], themeController.currentColor.sc2,
]
: [Colors.transparent],
child: Container( child: Container(
width: MediaQuery.sizeOf(context).width, width: MediaQuery.sizeOf(context).width,
height: MediaQuery.sizeOf(context).height * 0.055, height: MediaQuery.sizeOf(context).height * 0.055,
@@ -385,6 +438,15 @@ Widget _buildActionButton(
minWidth: 500.rpx, minWidth: 500.rpx,
minHeight: 90.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( child: Row(
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,

View File

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