更新快检功能
This commit is contained in:
208
lib/pages/sleep_report/qc_report/QcDiseasePercentsWidget.dart
Normal file
208
lib/pages/sleep_report/qc_report/QcDiseasePercentsWidget.dart
Normal file
@@ -0,0 +1,208 @@
|
||||
import 'package:ef/ef.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.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/component/tool/ClickableContainer.dart';
|
||||
import 'package:vbvs_app/enum/APPPackageType.dart';
|
||||
import 'package:vbvs_app/pages/device_bind/componnet/bind_dialog.dart';
|
||||
import 'package:vbvs_app/pages/sleep_report/chart/HorizontalBarChart.dart';
|
||||
import 'package:EasyDartModule/EasyDartModule.dart' as es;
|
||||
|
||||
class QcDiseasePercentsWidget extends StatefulWidget {
|
||||
var reportData; // 改为更通用的名称
|
||||
QcDiseasePercentsWidget({super.key, required this.reportData});
|
||||
|
||||
@override
|
||||
State<QcDiseasePercentsWidget> createState() =>
|
||||
_QcDiseasePercentsWidgetState();
|
||||
}
|
||||
|
||||
class _QcDiseasePercentsWidgetState extends State<QcDiseasePercentsWidget> {
|
||||
@override
|
||||
void setState(VoidCallback callback) {
|
||||
super.setState(callback);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
try {
|
||||
if (widget.reportData == null) {
|
||||
return Container();
|
||||
}
|
||||
|
||||
// 从reportData中获取mbzs数据
|
||||
List mbzsData = widget.reportData['mbzs'] ?? [];
|
||||
if (mbzsData.isEmpty) {
|
||||
return Container();
|
||||
}
|
||||
|
||||
var showLabel = convertDiseaseData(mbzsData);
|
||||
|
||||
// 如果没有有效数据,不显示组件
|
||||
if (showLabel.isEmpty) {
|
||||
return Container();
|
||||
}
|
||||
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
color: themeController.currentColor.sc5,
|
||||
borderRadius: BorderRadius.circular(
|
||||
AppConstants().normal_container_radius), // 你可以按需调整圆角半径
|
||||
),
|
||||
child: Padding(
|
||||
padding:
|
||||
EdgeInsetsDirectional.fromSTEB(26.rpx, 29.rpx, 26.rpx, 45.rpx),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Container(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
"慢性病风险指数".tr,
|
||||
style: TextStyle(
|
||||
color: themeController.currentColor.sc3,
|
||||
fontSize: AppConstants().title_text_fontSize),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
ClickableContainer(
|
||||
backgroundColor: Colors.transparent,
|
||||
highlightColor: Colors.white, // 或设置为你需要的水波纹颜色
|
||||
padding: EdgeInsetsDirectional.fromSTEB(
|
||||
14.rpx, 10.rpx, 14.rpx, 10.rpx), //
|
||||
borderRadius: 0.rpx, // 圆形点击区域
|
||||
onTap: () {
|
||||
// 你的点击逻辑
|
||||
|
||||
if (AppConstants().ent_type ==
|
||||
APPPackageType.MHT.code) {
|
||||
showTipDialog(
|
||||
context,
|
||||
Container(
|
||||
child: Text(
|
||||
// "心理健康评估介绍".tr,
|
||||
"慢性病风险指数是通过整合个体的生理指标、生活方式等多维度数据,构建的量化评估模型,用于预测用户未来患慢性非传染性疾病(如高血压、糖尿病、冠心病、癌症等)的风险概率。"
|
||||
.tr,
|
||||
style: TextStyle(
|
||||
fontSize: 26.rpx,
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
),
|
||||
backgroundColor: Color(0xFFFFFFFF),
|
||||
colors: [
|
||||
Color(0XFF1592AA),
|
||||
Color(0xFF0C83A7),
|
||||
Color(0xFF006FA3)
|
||||
],
|
||||
);
|
||||
} else {
|
||||
showTipDialog(
|
||||
context,
|
||||
Container(
|
||||
child: Text(
|
||||
"慢性病风险指数是通过整合个体的生理指标、生活方式等多维度数据,构建的量化评估模型,用于预测用户未来患慢性非传染性疾病(如高血压、糖尿病、冠心病、癌症等)的风险概率。"
|
||||
.tr,
|
||||
style: TextStyle(
|
||||
fontSize: 26.rpx,
|
||||
color: themeController.currentColor.sc3,
|
||||
),
|
||||
),
|
||||
),
|
||||
backgroundColor: themeController.currentColor.sc17,
|
||||
colors: AppConstants().thNormalButton,
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsetsDirectional.fromSTEB(
|
||||
0, 0.rpx, 0.rpx, 0), // 外部 padding 移到内部
|
||||
width: 28.rpx,
|
||||
height: 28.rpx,
|
||||
child: SvgPicture.asset(
|
||||
'assets/img/icon/explain.svg',
|
||||
fit: BoxFit.cover,
|
||||
color: themeController.currentColor.sc4,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: 34.rpx,
|
||||
),
|
||||
Container(
|
||||
child: HorizontalBarChart(
|
||||
showLabel: showLabel,
|
||||
showPercent: true,
|
||||
showRangeBackground: true),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
es.EasyDartModule.logger.error("疾病绘制异常${e}");
|
||||
return Container();
|
||||
}
|
||||
}
|
||||
|
||||
List<Map<String, dynamic>> convertDiseaseData(List data) {
|
||||
return data.asMap().entries.map<Map<String, dynamic>>((entry) {
|
||||
final index = entry.key;
|
||||
final item = entry.value;
|
||||
|
||||
// 根据名称生成一个简单的ID(如果没有id字段)
|
||||
String id = 'disease_$index';
|
||||
if (item['name'] != null) {
|
||||
// 根据名称生成一个简单的哈希值作为id
|
||||
id = '${item['name']}_$index';
|
||||
}
|
||||
|
||||
// 根据值的大小决定颜色深浅
|
||||
Color barColor = _getColorByValue(item['val'] ?? 0);
|
||||
|
||||
return {
|
||||
"key": id,
|
||||
"name": item["name"] ?? '未知指标',
|
||||
"color": barColor,
|
||||
"percent": item["val"] ?? 0, // 注意这里从val取值
|
||||
"explain":
|
||||
(item["tips"] != null && (item["tips"] as String).trim().isNotEmpty)
|
||||
? item["tips"]
|
||||
: '${item["val"] ?? 0}%的风险概率',
|
||||
};
|
||||
}).toList();
|
||||
}
|
||||
|
||||
// 根据风险值获取对应的颜色
|
||||
Color _getColorByValue(int value) {
|
||||
if (value < 30) {
|
||||
return stringToColor("#00C1AA"); // 低风险 - 绿色
|
||||
} else if (value < 60) {
|
||||
return stringToColor("#FFB800"); // 中风险 - 黄色
|
||||
} else if (value < 80) {
|
||||
return stringToColor("#FF7159"); // 高风险 - 橙色
|
||||
} else {
|
||||
return stringToColor("#FF4D4F"); // 极高风险 - 红色
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user