睡眠报告多次点击查询 显示bug
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user