Flutter plugin for scanning and generating QR codes using the ZXing library, supporting Android, iOS, and desktop platforms
flutterbarcode-generatorbarcode-scannergeneratorqrqrcodeqrcode-generatorqrcode-scannerscannerzxingbarcodezxscanner
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.4 KiB
62 lines
1.4 KiB
3 years ago
|
import 'package:zxscanner/models/models.dart';
|
||
3 years ago
|
import 'package:hive_flutter/hive_flutter.dart';
|
||
|
|
||
|
class DbService {
|
||
|
DbService._privateConstructor();
|
||
|
|
||
|
static final DbService instance = DbService._privateConstructor();
|
||
|
|
||
|
Future<void> initializeApp() async {
|
||
|
await Hive.initFlutter();
|
||
|
Hive.registerAdapter(CodeAdapter());
|
||
3 years ago
|
Hive.registerAdapter(EncodeAdapter());
|
||
3 years ago
|
|
||
|
await Hive.openBox<Code>('codes');
|
||
|
await Hive.openBox<Encode>('encodes');
|
||
|
}
|
||
|
|
||
|
Box<Code> getCodes() => Hive.box<Code>('codes');
|
||
|
|
||
|
Future deleteCodes() async {
|
||
3 years ago
|
var items = getCodes();
|
||
|
await items.deleteAll(items.keys);
|
||
3 years ago
|
return;
|
||
|
}
|
||
|
|
||
|
Future addCode(Code value) async {
|
||
3 years ago
|
var items = getCodes();
|
||
|
if (!items.values.contains(value)) {
|
||
|
return items.add(value);
|
||
3 years ago
|
}
|
||
|
return;
|
||
|
}
|
||
|
|
||
3 years ago
|
Future<void> deleteCode(Code value) async {
|
||
|
var items = getCodes();
|
||
|
await items.delete(value.key);
|
||
|
return;
|
||
|
}
|
||
|
|
||
3 years ago
|
Box<Encode> getEncodes() => Hive.box<Encode>('encodes');
|
||
|
|
||
|
Future deleteEncodes() async {
|
||
3 years ago
|
var items = getEncodes();
|
||
|
await items.deleteAll(items.keys);
|
||
3 years ago
|
return;
|
||
|
}
|
||
|
|
||
|
Future addEncode(Encode value) async {
|
||
3 years ago
|
var items = getEncodes();
|
||
|
if (!items.values.contains(value)) {
|
||
|
return items.add(value);
|
||
3 years ago
|
}
|
||
|
return;
|
||
|
}
|
||
3 years ago
|
|
||
|
Future<void> deleteEncode(Encode value) async {
|
||
|
var items = getEncodes();
|
||
|
await items.delete(value.key);
|
||
|
return;
|
||
|
}
|
||
3 years ago
|
}
|