更新睡眠报告

This commit is contained in:
wyf
2025-05-27 23:09:31 +08:00
parent e0fef11b33
commit 98cd7f4e6a
54 changed files with 4450 additions and 1160 deletions

View File

@@ -0,0 +1,388 @@
import 'package:ef/ef.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:vbvs_app/common/color/appConstants.dart';
import 'package:vbvs_app/common/util/FitTool.dart';
import 'package:vbvs_app/common/util/MyUtils.dart';
import 'package:vbvs_app/component/tool/ClickableContainer.dart';
import 'package:vbvs_app/pages/device_bind/componnet/bind_dialog.dart';
import 'package:vbvs_app/pages/sleep_report/chart/GradientLine.dart';
import 'package:vbvs_app/pages/sleep_report/chart/SnoreWaveform.dart';
//睡眠规律性
class SleepViewWidget extends StatefulWidget {
var sleepReport;
SleepViewWidget({super.key, required this.sleepReport});
@override
State<SleepViewWidget> createState() => _SleepViewWidgetState();
}
class _SleepViewWidgetState extends State<SleepViewWidget> {
@override
void setState(VoidCallback callback) {
super.setState(callback);
}
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
if (widget.sleepReport == null ||
widget.sleepReport is! Map ||
widget.sleepReport.isEmpty) {
return Container();
}
// List showLabel = widget.sleepReport['sleepData']['type'];
List showLabel = widget.sleepReport['sleepData']['type']
.where((item) => item['show'] != false)
.toList();
// final snoreValues = generateSnoreValues(
// widget.sleepReport['startTime'],
// widget.sleepReport['endTime'],
// );
List snoreValues = widget.sleepReport['ssp'];
Map time = MyUtils.diffHoursMinutesMap(
widget.sleepReport['startTime'], widget.sleepReport['endTime']);
int hour = time['hours'];
int minutes = time['minutes'];
// List stages = [
// {"et": 1748011592746, "st": 1748010870326, "type": 1},
// {"et": 1748013519534, "st": 1748011593746, "type": 2},
// {"et": 1748013639534, "st": 1748013520534, "type": 1},
// {"et": 1748014183143, "st": 1748013640534, "type": 2},
// {"et": 1748014363143, "st": 1748014184143, "type": 1},
// {"et": 1748014423143, "st": 1748014364143, "type": 2},
// {"et": 1748014541143, "st": 1748014424143, "type": 1},
// {"et": 1748015439477, "st": 1748014542143, "type": 0},
// {"et": 1748018470415, "st": 1748015440477, "type": 1},
// {"et": 1748019755726, "st": 1748018471415, "type": 2},
// {"et": 1748020123225, "st": 1748019756726, "type": 1},
// {"et": 1748021138809, "st": 1748020124225, "type": 2},
// {"et": 1748021535809, "st": 1748021139809, "type": 1},
// {"et": 1748021776809, "st": 1748021536809, "type": 2},
// {"et": 1748022140117, "st": 1748021777809, "type": 1},
// {"et": 1748022320117, "st": 1748022141117, "type": 2},
// {"et": 1748022996627, "st": 1748022321117, "type": 1},
// {"et": 1748023439627, "st": 1748022997627, "type": 2},
// {"et": 1748023812173, "st": 1748023440627, "type": 1},
// {"et": 1748023895173, "st": 1748023813173, "type": 2},
// {"et": 1748024692483, "st": 1748023896173, "type": 1},
// {"et": 1748024960483, "st": 1748024693483, "type": 2},
// {"et": 1748025678983, "st": 1748024961483, "type": 1},
// {"et": 1748026351585, "st": 1748025679983, "type": 2},
// {"et": 1748027131585, "st": 1748026352585, "type": 1},
// {"et": 1748027209585, "st": 1748027132585, "type": 2},
// {"et": 1748027487864, "st": 1748027210585, "type": 1},
// {"et": 1748027967864, "st": 1748027488864, "type": 3},
// {"et": 1748028182371, "st": 1748027968864, "type": 1},
// {"et": 1748028372371, "st": 1748028183371, "type": 2},
// {"et": 1748029109981, "st": 1748028373371, "type": 1},
// {"et": 1748029958223, "st": 1748029110981, "type": 2},
// {"et": 1748030792223, "st": 1748029959223, "type": 1},
// {"et": 1748030874723, "st": 1748030793223, "type": 2},
// {"et": 1748032042305, "st": 1748030875723, "type": 1},
// {"et": 1748032170305, "st": 1748032043305, "type": 2},
// {"et": 1748033387611, "st": 1748032171305, "type": 1},
// {"et": 1748033967118, "st": 1748033388611, "type": 2},
// {"et": 1748034087118, "st": 1748033968118, "type": 1},
// {"et": 1748034147118, "st": 1748034088118, "type": 2},
// {"et": 1748034327118, "st": 1748034148118, "type": 1},
// {"et": 1748034930672, "st": 1748034328118, "type": 2},
// {"et": 1748035230672, "st": 1748034931672, "type": 1},
// {"et": 1748035353974, "st": 1748035231672, "type": 2},
// {"et": 1748036710471, "st": 1748035354974, "type": 1},
// {"et": 1748037126471, "st": 1748036711471, "type": 2},
// {"et": 1748037310051, "st": 1748037127471, "type": 1},
// {"et": 1748037380051, "st": 1748037311051, "type": 2},
// {"et": 1748038881358, "st": 1748037381051, "type": 1},
// {"et": 1748038962867, "st": 1748038882358, "type": 0},
// {"et": 1748039291867, "st": 1748038963867, "type": 1},
// {"et": 1748039684867, "st": 1748039292867, "type": 0}
// ];
List stages = widget.sleepReport['sleepData']['stages'];
return Container(
width: double.infinity,
decoration: BoxDecoration(
color: themeController.currentColor.sc5,
borderRadius:
BorderRadius.circular(AppConstants().normal_container_radius),
),
child: Padding(
padding: EdgeInsetsDirectional.fromSTEB(26.rpx, 29.rpx, 26.rpx, 45.rpx),
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"睡眠规律性".tr,
style: TextStyle(
color: themeController.currentColor.sc3,
fontSize: AppConstants().title_text_fontSize),
),
ClickableContainer(
backgroundColor: Colors.transparent,
highlightColor: Colors.white, // 或设置为你需要的水波纹颜色
padding: EdgeInsetsDirectional.fromSTEB(
14.rpx, 0.rpx, 14.rpx, 0), //
borderRadius: 0.rpx, // 圆形点击区域
onTap: () {
showTipDialog(
context,
Container(
child: Text(
"睡眠规律性介绍。",
style: TextStyle(
fontSize: 26.rpx,
color: themeController.currentColor.sc3,
),
),
),
);
},
child: Container(
padding: EdgeInsetsDirectional.fromSTEB(
0, 0.rpx, 0.rpx, 0), // 外部 padding 移到内部
width: 28.rpx,
height: 28.rpx,
child: SvgPicture.asset(
'assets/img/icon/explain.svg',
fit: BoxFit.cover,
color: themeController.currentColor.sc4,
),
),
),
],
),
),
SizedBox(
height: 83.rpx,
),
Padding(
padding:
EdgeInsetsDirectional.fromSTEB(30.rpx, 0.rpx, 30.rpx, 0.rpx),
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
// 左侧 - 入睡时间
Column(
mainAxisSize: MainAxisSize.min,
children: [
Image.asset(
"assets/img/moon.png",
width: 43.rpx,
height: 43.rpx,
fit: BoxFit.cover,
),
SizedBox(height: 33.rpx),
Container(
height: 40.rpx,
child: Text(
"${MyUtils.formatToHHmm(widget.sleepReport['startTime'])}",
style: TextStyle(
color: themeController.currentColor.sc3,
fontSize: AppConstants().normal_text_fontSize,
),
),
),
SizedBox(height: 20.rpx),
Text(
"入睡时间".tr,
style: TextStyle(
color: themeController.currentColor.sc4,
fontSize: AppConstants().normal_text_fontSize,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
),
// 中间 - 渐变线 + 时间
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
height: 43.rpx,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
GradientLine(
height: 1,
color: Colors.white60,
),
],
)),
SizedBox(height: 33.rpx), // 与图标对齐
Text.rich(
TextSpan(
children: [
TextSpan(
text: "$hour",
style: TextStyle(
color: themeController
.currentColor.sc2, // 小时数字颜色
fontSize: 36.rpx, // 小时数字字号
),
),
TextSpan(
text: "小时",
style: TextStyle(
color: themeController.currentColor.sc3,
fontSize: AppConstants().title_text_fontSize,
),
),
TextSpan(
text: "$minutes",
style: TextStyle(
color: themeController
.currentColor.sc2, // 小时数字颜色
fontSize: 36.rpx, // 分钟数字字号
),
),
TextSpan(
text: "分钟",
style: TextStyle(
color: themeController.currentColor.sc3,
fontSize: AppConstants().title_text_fontSize,
),
),
],
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
SizedBox(height: 20.rpx),
Text(
"睡眠时长".tr,
style: TextStyle(
color: themeController.currentColor.sc4,
fontSize: AppConstants().normal_text_fontSize,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
),
),
// 右侧 - 起床时间图标
Column(
mainAxisSize: MainAxisSize.min,
children: [
Image.asset(
"assets/img/sun.png",
width: 43.rpx,
height: 43.rpx,
fit: BoxFit.cover,
),
SizedBox(height: 33.rpx),
Container(
height: 40.rpx,
child: Text(
"${MyUtils.formatToHHmm(widget.sleepReport['endTime'])}",
style: TextStyle(
color: themeController.currentColor.sc3,
fontSize: AppConstants().normal_text_fontSize,
),
),
),
SizedBox(height: 20.rpx),
Text(
"起床时间".tr,
style: TextStyle(
color: themeController.currentColor.sc4,
fontSize: AppConstants().normal_text_fontSize,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
),
],
),
),
SizedBox(
height: 49.rpx,
),
Padding(
padding:
EdgeInsetsDirectional.fromSTEB(26.rpx, 0.rpx, 26.rpx, 0.rpx),
child: SnoreChartContainer(
snoreValues: snoreValues,
barData: stages,
startTime: widget.sleepReport['startTime'],
endTime: widget.sleepReport['endTime'],
showLabel: showLabel,
),
),
SizedBox(
height: 70.rpx,
),
Wrap(
spacing: 55.rpx,
runSpacing: 20.rpx,
children: showLabel.map<Widget>((item) {
return Container(
padding: EdgeInsets.all(5.rpx),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 20.rpx,
height: 20.rpx,
decoration: BoxDecoration(
color: item["color"] == null || item["color"] == ""
? Colors.transparent
: stringToColor(item["color"]),
borderRadius: BorderRadius.circular(10.rpx),
),
),
SizedBox(width: 17.rpx),
Text(
item["name"],
style: TextStyle(
color: Colors.white,
fontSize: 24.rpx,
),
),
],
),
);
}).toList(),
),
],
),
),
);
}
List<Map<String, dynamic>> generateSnoreValues(int startTime, int endTime) {
final int count = 100;
final int interval = ((endTime - startTime) / count).floor();
return List.generate(count, (index) {
final timestamp = startTime + interval * index;
final value =
(2 + 1 * (index % 7) / 6.0) * (index % 2 == 0 ? 1 : -1); // 示例上下对称波动
return {
"timestamp": timestamp,
"value": double.parse(value.toStringAsFixed(2)),
};
});
}
}