1035 lines
48 KiB
Dart
1035 lines
48 KiB
Dart
import 'dart:async';
|
||
|
||
import 'package:EasyDartModule/EasyDartModule.dart' as edm;
|
||
import 'package:ef/ef.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter_svg/svg.dart';
|
||
import 'package:flutterflow_ui/flutterflow_ui.dart';
|
||
import 'package:vbvs_app/common/color/ServiceConstant.dart';
|
||
import 'package:vbvs_app/common/color/appConstants.dart';
|
||
import 'package:vbvs_app/common/util/FitTool.dart';
|
||
import 'package:vbvs_app/common/util/MyUtils.dart';
|
||
import 'package:vbvs_app/common/util/requestWithLog.dart';
|
||
import 'package:vbvs_app/component/base/GradientSwitch.dart';
|
||
import 'package:vbvs_app/component/tool/ClickableContainer.dart';
|
||
import 'package:vbvs_app/component/tool/NewTopSlideNotification.dart';
|
||
import 'package:vbvs_app/component/tool/TopSlideNotification.dart';
|
||
import 'package:vbvs_app/controller/message/common_message_setting_controller.dart';
|
||
import 'package:vbvs_app/controller/message/message_setting_controller.dart';
|
||
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
|
||
|
||
//消息总配置
|
||
class MessageSettingPage extends StatefulWidget {
|
||
var data;
|
||
MessageSettingPage({super.key, required this.data});
|
||
|
||
@override
|
||
State<MessageSettingPage> createState() => _MessageSettingPageState();
|
||
}
|
||
|
||
class _MessageSettingPageState extends State<MessageSettingPage> {
|
||
final ThemeController themeController = Get.find();
|
||
MessageSettingController messageSettingController = Get.find();
|
||
CommonMessageSettingController commonMessageSettingController = Get.find();
|
||
|
||
@override
|
||
void initState() {
|
||
super.initState();
|
||
_fetchCommonMessageSetting();
|
||
_fetchDeviceMessageSetting();
|
||
_fetchMessageCommonConfig();
|
||
//todo 查询用户自定义配置
|
||
//todo 查询用户总配置
|
||
}
|
||
|
||
Future<void> _fetchCommonMessageSetting() async {
|
||
String serviceAddress = ServiceConstant.service_address;
|
||
String serviceName = ServiceConstant.server_service;
|
||
String serviceApi = ServiceConstant.user_setting;
|
||
String type = "user_message_setting";
|
||
String queryUrl = "${serviceAddress}${serviceName}${serviceApi}?type=$type";
|
||
requestWithLog(
|
||
logTitle: "查询用户消息配置1",
|
||
method: MyHttpMethod.get,
|
||
queryUrl: queryUrl,
|
||
onSuccess: (res) {
|
||
if (res.data == null || res.data.isEmpty) {
|
||
var data = {
|
||
"type": type,
|
||
"setting": 1,
|
||
"appSetting": 1,
|
||
"serviceSetting": 1,
|
||
"tipSetting": 1,
|
||
"deviceUpgradeSetting": 1,
|
||
"deviceIssueSetting": 1,
|
||
"telSetting": 1,
|
||
"smsSetting": 1,
|
||
};
|
||
requestWithLog(
|
||
logTitle: "更新用户消息配置",
|
||
method: MyHttpMethod.put,
|
||
queryUrl: queryUrl,
|
||
data: data,
|
||
onSuccess: (res) {
|
||
requestWithLog(
|
||
logTitle: "查询用户消息配置2",
|
||
method: MyHttpMethod.get,
|
||
queryUrl: queryUrl,
|
||
onSuccess: (res) {
|
||
if (res.data != null) {
|
||
var datalist = res.data;
|
||
commonMessageSettingController.model.setting =
|
||
datalist['setting'];
|
||
commonMessageSettingController.model.appSetting =
|
||
datalist['appSetting'];
|
||
commonMessageSettingController.model.serviceSetting =
|
||
datalist['serviceSetting'];
|
||
commonMessageSettingController.model.tipSetting =
|
||
datalist['tipSetting'];
|
||
commonMessageSettingController.model.deviceUpgradeSetting =
|
||
datalist['deviceUpgradeSetting'];
|
||
commonMessageSettingController.model.deviceIssueSetting =
|
||
datalist['deviceIssueSetting'];
|
||
commonMessageSettingController.model.telSetting =
|
||
datalist['telSetting'];
|
||
commonMessageSettingController.model.smsSetting =
|
||
datalist['smsSetting'];
|
||
commonMessageSettingController.updateAll();
|
||
}
|
||
},
|
||
);
|
||
},
|
||
);
|
||
} else {
|
||
var datalist = res.data;
|
||
commonMessageSettingController.model.setting = datalist['setting'];
|
||
commonMessageSettingController.model.appSetting =
|
||
datalist['appSetting'];
|
||
commonMessageSettingController.model.serviceSetting =
|
||
datalist['serviceSetting'];
|
||
commonMessageSettingController.model.tipSetting =
|
||
datalist['tipSetting'];
|
||
commonMessageSettingController.model.deviceUpgradeSetting =
|
||
datalist['deviceUpgradeSetting'];
|
||
commonMessageSettingController.model.deviceIssueSetting =
|
||
datalist['deviceIssueSetting'];
|
||
commonMessageSettingController.model.telSetting =
|
||
datalist['telSetting'];
|
||
commonMessageSettingController.model.smsSetting =
|
||
datalist['smsSetting'];
|
||
commonMessageSettingController.updateAll();
|
||
}
|
||
},
|
||
onFailure: (res) {
|
||
print(res);
|
||
},
|
||
);
|
||
}
|
||
|
||
Future<void> _fetchDeviceMessageSetting() async {
|
||
String serviceAddress = ServiceConstant.service_address;
|
||
String serviceName = ServiceConstant.server_service;
|
||
String serviceApi = ServiceConstant.user_setting;
|
||
String mac = widget.data['mac'];
|
||
String type = "user_device_message_setting_$mac";
|
||
String queryUrl = "${serviceAddress}${serviceName}${serviceApi}?type=$type";
|
||
requestWithLog(
|
||
logTitle: "查询用户消息配置3",
|
||
method: MyHttpMethod.get,
|
||
queryUrl: queryUrl,
|
||
onSuccess: (res) {
|
||
if (res.data == null) {
|
||
var data = {
|
||
"type": type,
|
||
"setting": 1,
|
||
"appSetting": 1,
|
||
"serviceSetting": 1,
|
||
};
|
||
requestWithLog(
|
||
logTitle: "更新用户消息配置",
|
||
method: MyHttpMethod.put,
|
||
queryUrl: queryUrl,
|
||
data: data,
|
||
onSuccess: (res) {
|
||
requestWithLog(
|
||
logTitle: "查询用户消息配置4",
|
||
method: MyHttpMethod.get,
|
||
queryUrl: queryUrl,
|
||
onSuccess: (res) {
|
||
if (res.data != null && res.data.isNotEmpty) {
|
||
var datalist = res.data;
|
||
messageSettingController.model.setting =
|
||
datalist['setting'];
|
||
messageSettingController.model.appSetting =
|
||
datalist['appSetting'];
|
||
messageSettingController.model.serviceSetting =
|
||
datalist['serviceSetting'];
|
||
messageSettingController.updateAll();
|
||
}
|
||
},
|
||
);
|
||
|
||
//
|
||
},
|
||
);
|
||
} else {
|
||
var datalist = res.data;
|
||
messageSettingController.model.setting = datalist['setting'];
|
||
messageSettingController.model.appSetting = datalist['appSetting'];
|
||
messageSettingController.model.serviceSetting =
|
||
datalist['serviceSetting'];
|
||
|
||
if (datalist['device_type_setting'] != null) {
|
||
messageSettingController.model.device_type_setting =
|
||
datalist['device_type_setting'];
|
||
} else {
|
||
messageSettingController.model.device_type_setting.clear();
|
||
}
|
||
messageSettingController.updateAll();
|
||
}
|
||
},
|
||
onFailure: (res) {
|
||
print(res);
|
||
},
|
||
);
|
||
}
|
||
|
||
@override
|
||
void dispose() {
|
||
super.dispose();
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return LayoutBuilder(
|
||
builder: (context, bodysize) => GestureDetector(
|
||
// onTap: () => FocusScope.of(context).unfocus(),,
|
||
child: Container(
|
||
decoration: BoxDecoration(
|
||
image: DecorationImage(
|
||
image: AssetImage('assets/img/bgNoImg.png'),
|
||
fit: BoxFit.fill,
|
||
),
|
||
),
|
||
child: Scaffold(
|
||
backgroundColor: Colors.transparent,
|
||
appBar: AppBar(
|
||
backgroundColor: themeController.currentColor.sc17,
|
||
automaticallyImplyLeading: false,
|
||
iconTheme: IconThemeData(
|
||
color: themeController.currentColor.sc3,
|
||
),
|
||
titleSpacing: 0,
|
||
title: Container(
|
||
width: double.infinity,
|
||
height: 180.rpx,
|
||
child: Stack(
|
||
alignment: Alignment.center,
|
||
children: [
|
||
/// 居中标题
|
||
Text(
|
||
'消息设置'.tr,
|
||
style: TextStyle(
|
||
fontFamily: 'ReadexPro',
|
||
color: themeController.currentColor.sc3,
|
||
letterSpacing: 0,
|
||
fontSize: 30.rpx,
|
||
),
|
||
),
|
||
Positioned(
|
||
left: 0,
|
||
child: returnIconButtomAddCallback(() {}),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
actions: [],
|
||
centerTitle: false,
|
||
),
|
||
body: GestureDetector(
|
||
child: SafeArea(
|
||
top: true,
|
||
child: Padding(
|
||
padding: EdgeInsetsDirectional.fromSTEB(0.rpx, 0, 0.rpx, 0),
|
||
child: Column(
|
||
mainAxisSize: MainAxisSize.min,
|
||
children: [
|
||
Padding(
|
||
padding:
|
||
EdgeInsetsDirectional.fromSTEB(0, 30.rpx, 0, 0),
|
||
child: Container(
|
||
width: double.infinity,
|
||
constraints: BoxConstraints(
|
||
minHeight: 90.rpx,
|
||
),
|
||
decoration: BoxDecoration(
|
||
color: themeController.currentColor.sc5),
|
||
child: Padding(
|
||
padding: EdgeInsetsDirectional.fromSTEB(
|
||
30.rpx, 15.rpx, 30.rpx, 15.rpx),
|
||
child: Row(
|
||
mainAxisSize: MainAxisSize.max,
|
||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
children: [
|
||
Expanded(
|
||
child: Text(
|
||
"消息提醒设置".tr,
|
||
style: TextStyle(
|
||
color: themeController.currentColor.sc3,
|
||
fontSize:
|
||
AppConstants().title_text_fontSize),
|
||
),
|
||
),
|
||
Obx(() {
|
||
return GradientSwitch(
|
||
value: commonMessageSettingController
|
||
.model.setting ==
|
||
1
|
||
? (messageSettingController
|
||
.model.setting ==
|
||
1
|
||
? true
|
||
: false)
|
||
: false,
|
||
onChanged: (val) {
|
||
if (commonMessageSettingController
|
||
.model.setting ==
|
||
0) {
|
||
TopSlideNotification.show(context,
|
||
text: "请先在设置里的消息通知打开全部消息配置".tr,
|
||
textColor: themeController
|
||
.currentColor.sc9);
|
||
return;
|
||
}
|
||
String serviceAddress =
|
||
ServiceConstant.service_address;
|
||
String serviceName =
|
||
ServiceConstant.server_service;
|
||
String serviceApi =
|
||
ServiceConstant.user_setting;
|
||
String mac = widget.data['mac'];
|
||
String type =
|
||
"user_device_message_setting_$mac";
|
||
String queryUrl =
|
||
"${serviceAddress}${serviceName}${serviceApi}";
|
||
var data = {
|
||
"type": type,
|
||
"setting": val == true ? 1 : 0,
|
||
"appSetting": messageSettingController
|
||
.model.appSetting,
|
||
"serviceSetting":
|
||
messageSettingController
|
||
.model.serviceSetting,
|
||
};
|
||
requestWithLog(
|
||
logTitle: "更新消息推送状态",
|
||
method: MyHttpMethod.put,
|
||
queryUrl: queryUrl,
|
||
data: data,
|
||
onSuccess: (res) {
|
||
_fetchDeviceMessageSetting();
|
||
messageSettingController.updateAll();
|
||
},
|
||
onFailure: (res) {
|
||
NewTopSlideNotification.show(
|
||
text: '操作失败'.tr,
|
||
textColor: themeController
|
||
.currentColor.sc9);
|
||
},
|
||
);
|
||
},
|
||
activeGradient: LinearGradient(
|
||
colors: [
|
||
themeController.currentColor.sc1,
|
||
themeController.currentColor.sc2
|
||
],
|
||
),
|
||
activeThumbColor: Colors.white,
|
||
inactiveThumbColor:
|
||
stringToColor("#A2A4A9"),
|
||
inactiveColor: stringToColor("#161B28"),
|
||
);
|
||
}),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
),
|
||
// Padding(
|
||
// padding: EdgeInsetsDirectional.fromSTEB(
|
||
// 30.rpx, 21.rpx, 30.rpx, 0),
|
||
// child: Container(
|
||
// decoration: BoxDecoration(
|
||
// color: themeController.currentColor.sc5,
|
||
// borderRadius: BorderRadius.circular(
|
||
// AppConstants().normal_container_radius),
|
||
// ),
|
||
// child: Padding(
|
||
// padding: EdgeInsetsDirectional.fromSTEB(
|
||
// 30.rpx, 40.rpx, 30.rpx, 54.rpx),
|
||
// child: Container(
|
||
// child: Column(
|
||
// crossAxisAlignment: CrossAxisAlignment.start,
|
||
// children: [
|
||
// Row(
|
||
// mainAxisSize: MainAxisSize.max,
|
||
// mainAxisAlignment:
|
||
// MainAxisAlignment.spaceBetween,
|
||
// children: [
|
||
// Expanded(
|
||
// child: Text(
|
||
// "APP消息".tr,
|
||
// style: TextStyle(
|
||
// color: themeController
|
||
// .currentColor.sc3,
|
||
// fontSize: AppConstants()
|
||
// .title_text_fontSize),
|
||
// ),
|
||
// ),
|
||
// Obx(() {
|
||
// return GradientSwitch(
|
||
// value: commonMessageSettingController
|
||
// .model.setting ==
|
||
// 1
|
||
// ? (messageSettingController
|
||
// .model.setting ==
|
||
// 1
|
||
// ? (messageSettingController
|
||
// .model
|
||
// .appSetting ==
|
||
// 1
|
||
// ? true
|
||
// : false)
|
||
// : false)
|
||
// : false,
|
||
// onChanged: (val) {
|
||
// if (commonMessageSettingController
|
||
// .model.setting ==
|
||
// 0) {
|
||
// TopSlideNotification.show(context,
|
||
// text:
|
||
// "请先在设置里的消息通知打开全部消息配置".tr,
|
||
// textColor: themeController
|
||
// .currentColor.sc9);
|
||
// return;
|
||
// }
|
||
// if (messageSettingController
|
||
// .model.setting ==
|
||
// 0) {
|
||
// TopSlideNotification.show(context,
|
||
// text: "请先打开消息提醒设置".tr,
|
||
// textColor: themeController
|
||
// .currentColor.sc9);
|
||
// return;
|
||
// }
|
||
// String serviceAddress =
|
||
// ServiceConstant.service_address;
|
||
// String serviceName =
|
||
// ServiceConstant.server_service;
|
||
// String serviceApi =
|
||
// ServiceConstant.user_setting;
|
||
// String mac = widget.data['mac'];
|
||
// String type =
|
||
// "user_device_message_setting_$mac";
|
||
// String queryUrl =
|
||
// "${serviceAddress}${serviceName}${serviceApi}";
|
||
// var data = {
|
||
// "type": type,
|
||
// "setting":
|
||
// messageSettingController
|
||
// .model.setting,
|
||
// "appSetting": val == true ? 1 : 0,
|
||
// "serviceSetting":
|
||
// messageSettingController
|
||
// .model.serviceSetting,
|
||
// };
|
||
// requestWithLog(
|
||
// logTitle: "更新消息推送状态",
|
||
// method: MyHttpMethod.put,
|
||
// queryUrl: queryUrl,
|
||
// data: data,
|
||
// onSuccess: (res) {
|
||
// _fetchDeviceMessageSetting();
|
||
// messageSettingController
|
||
// .updateAll();
|
||
// });
|
||
// },
|
||
// activeGradient: LinearGradient(
|
||
// colors: [
|
||
// themeController.currentColor.sc1,
|
||
// themeController.currentColor.sc2
|
||
// ],
|
||
// ),
|
||
// activeThumbColor: Colors.white,
|
||
// inactiveThumbColor:
|
||
// stringToColor("#A2A4A9"),
|
||
// inactiveColor:
|
||
// stringToColor("#161B28"),
|
||
// );
|
||
// }),
|
||
// ],
|
||
// ),
|
||
// Text(
|
||
// "APP消息介绍".tr,
|
||
// style: TextStyle(
|
||
// color: themeController.currentColor.sc4,
|
||
// fontSize: AppConstants()
|
||
// .normal_text_fontSize),
|
||
// ),
|
||
// Row(
|
||
// mainAxisSize: MainAxisSize.max,
|
||
// mainAxisAlignment:
|
||
// MainAxisAlignment.spaceBetween,
|
||
// children: [
|
||
// Expanded(
|
||
// child: Text(
|
||
// "服务号消息".tr,
|
||
// style: TextStyle(
|
||
// color: themeController
|
||
// .currentColor.sc3,
|
||
// fontSize: AppConstants()
|
||
// .title_text_fontSize),
|
||
// ),
|
||
// ),
|
||
// Obx(() {
|
||
// return GradientSwitch(
|
||
// value: commonMessageSettingController
|
||
// .model.setting ==
|
||
// 1
|
||
// ? (messageSettingController
|
||
// .model.setting ==
|
||
// 1
|
||
// ? (messageSettingController
|
||
// .model
|
||
// .serviceSetting ==
|
||
// 1
|
||
// ? true
|
||
// : false)
|
||
// : false)
|
||
// : false,
|
||
// onChanged: (val) {
|
||
// if (commonMessageSettingController
|
||
// .model.setting ==
|
||
// 0) {
|
||
// TopSlideNotification.show(context,
|
||
// text:
|
||
// "请先在设置里的消息通知打开全部消息配置".tr,
|
||
// textColor: themeController
|
||
// .currentColor.sc9);
|
||
// return;
|
||
// }
|
||
// if (messageSettingController
|
||
// .model.setting ==
|
||
// 0) {
|
||
// TopSlideNotification.show(context,
|
||
// text: "请先打开消息提醒设置".tr,
|
||
// textColor: themeController
|
||
// .currentColor.sc9);
|
||
// return;
|
||
// }
|
||
// String serviceAddress =
|
||
// ServiceConstant.service_address;
|
||
// String serviceName =
|
||
// ServiceConstant.server_service;
|
||
// String serviceApi =
|
||
// ServiceConstant.user_setting;
|
||
// String mac = widget.data['mac'];
|
||
// String type =
|
||
// "user_device_message_setting_$mac";
|
||
// String queryUrl =
|
||
// "${serviceAddress}${serviceName}${serviceApi}";
|
||
// var data = {
|
||
// "type": type,
|
||
// "setting":
|
||
// messageSettingController
|
||
// .model.setting,
|
||
// "appSetting":
|
||
// messageSettingController
|
||
// .model.appSetting,
|
||
// "serviceSetting":
|
||
// val == true ? 1 : 0,
|
||
// };
|
||
// requestWithLog(
|
||
// logTitle: "更新消息推送状态",
|
||
// method: MyHttpMethod.put,
|
||
// queryUrl: queryUrl,
|
||
// data: data,
|
||
// onSuccess: (res) {
|
||
// _fetchDeviceMessageSetting();
|
||
// messageSettingController
|
||
// .updateAll();
|
||
// });
|
||
// },
|
||
// activeGradient: LinearGradient(
|
||
// colors: [
|
||
// themeController.currentColor.sc1,
|
||
// themeController.currentColor.sc2
|
||
// ],
|
||
// ),
|
||
// activeThumbColor: Colors.white,
|
||
// inactiveThumbColor:
|
||
// stringToColor("#A2A4A9"),
|
||
// inactiveColor:
|
||
// stringToColor("#161B28"),
|
||
// );
|
||
// }),
|
||
// ],
|
||
// ),
|
||
// Text(
|
||
// "服务号消息介绍".tr,
|
||
// style: TextStyle(
|
||
// color: themeController.currentColor.sc4,
|
||
// fontSize: AppConstants()
|
||
// .normal_text_fontSize),
|
||
// ),
|
||
// ].divide(SizedBox(
|
||
// height: 49.rpx,
|
||
// )),
|
||
// ),
|
||
// ),
|
||
// ),
|
||
// ),
|
||
// ),
|
||
Obx(() {
|
||
if (messageSettingController
|
||
.messageType.value.isEmpty) {
|
||
return Container();
|
||
}
|
||
return Expanded(
|
||
child: SingleChildScrollView(
|
||
child: Column(
|
||
children: getMessageTypeList(
|
||
messageSettingController.messageType.value,
|
||
widget.data),
|
||
),
|
||
));
|
||
})
|
||
],
|
||
),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
void _fetchMessageCommonConfig() {
|
||
String serviceAddress = ServiceConstant.service_address;
|
||
String serviceName = ServiceConstant.server_service;
|
||
String serviceApi = ServiceConstant.user_setting;
|
||
String type = "alarmType";
|
||
String queryUrl = "${serviceAddress}${serviceName}${serviceApi}?type=$type";
|
||
requestWithLog(
|
||
logTitle: "查询用户消息配置5",
|
||
method: MyHttpMethod.get,
|
||
queryUrl: queryUrl,
|
||
onSuccess: (res) {
|
||
if (res.data != null) {
|
||
messageSettingController.messageType.value = res.data;
|
||
ef.log("查询用户消息配置成功");
|
||
messageSettingController.updateAll();
|
||
}
|
||
},
|
||
onFailure: (res) {
|
||
print(res);
|
||
},
|
||
);
|
||
}
|
||
|
||
getMessageTypeList(Map<String, dynamic> data, Map deviceData) {
|
||
try {
|
||
List<Widget> list = [];
|
||
if (data.containsKey("real") && data["real"] is List) {
|
||
// 首先添加容器装饰
|
||
list.add(
|
||
SizedBox(height: 30.rpx),
|
||
);
|
||
list.add(
|
||
Padding(
|
||
padding: EdgeInsets.fromLTRB(40.rpx, 0, 40.rpx, 0),
|
||
child: Container(
|
||
decoration: BoxDecoration(
|
||
borderRadius: BorderRadius.circular(
|
||
AppConstants().normal_container_radius),
|
||
color: themeController.currentColor.sc17,
|
||
),
|
||
child: Column(
|
||
children: [
|
||
Padding(
|
||
padding: EdgeInsetsDirectional.fromSTEB(
|
||
30.rpx, 40.rpx, 30.rpx, 20.rpx),
|
||
child: Row(
|
||
mainAxisAlignment: MainAxisAlignment.start,
|
||
children: [
|
||
Text(
|
||
"实时体征消息".tr,
|
||
style: TextStyle(
|
||
fontFamily: 'Inter',
|
||
color: themeController.currentColor.sc3,
|
||
fontSize: AppConstants().title_text_fontSize,
|
||
letterSpacing: 0.0,
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
// 动态生成每个数据项
|
||
for (int i = 0; i < (data["real"] as List).length; i++)
|
||
if ((data["real"] as List)[i] is Map &&
|
||
(data["real"] as List)[i].containsKey("name"))
|
||
Padding(
|
||
padding: EdgeInsetsDirectional.fromSTEB(
|
||
30.rpx,
|
||
i == 0 ? 20.rpx : 0, // 第一个元素顶部有20.rpx间距
|
||
30.rpx,
|
||
i == (data["real"] as List).length - 1
|
||
? 20.rpx
|
||
: 0.rpx),
|
||
child: ClickableContainer(
|
||
backgroundColor: Colors.transparent,
|
||
highlightColor: themeController.currentColor.sc21,
|
||
padding: EdgeInsetsDirectional.fromSTEB(
|
||
0.rpx, 0.rpx, 0.rpx, 0.rpx),
|
||
onTap: () async {
|
||
var item = (data["real"] as List)[i];
|
||
item['device'] = deviceData;
|
||
Get.toNamed('/singleMessageSetting',
|
||
arguments: item);
|
||
},
|
||
child: Container(
|
||
child: Padding(
|
||
padding: EdgeInsetsDirectional.fromSTEB(
|
||
0.rpx, 30.rpx, 0.rpx, 30.rpx),
|
||
child: Row(
|
||
mainAxisSize: MainAxisSize.max,
|
||
mainAxisAlignment:
|
||
MainAxisAlignment.spaceBetween,
|
||
children: [
|
||
Row(
|
||
mainAxisSize: MainAxisSize.max,
|
||
children: [
|
||
Text(
|
||
"${((data["real"] as List)[i]["name"] ?? "")}"
|
||
.tr,
|
||
style: TextStyle(
|
||
fontFamily: 'Inter',
|
||
color:
|
||
themeController.currentColor.sc3,
|
||
fontSize: AppConstants()
|
||
.title_text_fontSize,
|
||
letterSpacing: 0.0,
|
||
),
|
||
),
|
||
].divide(SizedBox(width: 22.rpx)),
|
||
),
|
||
Row(
|
||
mainAxisSize: MainAxisSize.max,
|
||
children: [
|
||
// 可以根据需要显示其他数据
|
||
Text(
|
||
"${getSwitchStatus((data["real"] as List)[i], widget.data)}"
|
||
.tr, // 这里可以显示其他信息,比如: (data["real"] as List)[i]["value"] ?? ""
|
||
style: TextStyle(
|
||
fontFamily: 'Inter',
|
||
color: getSwitchStatusValue(
|
||
(data["real"] as List)[i],
|
||
widget.data) ==
|
||
1
|
||
? themeController.currentColor.sc2
|
||
: themeController
|
||
.currentColor.sc9,
|
||
fontSize: 26.rpx,
|
||
letterSpacing: 0.0,
|
||
),
|
||
),
|
||
SvgPicture.asset(
|
||
'assets/img/icon/arrow_right.svg',
|
||
width: 8.rpx,
|
||
height: 15.rpx,
|
||
color: themeController.currentColor.sc3,
|
||
),
|
||
].divide(SizedBox(width: 28.rpx)),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
if (data.containsKey("report")) {
|
||
list.add(
|
||
SizedBox(height: 30.rpx),
|
||
);
|
||
list.add(
|
||
Padding(
|
||
padding: EdgeInsets.fromLTRB(40.rpx, 0, 40.rpx, 0),
|
||
child: Container(
|
||
decoration: BoxDecoration(
|
||
borderRadius: BorderRadius.circular(
|
||
AppConstants().normal_container_radius),
|
||
color: themeController.currentColor.sc17,
|
||
),
|
||
child: Column(
|
||
children: [
|
||
Padding(
|
||
padding: EdgeInsetsDirectional.fromSTEB(
|
||
30.rpx, 40.rpx, 30.rpx, 20.rpx),
|
||
child: Row(
|
||
mainAxisAlignment: MainAxisAlignment.start,
|
||
children: [
|
||
Text(
|
||
"睡眠报告消息".tr,
|
||
style: TextStyle(
|
||
fontFamily: 'Inter',
|
||
color: themeController.currentColor.sc3,
|
||
fontSize: AppConstants().title_text_fontSize,
|
||
letterSpacing: 0.0,
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
// 动态生成每个数据项
|
||
for (int i = 0; i < (data["report"] as List).length; i++)
|
||
if ((data["report"] as List)[i] is Map &&
|
||
(data["report"] as List)[i].containsKey("name"))
|
||
Padding(
|
||
padding: EdgeInsetsDirectional.fromSTEB(
|
||
30.rpx,
|
||
i == 0 ? 20.rpx : 0, // 第一个元素顶部有20.rpx间距
|
||
30.rpx,
|
||
i == (data["report"] as List).length - 1
|
||
? 20.rpx
|
||
: 0.rpx),
|
||
child: ClickableContainer(
|
||
backgroundColor: Colors.transparent,
|
||
highlightColor: themeController.currentColor.sc21,
|
||
padding: EdgeInsetsDirectional.fromSTEB(
|
||
0.rpx, 0.rpx, 0.rpx, 0.rpx),
|
||
onTap: () async {
|
||
var item = (data["report"] as List)[i];
|
||
item['device'] = deviceData;
|
||
Get.toNamed(
|
||
'/singleMessageSetting',
|
||
arguments: item,
|
||
);
|
||
},
|
||
child: Container(
|
||
child: Padding(
|
||
padding: EdgeInsetsDirectional.fromSTEB(
|
||
0.rpx, 30.rpx, 0.rpx, 30.rpx),
|
||
child: Row(
|
||
mainAxisSize: MainAxisSize.max,
|
||
mainAxisAlignment:
|
||
MainAxisAlignment.spaceBetween,
|
||
children: [
|
||
Row(
|
||
mainAxisSize: MainAxisSize.max,
|
||
children: [
|
||
Text(
|
||
"${((data["report"] as List)[i]["name"] ?? "")}"
|
||
.tr,
|
||
style: TextStyle(
|
||
fontFamily: 'Inter',
|
||
color:
|
||
themeController.currentColor.sc3,
|
||
fontSize: AppConstants()
|
||
.title_text_fontSize,
|
||
letterSpacing: 0.0,
|
||
),
|
||
),
|
||
].divide(SizedBox(width: 22.rpx)),
|
||
),
|
||
Row(
|
||
mainAxisSize: MainAxisSize.max,
|
||
children: [
|
||
// 可以根据需要显示其他数据
|
||
Text(
|
||
"${getSwitchStatus((data["report"] as List)[i], widget.data)}"
|
||
.tr, // 这里可以显示其他信息,比如: (data["real"] as List)[i]["value"] ?? ""// 这里可以显示其他信息,比如: (data["real"] as List)[i]["value"] ?? ""
|
||
style: TextStyle(
|
||
fontFamily: 'Inter',
|
||
color: getSwitchStatusValue(
|
||
(data["report"]
|
||
as List)[i],
|
||
widget.data) ==
|
||
1
|
||
? themeController.currentColor.sc2
|
||
: themeController
|
||
.currentColor.sc9,
|
||
fontSize: 26.rpx,
|
||
letterSpacing: 0.0,
|
||
),
|
||
),
|
||
SvgPicture.asset(
|
||
'assets/img/icon/arrow_right.svg',
|
||
width: 8.rpx,
|
||
height: 15.rpx,
|
||
color: themeController.currentColor.sc3,
|
||
),
|
||
].divide(SizedBox(width: 28.rpx)),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
if (list.length > 0) {
|
||
list = [
|
||
...list, // 使用 ... 展开原列表的所有元素
|
||
SizedBox(height: 30.rpx),
|
||
];
|
||
}
|
||
|
||
return list;
|
||
} catch (e) {
|
||
ef.log("$e");
|
||
edm.EasyDartModule.logger.info("[websokcet数据]:解析消息类型失败-->$e");
|
||
return [
|
||
Container(),
|
||
];
|
||
}
|
||
}
|
||
|
||
getSwitchStatus(config, device) {
|
||
String on = "已开启".tr;
|
||
String off = "已关闭".tr;
|
||
|
||
try {
|
||
// 1. 检查通用消息设置
|
||
if (commonMessageSettingController.model.setting == 0) {
|
||
return off;
|
||
}
|
||
|
||
// 2. 检查通用消息的app和service设置
|
||
if (commonMessageSettingController.model.appSetting == 0 &&
|
||
commonMessageSettingController.model.serviceSetting == 0) {
|
||
return off;
|
||
}
|
||
|
||
// 3. 检查设备消息总开关
|
||
if (messageSettingController.model.setting == 0) {
|
||
return off;
|
||
}
|
||
|
||
// 4. 获取当前配置的id
|
||
int id = config['id'];
|
||
|
||
// 5. 从device_type_setting中查找对应id的配置
|
||
List deviceTypeSettings =
|
||
messageSettingController.model.device_type_setting;
|
||
|
||
if (deviceTypeSettings == null || deviceTypeSettings.isEmpty) {
|
||
return on; // 如果列表为空,返回on
|
||
}
|
||
|
||
// 查找id匹配的配置
|
||
var targetConfig;
|
||
for (var item in deviceTypeSettings) {
|
||
if (item is Map && item['id'] == id) {
|
||
targetConfig = item;
|
||
break;
|
||
}
|
||
}
|
||
|
||
print("ID: $id, 找到配置: $targetConfig");
|
||
|
||
// 6. 如果找不到该配置,直接返回on(已开启)
|
||
if (targetConfig == null) {
|
||
return on;
|
||
}
|
||
|
||
// 7. 根据配置中的setting字段返回相应状态
|
||
if (targetConfig['setting'] == null) {
|
||
return on; // setting为空,默认返回on
|
||
}
|
||
|
||
int settingValue = targetConfig['setting'] is int
|
||
? targetConfig['setting']
|
||
: int.tryParse(targetConfig['setting'].toString()) ?? 1;
|
||
|
||
return settingValue == 1 ? on : off;
|
||
} catch (e) {
|
||
print("getSwitchStatus 错误: $e");
|
||
return on; // 出错时默认返回已开启
|
||
}
|
||
}
|
||
|
||
// 返回开关状态数值 (1:开启, 0:关闭)
|
||
getSwitchStatusValue(config, device) {
|
||
try {
|
||
// 1. 检查通用消息设置
|
||
if (commonMessageSettingController.model.setting == 0) {
|
||
return 0;
|
||
}
|
||
|
||
// 2. 检查通用消息的app和service设置
|
||
if (commonMessageSettingController.model.appSetting == 0 &&
|
||
commonMessageSettingController.model.serviceSetting == 0) {
|
||
return 0;
|
||
}
|
||
|
||
// 3. 检查设备消息总开关
|
||
if (messageSettingController.model.setting == 0) {
|
||
return 0;
|
||
}
|
||
|
||
// 4. 获取当前配置的id
|
||
int id = config['id'];
|
||
|
||
// 5. 从device_type_setting中查找对应id的配置
|
||
List deviceTypeSettings =
|
||
messageSettingController.model.device_type_setting;
|
||
|
||
if (deviceTypeSettings == null || deviceTypeSettings.isEmpty) {
|
||
return 1; // 如果列表为空,返回1(默认开启)
|
||
}
|
||
|
||
// 查找id匹配的配置
|
||
var targetConfig;
|
||
for (var item in deviceTypeSettings) {
|
||
if (item is Map && item['id'] == id) {
|
||
targetConfig = item;
|
||
break;
|
||
}
|
||
}
|
||
|
||
print("ID: $id, 找到配置: $targetConfig");
|
||
|
||
// 6. 如果找不到该配置,返回1(默认开启)
|
||
if (targetConfig == null) {
|
||
return 1;
|
||
}
|
||
|
||
// 7. 根据配置中的setting字段返回相应数值
|
||
if (targetConfig['setting'] == null) {
|
||
return 1; // setting为空,默认返回1
|
||
}
|
||
|
||
int settingValue = targetConfig['setting'] is int
|
||
? targetConfig['setting']
|
||
: int.tryParse(targetConfig['setting'].toString()) ?? 1;
|
||
|
||
return settingValue == 1 ? 1 : 0;
|
||
} catch (e) {
|
||
print("getSwitchStatusValue 错误: $e");
|
||
return 1; // 出错时默认返回1(开启)
|
||
}
|
||
}
|
||
}
|