更新日历样式

This commit is contained in:
czz
2025-07-10 11:47:27 +08:00
parent a50f607f25
commit b6395e6952
2 changed files with 57 additions and 67 deletions

View File

@@ -57,7 +57,7 @@ class _SleepCalendarWidgetState extends State<SleepCalendarWidget> {
// 初始化请求 // 初始化请求
fetchDate(initialDate); fetchDate(initialDate);
fetchSleepColor();
// 每当月份变化时,重新请求数据 // 每当月份变化时,重新请求数据
ever(calendarController.displayedMonth, (DateTime newMonth) { ever(calendarController.displayedMonth, (DateTime newMonth) {
fetchDate(newMonth); fetchDate(newMonth);
@@ -74,38 +74,26 @@ class _SleepCalendarWidgetState extends State<SleepCalendarWidget> {
"https://sleepdata.he-info.com/api/analysis/sleep/analysis?mac=${widget.mac}&time=$dateStr&type=3", "https://sleepdata.he-info.com/api/analysis/sleep/analysis?mac=${widget.mac}&time=$dateStr&type=3",
onSuccess: (res) { onSuccess: (res) {
sleepDate.value = res.data; sleepDate.value = res.data;
showLabel.value = [
...res.data['scoreList']['type'],
{"level": 5, "name": "无报告", "color": "#9E9E9E"},
// ✅ 注意拼写是 scoreList
];
}, },
onFailure: (res) { onFailure: (res) {
sleepDate.value = {}; sleepDate.value = {};
showLabel.value = [
{"level": 5, "name": "无报告", "color": "#9E9E9E"},
];
}, },
); );
} }
Future<void> fetchSleepColor(DateTime timeStamp) async { Future<void> fetchSleepColor() async {
final dateStr = timeStamp.toString().split(' ')[0];
await requestWithLog( await requestWithLog(
logTitle: "查询睡眠报告", logTitle: "查询睡眠报告",
method: MyHttpMethod.get, method: MyHttpMethod.get,
queryUrl: "https://sleepdata.he-info.com/api/analysis/sleep/score/type", queryUrl: "https://sleepdata.he-info.com/api/analysis/sleep/score/type",
onSuccess: (res) { onSuccess: (res) {
sleepDate.value = res.data;
showLabel.value = [ showLabel.value = [
...res.data['scoreList']['type'], ...res.data,
{"level": 5, "name": "无报告", "color": "#9E9E9E"}, {"level": 5, "name": "无报告", "color": "#9E9E9E"},
// ✅ 注意拼写是 scoreList // ✅ 注意拼写是 scoreList
]; ];
}, },
onFailure: (res) { onFailure: (res) {
sleepDate.value = {};
showLabel.value = [ showLabel.value = [
{"level": 5, "name": "无报告", "color": "#9E9E9E"}, {"level": 5, "name": "无报告", "color": "#9E9E9E"},
]; ];

View File

@@ -1074,62 +1074,64 @@ class _NewSleepReportPageState extends State<NewSleepReportPage> {
], ],
), ),
ClickableContainer( ClickableContainer(
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
highlightColor: themeController.currentColor.sc3, highlightColor: themeController.currentColor.sc3,
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
borderRadius: 8, borderRadius: 8,
onTap: () { onTap: () {
showSleepCalendarBottomSheet( showSleepCalendarBottomSheet(
type: sleepReportController.model.type, type: sleepReportController.model.type,
timestamp: selectedDate.millisecondsSinceEpoch, timestamp: selectedDate.millisecondsSinceEpoch,
context: context, context: context,
mac: widget.data['mac'], mac: widget.data['mac'],
onDateSelected: (newDate) { onDateSelected: (newDate) {
sleepReportController.selectedDate.value = newDate; sleepReportController.selectedDate.value = newDate;
calendarController.selectedDate.value = newDate; calendarController.selectedDate.value = newDate;
String data = String data = MyUtils.formatDate(
MyUtils.formatDate(calendarController.selectedDate.value!); calendarController.selectedDate.value!);
requestWithLog( requestWithLog(
logTitle: "查询睡眠报告", logTitle: "查询睡眠报告",
method: MyHttpMethod.get, method: MyHttpMethod.get,
queryUrl: queryUrl:
"https://sleepdata.he-info.com/api/analysis/sleep/analysis?mac=${widget.data['mac']}&time=${data}&type=${sleepReportController.model.type}", "https://sleepdata.he-info.com/api/analysis/sleep/analysis?mac=${widget.data['mac']}&time=${data}&type=${sleepReportController.model.type}",
onSuccess: (res) { onSuccess: (res) {
print(res); print(res);
sleepReportController.sleepReport.value = res.data; sleepReportController.sleepReport.value = res.data;
sleepReportController.updateAll(); sleepReportController.updateAll();
}, },
onFailure: (res) { onFailure: (res) {
if (MainPageBBottomChange.getCurrentIndex() != null) { if (MainPageBBottomChange.getCurrentIndex() != null) {
if (MainPageBBottomChange.getCurrentIndex() == 1) { if (MainPageBBottomChange.getCurrentIndex() == 1) {
TopSlideNotification.show(context,
text: res.msg!,
textColor: themeController.currentColor.sc9);
}
} else {
TopSlideNotification.show(context, TopSlideNotification.show(context,
text: res.msg!, text: res.msg!,
textColor: themeController.currentColor.sc9); textColor: themeController.currentColor.sc9);
} }
} else { sleepReportController.sleepReport.value = {};
TopSlideNotification.show(context, sleepReportController.updateAll();
text: res.msg!, print(res);
textColor: themeController.currentColor.sc9); });
} sleepReportController.updateAll();
sleepReportController.sleepReport.value = {}; calendarController.updateAll();
sleepReportController.updateAll(); },
print(res); );
}); },
sleepReportController.updateAll(); child: Padding(
calendarController.updateAll(); padding: EdgeInsets.all(10.rpx),
}, child: Container(
); width: 36.rpx,
}, height: 36.rpx,
child: Container( child: SvgPicture.asset(
width: 36.rpx, 'assets/img/icon/calendar.svg',
height: 36.rpx, fit: BoxFit.cover,
child: SvgPicture.asset( color: themeController.currentColor.sc3,
'assets/img/icon/calendar.svg', ),
fit: BoxFit.cover, ),
color: themeController.currentColor.sc3, )),
),
),
),
], ],
); );
} }