fix:修复更新记录失败的问题

This commit is contained in:
2025-12-02 22:21:38 +08:00
parent b3bb3378c3
commit e2853483f7
6 changed files with 42 additions and 24 deletions

View File

@@ -93,18 +93,19 @@ class HealthService {
Future<bool> updateRecord(HealthRecord record) async {
try {
print(record.date);
final existingRecords =
box.values.where((item) => item.date == record.date).toList();
final existingRecords = box.values.toList();
final index = existingRecords.indexWhere((item) => item.date == record.date);
if (existingRecords.isEmpty) {
await addRecord(record);
if (index == -1) {
await box.add(record);
} else {
await record.save();
final key = box.keyAt(index);
await box.put(key, record);
}
return true;
} catch (e) {
print(e.toString());
print('Update record error: $e');
return false;
}
}