Files
tuiche/lib/pages/sleep_report/component/BreatheStandardWidget.dart

390 lines
16 KiB
Dart

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/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/TimeSeriesChart.dart';
import 'package:EasyDartModule/EasyDartModule.dart' as es;
class BreatheStandardWidget extends StatefulWidget {
var sleepReport;
BreatheStandardWidget({super.key, required this.sleepReport});
@override
State<BreatheStandardWidget> createState() => _BreatheStandardWidgetState();
}
class _BreatheStandardWidgetState extends State<BreatheStandardWidget> {
@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.sleepReport == null ||
widget.sleepReport is! Map ||
widget.sleepReport.isEmpty) {
return Container();
}
final startTime = widget.sleepReport['startTime'];
final endTime = widget.sleepReport['endTime'];
List<Map<String, dynamic>> data =
(widget.sleepReport['brbc'] as List).cast<Map<String, dynamic>>();
List<TimeSeriesPoint> dataPoints = [];
if (data != null && data.isNotEmpty) {
data.forEach((item) {
final x = item['st'] as int;
if (item['value'] == null || item['value'] == '') {
// return;
dataPoints.add(TimeSeriesPoint(x, -1));
return;
}
final y = (item['value'] as num).toDouble(); // 安全地转换为 double
// return TimeSeriesPoint(x, y);
dataPoints.add(TimeSeriesPoint(x, y));
});
}
List<Map<String, dynamic>> brs =
(widget.sleepReport['brs'] as List).cast<Map<String, dynamic>>();
//307 平均呼吸
//305 基准呼吸
//308 最低呼吸
//309 最高呼吸
// 307 平均呼吸
Map<String, dynamic>? avgBreath = brs.firstWhere(
(element) => element['id'] == 307,
orElse: () => {},
);
// 305 基准呼吸
Map<String, dynamic>? baseBreath = brs.firstWhere(
(element) => element['id'] == 305,
orElse: () => {},
);
// 308 最低呼吸
Map<String, dynamic>? minBreath = brs.firstWhere(
(element) => element['id'] == 308,
orElse: () => {},
);
// 309 最高呼吸
Map<String, dynamic>? maxBreath = brs.firstWhere(
(element) => element['id'] == 309,
orElse: () => {},
);
String range = baseBreath['range'] ?? '';
int min = 0;
int max = 0;
if (range.isNotEmpty && range.contains('~')) {
List<String> parts = range.split('~');
if (parts.length == 2) {
min = int.tryParse(parts[0]) ?? 0;
max = int.tryParse(parts[1]) ?? 0;
}
}
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, 10.rpx, 14.rpx, 10.rpx), //
borderRadius: 0.rpx, // 圆形点击区域
onTap: () {
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)
],
);
},
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: 31.rpx,
),
Padding(
padding:
EdgeInsetsDirectional.fromSTEB(0.rpx, 0.rpx, 30.rpx, 0.rpx),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
// 圆形小球容器
Container(
width: 14.rpx, // 圆球的直径
height: 14.rpx,
decoration: BoxDecoration(
color: themeController.currentColor.sc2, // 小球的颜色
shape: BoxShape.circle, // 设置为圆形
),
),
SizedBox(width: 15.rpx), // 圆球和文字之间的间隔
// 文字
Text(
'正常范围'.tr + "${range}",
style: TextStyle(
fontSize:
AppConstants().smaller_text_fontSize, // 文字的大小
color: themeController.currentColor.sc3, // 文字颜色
),
),
],
),
Container(
// color: Colors.red,
width: double.infinity,
// height: 300.rpx,
child: TimeSeriesChart(
startTime: startTime,
endTime: endTime,
yMin: 8,
yMax: 20,
dataPoints: dataPoints,
// actYMax: max.toDouble(),
// actYMin: min.toDouble(),
),
),
Padding(
padding: EdgeInsetsDirectional.fromSTEB(
30.rpx, 0.rpx, 0.rpx, 0.rpx),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Column(
children: [
Text(
"${avgBreath['name']}",
style: TextStyle(
color: themeController.currentColor.sc3,
fontSize:
AppConstants().normal_text_fontSize),
),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
"${avgBreath['value']}",
style: TextStyle(
color: themeController.currentColor.sc2,
fontSize: AppConstants()
.normal_text_fontSize),
),
Text(
"${avgBreath['unit']}",
style: TextStyle(
color: themeController.currentColor.sc3,
fontSize:
AppConstants().small_text_fontSize),
),
].divide(SizedBox(
width: 6.rpx,
)),
),
],
),
Column(
children: [
Text(
"${baseBreath['name']}",
style: TextStyle(
color: themeController.currentColor.sc3,
fontSize:
AppConstants().normal_text_fontSize),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
"${baseBreath['value']}",
style: TextStyle(
color: themeController.currentColor.sc2,
fontSize: AppConstants()
.normal_text_fontSize),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
Text(
"${baseBreath['unit']}",
style: TextStyle(
color: themeController.currentColor.sc3,
fontSize:
AppConstants().small_text_fontSize),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
].divide(SizedBox(
width: 6.rpx,
)),
),
],
),
Column(
children: [
Text(
"${minBreath['name']}",
style: TextStyle(
color: themeController.currentColor.sc3,
fontSize:
AppConstants().normal_text_fontSize),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
"${minBreath['value']}",
style: TextStyle(
color: themeController.currentColor.sc2,
fontSize: AppConstants()
.normal_text_fontSize),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
Text(
"${minBreath['unit']}",
style: TextStyle(
color: themeController.currentColor.sc3,
fontSize:
AppConstants().small_text_fontSize),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
].divide(SizedBox(
width: 6.rpx,
)),
),
],
),
Column(
children: [
Text(
"${maxBreath['name']}",
style: TextStyle(
color: themeController.currentColor.sc3,
fontSize:
AppConstants().normal_text_fontSize),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
"${maxBreath['value']}",
style: TextStyle(
color: themeController.currentColor.sc2,
fontSize: AppConstants()
.normal_text_fontSize),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
Text(
"${maxBreath['unit']}",
style: TextStyle(
color: themeController.currentColor.sc3,
fontSize:
AppConstants().small_text_fontSize),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
].divide(SizedBox(
width: 6.rpx,
)),
),
],
),
],
),
),
].divide(SizedBox(
height: 18.rpx,
)),
),
),
],
),
),
);
} catch (e) {
es.EasyDartModule.logger.error("打鼾监测绘制异常${e}");
return Container();
}
}
}