更新语言

This commit is contained in:
wyf
2025-12-09 18:09:31 +08:00
parent e7c51bea52
commit 793dddfba8
7 changed files with 71 additions and 38 deletions

View File

@@ -35,6 +35,41 @@ class _BreatheStandardWidgetState extends State<BreatheStandardWidget> {
super.dispose();
}
// 计算y轴的最大最小值
(double, double) _calculateYMinMax(List<TimeSeriesPoint> dataPoints) {
if (dataPoints.isEmpty) {
return (8.0, 20.0);
}
// 过滤掉无效数据点(值为-1的
final validPoints = dataPoints.where((point) => point.value >= 0).toList();
if (validPoints.isEmpty) {
return (8.0, 20.0);
}
// 找出数据中的实际最小值和最大值
double dataMin = validPoints.map((point) => point.value).reduce((a, b) => a < b ? a : b);
double dataMax = validPoints.map((point) => point.value).reduce((a, b) => a > b ? a : b);
// 设置默认范围
double yMin = 8.0;
double yMax = 20.0;
// 如果数据范围超出了默认范围,则调整
if (dataMin < yMin) {
// 最小值为0不能为负数且向下浮动2
yMin = (dataMin - 2).clamp(0.0, double.infinity);
}
if (dataMax > yMax) {
// 向上浮动2
yMax = dataMax + 2;
}
return (yMin, yMax);
}
@override
Widget build(BuildContext context) {
try {
@@ -54,41 +89,35 @@ class _BreatheStandardWidgetState extends State<BreatheStandardWidget> {
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);
final y = (item['value'] as num).toDouble();
dataPoints.add(TimeSeriesPoint(x, y));
});
}
// 计算动态的y轴范围
final (yMin, yMax) = _calculateYMinMax(dataPoints);
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: () => {},
@@ -111,7 +140,7 @@ class _BreatheStandardWidgetState extends State<BreatheStandardWidget> {
decoration: BoxDecoration(
color: themeController.currentColor.sc5,
borderRadius: BorderRadius.circular(
AppConstants().normal_container_radius), // 你可以按需调整圆角半径
AppConstants().normal_container_radius),
),
child: Padding(
padding:
@@ -131,10 +160,10 @@ class _BreatheStandardWidgetState extends State<BreatheStandardWidget> {
),
ClickableContainer(
backgroundColor: Colors.transparent,
highlightColor: Colors.white, // 或设置为你需要的水波纹颜色
highlightColor: Colors.white,
padding: EdgeInsetsDirectional.fromSTEB(
14.rpx, 10.rpx, 14.rpx, 10.rpx), //
borderRadius: 0.rpx, // 圆形点击区域
14.rpx, 10.rpx, 14.rpx, 10.rpx),
borderRadius: 0.rpx,
onTap: () {
if (AppConstants().ent_type ==
APPPackageType.MHT.code) {
@@ -142,7 +171,6 @@ class _BreatheStandardWidgetState extends State<BreatheStandardWidget> {
context,
Container(
child: Text(
// "呼吸数据介绍".tr,
"呼吸数据是指用户在睡眠过程中呼吸的基本数据,是评估睡眠呼吸质量、筛查睡眠呼吸障碍的核心指标。"
.tr,
style: TextStyle(
@@ -178,7 +206,7 @@ class _BreatheStandardWidgetState extends State<BreatheStandardWidget> {
},
child: Container(
padding: EdgeInsetsDirectional.fromSTEB(
0, 0.rpx, 0.rpx, 0), // 外部 padding 移到内部
0, 0.rpx, 0.rpx, 0),
width: 28.rpx,
height: 28.rpx,
child: SvgPicture.asset(
@@ -202,39 +230,33 @@ class _BreatheStandardWidgetState extends State<BreatheStandardWidget> {
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
// 圆形小球容器
Container(
width: 14.rpx, // 圆球的直径
width: 14.rpx,
height: 14.rpx,
decoration: BoxDecoration(
color: themeController.currentColor.sc2, // 小球的颜色
shape: BoxShape.circle, // 设置为圆形
color: themeController.currentColor.sc2,
shape: BoxShape.circle,
),
),
SizedBox(width: 15.rpx), // 圆球和文字之间的间隔
// 文字
SizedBox(width: 15.rpx),
Text(
'正常范围'.tr + "${range}",
style: TextStyle(
fontSize:
AppConstants().smaller_text_fontSize, // 文字的大小
color: themeController.currentColor.sc3, // 文字颜色
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,
yMin: yMin,
yMax: yMax,
dataPoints: dataPoints,
// actYMax: max.toDouble(),
// actYMin: min.toDouble(),
),
),
].divide(SizedBox(
@@ -398,4 +420,4 @@ class _BreatheStandardWidgetState extends State<BreatheStandardWidget> {
return Container();
}
}
}
}