import 'package:fitnote/models/health.dart'; import 'package:hive_flutter/hive_flutter.dart'; class HealthService { static const String boxName = 'healths'; Box get box => Hive.box(boxName); Future addRecord(HealthRecord record) async { try { await box.add(record); return true; } catch (e) { return false; } } List getAllRecords() { return box.values.toList(); } HealthRecord getAllRecordByDate(String date) { return box.values.toList().firstWhere( (item) => item.date == date, orElse: () => HealthRecord.getEmpty(), ); } Future updateRecord(HealthRecord record) async { try { await record.save(); return true; } catch (e) { return false; } } Future deleteRecord(HealthRecord record) async { try { await record.delete(); return true; } catch (e) { return false; } } }