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

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 showLabel = widget.sleepReport['score']['type'];
List stages = widget.sleepReport['score']['stages']; List stages = widget.sleepReport['score']['stages'];
List<SegmentData> segments = parseSegments(widget.sleepReport); 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( return Container(
width: double.infinity, width: double.infinity,
// decoration: BoxDecoration(color: Colors.green), // decoration: BoxDecoration(color: Colors.green),
@@ -81,7 +91,11 @@ class _SleepScoreWidgetState extends State<SleepScoreWidget> {
Text( Text(
'${widget.sleepReport['score']?['avg']}', '${widget.sleepReport['score']?['avg']}',
style: TextStyle( style: TextStyle(
color: Colors.white, // color: Colors.white,
color: stringToColor(
matchedColor?.trim().isEmpty ?? true
? "#FFFFFF"
: matchedColor!),
fontSize: 48.rpx, fontSize: 48.rpx,
letterSpacing: 0.0, letterSpacing: 0.0,
), ),
@@ -103,7 +117,12 @@ class _SleepScoreWidgetState extends State<SleepScoreWidget> {
Text( Text(
'${getSleepLevel(widget.sleepReport)}', '${getSleepLevel(widget.sleepReport)}',
style: TextStyle( style: TextStyle(
color: stringToColor("#FF9F66"), // color: stringToColor("#FF9F66"),
color: stringToColor(
matchedColor?.trim().isEmpty ?? true
? "#FFFFFF"
: matchedColor!),
fontSize: 48.rpx, fontSize: 48.rpx,
letterSpacing: 0.0, letterSpacing: 0.0,
), ),
@@ -139,7 +158,11 @@ class _SleepScoreWidgetState extends State<SleepScoreWidget> {
Text( Text(
'${widget.sleepReport['score']?['score']}', '${widget.sleepReport['score']?['score']}',
style: TextStyle( style: TextStyle(
color: stringToColor("#FF9F66"), // color: stringToColor("#FF9F66"),
color: stringToColor(
matchedColor?.trim().isEmpty ?? true
? "#FFFFFF"
: matchedColor!),
fontSize: 100.rpx), fontSize: 100.rpx),
), ),
], ],