更新首页睡眠报告定时刷新

This commit is contained in:
wyf
2025-09-22 14:28:45 +08:00
parent aaf378e016
commit 39df3d7294
2 changed files with 20 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:convert';
import 'package:EasyDartModule/EasyDartModule.dart';
@@ -48,6 +49,24 @@ class BodyDeviceController extends GetControllerEx<BodyDeviceModel> {
String wifiMac = "";
Timer? _sleepReportTimer; // 定时器
@override
void onInit() {
super.onInit();
// 启动定时器每10分钟请求一次
_sleepReportTimer = Timer.periodic(const Duration(minutes: 10), (timer) {
getSleepReport();
});
}
@override
void onClose() {
// 页面销毁时取消定时器
_sleepReportTimer?.cancel();
super.onClose();
}
Future<ApiResponse> getDeviceNum() async {
try {
ApiResponse apiResponse = ApiResponse(code: -1, msg: "设备.设备列表请求失败".tr);
@@ -199,6 +218,7 @@ class BodyDeviceController extends GetControllerEx<BodyDeviceModel> {
Future<ApiResponse> getSleepReport() async {
try {
ef.log("刷新睡眠报告");
sleepReportData.value = {};
ApiResponse<Map<String, List<dynamic>>> apiResponse = ApiResponse(
code: -1,

View File

@@ -383,7 +383,6 @@ class _HomePageState extends State<HomePage> {
.currentColor.sc4,
),
),
].divide(SizedBox(
width: 20.rpx,
)),