From 03024554339ef82a7ecb2485fd78a1a5b518d1ff Mon Sep 17 00:00:00 2001 From: wyf <494641114@qq.com> Date: Mon, 21 Jul 2025 17:53:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=A5=E6=8A=A5=E7=9D=A1?= =?UTF-8?q?=E7=9C=A0=E8=AF=84=E5=88=86=E9=A2=9C=E8=89=B2=E4=B8=8D=E5=AF=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../component/SleepScoreWidget.dart | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/pages/sleep_report/component/SleepScoreWidget.dart b/lib/pages/sleep_report/component/SleepScoreWidget.dart index fa75e4a..2d51abd 100644 --- a/lib/pages/sleep_report/component/SleepScoreWidget.dart +++ b/lib/pages/sleep_report/component/SleepScoreWidget.dart @@ -43,7 +43,17 @@ class _SleepScoreWidgetState extends State { List showLabel = widget.sleepReport['score']['type']; List stages = widget.sleepReport['score']['stages']; List 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 { 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 { 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 { Text( '${widget.sleepReport['score']?['score']}', style: TextStyle( - color: stringToColor("#FF9F66"), + // color: stringToColor("#FF9F66"), + color: stringToColor( + matchedColor?.trim().isEmpty ?? true + ? "#FFFFFF" + : matchedColor!), fontSize: 100.rpx), ), ],