Khoren Markosyan
3 years ago
17 changed files with 337 additions and 61 deletions
@ -1,3 +1,7 @@
|
||||
{ |
||||
"cmake.sourceDirectory": "${workspaceFolder}/ios/Classes/src" |
||||
"cmake.sourceDirectory": "${workspaceFolder}/ios/Classes/src", |
||||
"files.associations": { |
||||
"__config": "cpp", |
||||
"__nullptr": "cpp" |
||||
} |
||||
} |
@ -0,0 +1,24 @@
|
||||
import 'package:flutter_zxing/flutter_zxing.dart'; |
||||
import 'package:hive_flutter/hive_flutter.dart'; |
||||
|
||||
part "code.g.dart"; |
||||
|
||||
@HiveType(typeId: 0) |
||||
class Code extends HiveObject { |
||||
@HiveField(0) |
||||
bool? isValid; |
||||
|
||||
@HiveField(1) |
||||
int? format; |
||||
|
||||
@HiveField(2) |
||||
String? text; |
||||
|
||||
Code(); |
||||
|
||||
Code.fromCodeResult(CodeResult result) { |
||||
isValid = result.isValidBool; |
||||
format = result.format; |
||||
text = result.textString; |
||||
} |
||||
} |
@ -0,0 +1,46 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND |
||||
|
||||
part of 'code.dart'; |
||||
|
||||
// ************************************************************************** |
||||
// TypeAdapterGenerator |
||||
// ************************************************************************** |
||||
|
||||
class CodeAdapter extends TypeAdapter<Code> { |
||||
@override |
||||
final int typeId = 0; |
||||
|
||||
@override |
||||
Code read(BinaryReader reader) { |
||||
final numOfFields = reader.readByte(); |
||||
final fields = <int, dynamic>{ |
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), |
||||
}; |
||||
return Code() |
||||
..isValid = fields[0] as bool? |
||||
..format = fields[1] as int? |
||||
..text = fields[2] as String?; |
||||
} |
||||
|
||||
@override |
||||
void write(BinaryWriter writer, Code obj) { |
||||
writer |
||||
..writeByte(3) |
||||
..writeByte(0) |
||||
..write(obj.isValid) |
||||
..writeByte(1) |
||||
..write(obj.format) |
||||
..writeByte(2) |
||||
..write(obj.text); |
||||
} |
||||
|
||||
@override |
||||
int get hashCode => typeId.hashCode; |
||||
|
||||
@override |
||||
bool operator ==(Object other) => |
||||
identical(this, other) || |
||||
other is CodeAdapter && |
||||
runtimeType == other.runtimeType && |
||||
typeId == other.typeId; |
||||
} |
@ -0,0 +1,34 @@
|
||||
import 'dart:typed_data'; |
||||
|
||||
import 'package:flutter_zxing/flutter_zxing.dart'; |
||||
import 'package:hive_flutter/hive_flutter.dart'; |
||||
|
||||
part "encode.g.dart"; |
||||
|
||||
@HiveType(typeId: 1) |
||||
class Encode extends HiveObject { |
||||
@HiveField(0) |
||||
bool? isValid; |
||||
|
||||
@HiveField(1) |
||||
int? format; |
||||
|
||||
@HiveField(2) |
||||
String? text; |
||||
|
||||
@HiveField(3) |
||||
Uint8List? data; |
||||
|
||||
@HiveField(4) |
||||
int? length; |
||||
|
||||
Encode(); |
||||
|
||||
Encode.fromEncodeResult(EncodeResult result) { |
||||
isValid = result.isValidBool; |
||||
format = result.format; |
||||
text = result.textString; |
||||
data = result.bytes as Uint8List?; |
||||
length = result.length; |
||||
} |
||||
} |
@ -0,0 +1,52 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND |
||||
|
||||
part of 'encode.dart'; |
||||
|
||||
// ************************************************************************** |
||||
// TypeAdapterGenerator |
||||
// ************************************************************************** |
||||
|
||||
class EncodeAdapter extends TypeAdapter<Encode> { |
||||
@override |
||||
final int typeId = 1; |
||||
|
||||
@override |
||||
Encode read(BinaryReader reader) { |
||||
final numOfFields = reader.readByte(); |
||||
final fields = <int, dynamic>{ |
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), |
||||
}; |
||||
return Encode() |
||||
..isValid = fields[0] as bool? |
||||
..format = fields[1] as int? |
||||
..text = fields[2] as String? |
||||
..data = fields[3] as Uint8List? |
||||
..length = fields[4] as int?; |
||||
} |
||||
|
||||
@override |
||||
void write(BinaryWriter writer, Encode obj) { |
||||
writer |
||||
..writeByte(5) |
||||
..writeByte(0) |
||||
..write(obj.isValid) |
||||
..writeByte(1) |
||||
..write(obj.format) |
||||
..writeByte(2) |
||||
..write(obj.text) |
||||
..writeByte(3) |
||||
..write(obj.data) |
||||
..writeByte(4) |
||||
..write(obj.length); |
||||
} |
||||
|
||||
@override |
||||
int get hashCode => typeId.hashCode; |
||||
|
||||
@override |
||||
bool operator ==(Object other) => |
||||
identical(this, other) || |
||||
other is EncodeAdapter && |
||||
runtimeType == other.runtimeType && |
||||
typeId == other.typeId; |
||||
} |
@ -0,0 +1,2 @@
|
||||
export 'code.dart'; |
||||
export 'encode.dart'; |
@ -0,0 +1,50 @@
|
||||
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<void> initializeApp() async { |
||||
await Hive.initFlutter(); |
||||
Hive.registerAdapter(CodeAdapter()); |
||||
|
||||
await Hive.openBox<Code>('codes'); |
||||
await Hive.openBox<Encode>('encodes'); |
||||
|
||||
// Hive.box('codes').close(); |
||||
} |
||||
|
||||
Box<Code> getCodes() => Hive.box<Code>('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<Encode> getEncodes() => Hive.box<Encode>('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; |
||||
} |
||||
} |
Loading…
Reference in new issue