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), ), ],