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/pages/device_bind/componnet/bind_dialog.dart'; import 'package:vbvs_app/pages/sleep_report/chart/HorizontalBarChart.dart'; class DiseasePercentsWidget extends StatefulWidget { var sleepReport; DiseasePercentsWidget({super.key, required this.sleepReport}); @override State createState() => _DiseasePercentsWidgetState(); } class _DiseasePercentsWidgetState extends State { // var showLabel = [ // { // "key": 1, // "name": "心脏病", // "color": stringToColor("#00C1AA"), // "percent": 45, // "explain": "心脏病是指心脏的结构或功能异常,可能导致心脏无法有效地泵血。" // }, // { // "key": 2, // "name": "高血压", // "color": stringToColor("#00C1AA"), // "percent": 32, // "explain": "高血压是指血液在动脉中流动时对血管壁施加的压力过高。" // }, // { // "key": 3, // "name": "糖尿病", // "color": stringToColor("#00C1AA"), // "percent": 50, // "explain": "糖尿病是一种代谢性疾病,导致血糖水平异常升高。" // }, // { // "key": 4, // "name": "甲亢", // "color": stringToColor("#FF7159"), // "percent": 80, // "explain": "甲亢是指甲状腺分泌过多的甲状腺激素,导致新陈代谢加速。" // }, // { // "key": 5, // "name": "消化系统", // "color": stringToColor("#00C1AA"), // "percent": 12, // "explain": "消化系统是身体中处理食物的机构,是造成疾病和疾病症状的来源。", // }, // { // "key": 6, // "name": "呼吸系统", // "color": stringToColor("#00C1AA"), // "percent": 62, // "explain": "呼吸系统是负责气体交换的器官系统,包括鼻、喉、气管和肺等。", // }, // ]; @override void setState(VoidCallback callback) { super.setState(callback); } @override void initState() { super.initState(); } @override void dispose() { super.dispose(); } @override Widget build(BuildContext context) { if (widget.sleepReport == null || widget.sleepReport['cdri'] == null || widget.sleepReport['cdri'].isEmpty) { return Container(); } List diseaseData = widget.sleepReport['cdri']; var showLabel = convertDiseaseData(diseaseData); 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: [ Text( "慢性病风险指数".tr, style: TextStyle( color: themeController.currentColor.sc3, fontSize: AppConstants().title_text_fontSize), ), ClickableContainer( backgroundColor: Colors.transparent, highlightColor: Colors.white, // 或设置为你需要的水波纹颜色 padding: EdgeInsetsDirectional.fromSTEB( 14.rpx, 0.rpx, 14.rpx, 0), // borderRadius: 0.rpx, // 圆形点击区域 onTap: () { // 你的点击逻辑 showTipDialog( context, Container( child: Text( "慢性病风险指数介绍".tr, style: TextStyle( fontSize: 26.rpx, color: themeController.currentColor.sc3, ), ), ), ); }, 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, ), ), ], ), ), ); } List> convertDiseaseData(List data) { return data.asMap().entries.map>((entry) { final index = entry.key; final item = entry.value; return { "key": item["id"], "name": item["name"], "color": item["id"] == 40004 ? stringToColor("#FF7159") // 特殊颜色处理 : stringToColor("#00C1AA"), "percent": item["value"], "explain": (item["tips"] != null && (item["tips"] as String).trim().isNotEmpty) ? item["tips"] : '未知数据'.tr, }; }).toList(); } }