feat:增加睡眠记录

This commit is contained in:
2025-12-02 14:09:56 +08:00
parent 2cc69b4019
commit 8a71ea542e
14 changed files with 402 additions and 129 deletions

View File

@@ -25,9 +25,6 @@ class HealthRecord extends HiveObject {
@HiveField(5)
String sleepEndTime;
@HiveField(6)
num sleepDuration;
@HiveField(7)
String date;
@@ -38,11 +35,10 @@ class HealthRecord extends HiveObject {
required this.weight,
required this.sleepStartTime,
required this.sleepEndTime,
required this.sleepDuration,
required this.date,
});
static HealthRecord getEmpty() {
static HealthRecord getEmpty(String date) {
return HealthRecord(
id: DateTime.now().millisecondsSinceEpoch ~/ 1000,
sportProject: '',
@@ -50,21 +46,27 @@ class HealthRecord extends HiveObject {
weight: 0,
sleepStartTime: '',
sleepEndTime: '',
sleepDuration: 0,
date: '',
date: date,
);
}
static HealthRecord getDefault() {
HealthRecord copyWith({
int? id,
num? weight,
String? sportProject,
num? sportDuration,
String? sleepStartTime,
String? sleepEndTime,
String? date,
}) {
return HealthRecord(
id: DateTime.now().millisecondsSinceEpoch ~/ 1000,
sportProject: '跑步',
sportDuration: 30,
weight: 70,
sleepStartTime: '',
sleepEndTime: '',
sleepDuration: 0,
date: '',
id: id ?? this.id,
date: date ?? this.date,
weight: weight ?? this.weight,
sportProject: sportProject ?? this.sportProject,
sportDuration: sportDuration ?? this.sportDuration,
sleepStartTime: sleepStartTime ?? this.sleepStartTime,
sleepEndTime: sleepEndTime ?? this.sleepEndTime
);
}
}

View File

@@ -23,7 +23,6 @@ class HealthRecordAdapter extends TypeAdapter<HealthRecord> {
weight: fields[3] as num,
sleepStartTime: fields[4] as String,
sleepEndTime: fields[5] as String,
sleepDuration: fields[6] as num,
date: fields[7] as String,
);
}
@@ -31,7 +30,7 @@ class HealthRecordAdapter extends TypeAdapter<HealthRecord> {
@override
void write(BinaryWriter writer, HealthRecord obj) {
writer
..writeByte(8)
..writeByte(7)
..writeByte(0)
..write(obj.id)
..writeByte(1)
@@ -44,8 +43,6 @@ class HealthRecordAdapter extends TypeAdapter<HealthRecord> {
..write(obj.sleepStartTime)
..writeByte(5)
..write(obj.sleepEndTime)
..writeByte(6)
..write(obj.sleepDuration)
..writeByte(7)
..write(obj.date);
}