fix:修复更新记录失败的问题
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user