import 'package:hive_flutter/hive_flutter.dart'; import '../models/models.dart'; class DbService { DbService._privateConstructor(); static final DbService instance = DbService._privateConstructor(); Future initializeApp() async { await Hive.initFlutter(); Hive.registerAdapter(CodeAdapter()); Hive.registerAdapter(EncodeAdapter()); await Hive.openBox('codes'); await Hive.openBox('encodes'); } Box getCodes() => Hive.box('codes'); Future deleteCodes() async { final Box items = getCodes(); await items.deleteAll(items.keys); } Future addCode(Code value) async { final Box items = getCodes(); if (!items.values.contains(value)) { return items.add(value); } return -1; } Future deleteCode(Code value) async { final Box items = getCodes(); await items.delete(value.key); return; } Box getEncodes() => Hive.box('encodes'); Future deleteEncodes() async { final Box items = getEncodes(); await items.deleteAll(items.keys); } Future addEncode(Encode value) async { final Box items = getEncodes(); if (!items.values.contains(value)) { return items.add(value); } return -1; } Future deleteEncode(Encode value) async { final Box items = getEncodes(); await items.delete(value.key); return; } }