import 'package:flisp_app/models/flisp.dart'; import 'package:hive_flutter/hive_flutter.dart'; class FlispService { static const String boxName = 'flisps'; Box get box => Hive.box(boxName); Future addFlisp(Flisp flisp) async { try { await box.add(flisp); return true; } catch (e) { return false; } } List getAllFlisps() { return box.values.toList() ..sort((a, b) => b.updateTime.compareTo(a.updateTime)); } List getAllFlispsByYear(int year) { return box.values .toList() .where((flisp) => flisp.createTime.year == year) .toList(); } Future updateFlisp(Flisp flisp) async { try { flisp.updateTime = DateTime.now(); await flisp.save(); return true; } catch (e) { return false; } } Future deleteFlisp(Flisp flisp) async { try { await flisp.delete(); return true; } catch (e) { return false; } } }