trend_controller.dart
973 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import 'package:get/get.dart';
import '../../../report_common/models/health_report_query.dart';
enum TrendType {
hrv,
activity,
sleep;
int get tabIndex => index;
}
/// 趋势页顶层 Controller,仅负责:
/// 顶层 HRV / 活动 / 睡眠 类型切换 (selectedTypeIndex)
class TrendController extends GetxController {
// 第1层类型 Tab(0 = HRV, 1 = 活动, 2 = 睡眠)
final selectedTypeIndex = 0.obs;
// 当前查看的用户。null 表示查看自己;非 null 表示查看指定用户。
final targetUserId = RxnInt();
HealthReportQuery get query => HealthReportQuery(
targetUserId: targetUserId.value,
);
void changeType(int index) {
if (index == selectedTypeIndex.value) return;
selectedTypeIndex.value = index;
}
void selectType(TrendType type) => changeType(type.tabIndex);
void changeTargetUser(int? userId) {
if (userId == targetUserId.value) return;
targetUserId.value = userId;
}
}