修复日报睡眠评分颜色不对

This commit is contained in:
wyf
2025-07-21 17:53:06 +08:00
parent a005fb7714
commit 0302455433

View File

@@ -43,7 +43,17 @@ class _SleepScoreWidgetState extends State<SleepScoreWidget> {
List showLabel = widget.sleepReport['score']['type'];
List stages = widget.sleepReport['score']['stages'];
List<SegmentData> segments = parseSegments(widget.sleepReport);
int level = widget.sleepReport['score']['level'];
// 查找与 level 匹配的 map
String? matchedColor;
final matchedLabel = showLabel.firstWhere(
(item) => item['level'] == level,
orElse: () => null,
);
if (matchedLabel != null) {
matchedColor = matchedLabel['color'];
}
return Container(
width: double.infinity,
// decoration: BoxDecoration(color: Colors.green),
@@ -81,7 +91,11 @@ class _SleepScoreWidgetState extends State<SleepScoreWidget> {
Text(
'${widget.sleepReport['score']?['avg']}',
style: TextStyle(
color: Colors.white,
// color: Colors.white,
color: stringToColor(
matchedColor?.trim().isEmpty ?? true
? "#FFFFFF"
: matchedColor!),
fontSize: 48.rpx,
letterSpacing: 0.0,
),
@@ -103,7 +117,12 @@ class _SleepScoreWidgetState extends State<SleepScoreWidget> {
Text(
'${getSleepLevel(widget.sleepReport)}',
style: TextStyle(
color: stringToColor("#FF9F66"),
// color: stringToColor("#FF9F66"),
color: stringToColor(
matchedColor?.trim().isEmpty ?? true
? "#FFFFFF"
: matchedColor!),
fontSize: 48.rpx,
letterSpacing: 0.0,
),
@@ -139,7 +158,11 @@ class _SleepScoreWidgetState extends State<SleepScoreWidget> {
Text(
'${widget.sleepReport['score']?['score']}',
style: TextStyle(
color: stringToColor("#FF9F66"),
// color: stringToColor("#FF9F66"),
color: stringToColor(
matchedColor?.trim().isEmpty ?? true
? "#FFFFFF"
: matchedColor!),
fontSize: 100.rpx),
),
],