friend_models.dart
4.1 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// ─── Responses ───────────────────────────────────────────────────────────────
class FriendListResponse {
const FriendListResponse({this.list = const [], this.limit});
final List<FriendItem> list;
final int? limit;
factory FriendListResponse.fromJson(Map<String, dynamic> json) {
return FriendListResponse(
list: (json['list'] as List<dynamic>?)
?.map((e) => FriendItem.fromJson(e as Map<String, dynamic>))
.toList() ??
const [],
limit: json['limit'] as int?,
);
}
Map<String, dynamic> toJson() => {
'list': list.map((e) => e.toJson()).toList(),
'limit': limit,
};
}
class FriendItem {
const FriendItem({
this.id,
this.userId,
this.friendUserId,
this.remarkName,
this.showInDial,
this.state,
this.createTime,
this.updateTime,
this.avatar,
this.friendNickname,
this.healthData,
});
final int? id;
final int? userId;
final int? friendUserId;
final String? remarkName;
/// 0 = hidden, 1 = shown in dial
final int? showInDial;
/// 1 = normal
final int? state;
final int? createTime;
final int? updateTime;
final String? avatar;
final String? friendNickname;
final FriendHealthData? healthData;
bool get isShowInDial => showInDial == 1;
factory FriendItem.fromJson(Map<String, dynamic> json) {
return FriendItem(
id: json['id'] as int?,
userId: json['user_id'] as int?,
friendUserId: json['friend_user_id'] as int?,
remarkName: json['remark_name'] as String?,
showInDial: json['show_in_dial'] as int?,
state: json['state'] as int?,
createTime: json['create_time'] as int?,
updateTime: json['update_time'] as int?,
avatar: json['avatar'] as String?,
friendNickname: json['friend_nickname'] as String?,
healthData: json['health_data'] == null
? null
: FriendHealthData.fromJson(
json['health_data'] as Map<String, dynamic>),
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (id != null) val['id'] = id;
if (userId != null) val['user_id'] = userId;
if (friendUserId != null) val['friend_user_id'] = friendUserId;
if (remarkName != null) val['remark_name'] = remarkName;
if (showInDial != null) val['show_in_dial'] = showInDial;
if (state != null) val['state'] = state;
if (createTime != null) val['create_time'] = createTime;
if (updateTime != null) val['update_time'] = updateTime;
if (avatar != null) val['avatar'] = avatar;
if (friendNickname != null) val['friend_nickname'] = friendNickname;
if (healthData != null) val['health_data'] = healthData!.toJson();
return val;
}
}
class FriendHealthData {
const FriendHealthData({
this.hrvState,
this.latestHrv,
this.realtimeStress,
this.sleepEvaluate,
this.totalSteps,
});
/// HRV state indicator
final int? hrvState;
/// Latest HRV value used by the friend health card.
final double? latestHrv;
/// Real-time stress data (may be an empty map `{}`)
final Map<String, dynamic>? realtimeStress;
/// Sleep quality score
final int? sleepEvaluate;
/// Total step count for the day (nullable)
final int? totalSteps;
factory FriendHealthData.fromJson(Map<String, dynamic> json) {
return FriendHealthData(
hrvState: json['hrv_state'] as int?,
latestHrv: (json['latest_hrv'] as num?)?.toDouble(),
realtimeStress: json['realtime_stress'] as Map<String, dynamic>?,
sleepEvaluate: json['sleep_evaluate'] as int?,
totalSteps: json['total_steps'] as int?,
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (hrvState != null) val['hrv_state'] = hrvState;
if (latestHrv != null) val['latest_hrv'] = latestHrv;
if (realtimeStress != null) val['realtime_stress'] = realtimeStress;
if (sleepEvaluate != null) val['sleep_evaluate'] = sleepEvaluate;
if (totalSteps != null) val['total_steps'] = totalSteps;
return val;
}
}