睡眠报告多次点击查询 显示bug

This commit is contained in:
czz
2025-10-14 16:41:52 +08:00
parent d7f1b78404
commit 6b0f422fa4
3 changed files with 73 additions and 20 deletions

View File

@@ -77,7 +77,7 @@ Widget MonthDataWidget(
},
),
],
tips: buildValueTexts(sleepReport['scoreList']['data'], ''.tr, 1),
tips: buildValueTexts(sleepReport['scoreList']['data'], null, 1),
xCount: buildMonthlyChartData(sleepReport['scoreList'])['daysInMonth']
.toInt(),
yCount: sleepReport['scoreList']['yLable'].length,
@@ -547,27 +547,59 @@ Widget MonthDataWidget(
);
}
// List<String> buildValueTexts(
// List<dynamic> data,
// String? unit,
// int direction, // 0 表示左侧1 表示右侧
// ) {
// if (data.isEmpty) return [];
// return data
// .where((item) => item.containsKey('value') && item.containsKey('st'))
// .map((item) {
// final val = item['value'].toString();
// // 单位位置
// final prefix = direction == 1 ? '' : unit;
// final suffix = direction == 1 ? unit : '';
// // 中文年月日格式
// DateTime date = DateTime.fromMillisecondsSinceEpoch(item['st']);
// final dateStr = "${date.year}/${date.month}/${date.day}";
// return "$prefix$val$suffix\n$dateStr";
// }).toList();
// }
List<String> buildValueTexts(
List<dynamic> data,
String unit,
int direction, // 0 表示左侧1 表示右侧
String? unit,
int direction, // 0 左侧1 右侧
) {
if (data.isEmpty) return [];
final safeUnit = unit ?? ""; // 防止 null
return data
.where((item) => item.containsKey('value') && item.containsKey('st'))
.where((item) =>
item is Map && item.containsKey('value') && item.containsKey('st'))
.map((item) {
final val = item['value'].toString();
// 单位位置
final prefix = direction == 1 ? '' : unit;
final suffix = direction == 1 ? unit : '';
// ✅ 如果单位为空,不拼接单位
final prefix = safeUnit.isEmpty ? '' : (direction == 0 ? safeUnit : '');
final suffix = safeUnit.isEmpty ? '' : (direction == 1 ? safeUnit : '');
// 中文年月日格式
DateTime date = DateTime.fromMillisecondsSinceEpoch(item['st']);
final dateStr = "${date.year}/${date.month}/${date.day}";
// ✅ 处理时间戳
final ts = item['st'];
String dateStr = '';
if (ts != null && ts is int && ts > 0) {
final date = DateTime.fromMillisecondsSinceEpoch(ts);
// 格式化为 yyyy/MM/dd
dateStr = "${date.year}/${date.month}/${date.day}";
}
return "$prefix$val$suffix\n$dateStr";
return "$prefix$val$suffix${dateStr.isNotEmpty ? '\n$dateStr' : ''}";
}).toList();
}