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