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

@@ -20,15 +20,25 @@ class HealthService {
}
HealthRecord getAllRecordByDate(String date) {
return box.values.toList().firstWhere(
final record = box.values.toList().firstWhere(
(item) => item.date == date,
orElse: () => HealthRecord.getEmpty(),
orElse: () => HealthRecord.getEmpty(date),
);
return record.copyWith();
}
Future<bool> updateRecord(HealthRecord record) async {
try {
await record.save();
List<HealthRecord> records =
box.values.where((item) => item.date == record.date).toList();
if (records.isEmpty) {
await addRecord(record);
} else {
await record.save();
}
return true;
} catch (e) {
return false;