feat : cashing data in local storage and send it
This commit is contained in:
@@ -8,7 +8,7 @@ import 'presentation/routes/auth_route_resolver_impl.dart';
|
|||||||
|
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
await Hive.initFlutter();
|
||||||
await setupPreInjection();
|
await setupPreInjection();
|
||||||
Get.put(TokenStorageService());
|
Get.put(TokenStorageService());
|
||||||
await Get.find<TokenStorageService>().init();
|
await Get.find<TokenStorageService>().init();
|
||||||
|
|||||||
3
packages/core/devtools_options.yaml
Normal file
3
packages/core/devtools_options.yaml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
description: This file stores settings for Dart & Flutter DevTools.
|
||||||
|
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
|
||||||
|
extensions:
|
||||||
@@ -21,7 +21,7 @@ class TokenStorageService extends GetxService {
|
|||||||
Rxn<Module> appModule = Rxn(null);
|
Rxn<Module> appModule = Rxn(null);
|
||||||
|
|
||||||
Future<void> init() async {
|
Future<void> init() async {
|
||||||
await Hive.initFlutter();
|
|
||||||
Hive.registerAdapters();
|
Hive.registerAdapters();
|
||||||
|
|
||||||
final String? encryptedKey = await _secureStorage.read(key: 'hive_enc_key');
|
final String? encryptedKey = await _secureStorage.read(key: 'hive_enc_key');
|
||||||
|
|||||||
@@ -4,4 +4,12 @@ const int authModuleTypeId = 1;
|
|||||||
|
|
||||||
//chicken
|
//chicken
|
||||||
const int chickenWidelyUsedLocalModelTypeId = 2;
|
const int chickenWidelyUsedLocalModelTypeId = 2;
|
||||||
const int chickenWidelyUsedLocalItemTypeId = 3;
|
const int chickenWidelyUsedLocalItemTypeId = 3;
|
||||||
|
|
||||||
|
//liveStock
|
||||||
|
|
||||||
|
const int liveStockDataLocalModelTypeId = 4;
|
||||||
|
const int liveStockDataRancherLocalModelTypeId = 5;
|
||||||
|
const int liveStockDataHerdLocalModelTypeId = 6;
|
||||||
|
const int liveStockDataLocationLocalModelTypeId = 7;
|
||||||
|
const int liveStockDataLivestockLocalModelTypeId = 8;
|
||||||
3
packages/inspection/devtools_options.yaml
Normal file
3
packages/inspection/devtools_options.yaml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
description: This file stores settings for Dart & Flutter DevTools.
|
||||||
|
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
|
||||||
|
extensions:
|
||||||
3
packages/livestock/devtools_options.yaml
Normal file
3
packages/livestock/devtools_options.yaml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
description: This file stores settings for Dart & Flutter DevTools.
|
||||||
|
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
|
||||||
|
extensions:
|
||||||
@@ -33,8 +33,8 @@ class LivestockRemoteDataSourceImp implements LivestockRemoteDataSource {
|
|||||||
try {
|
try {
|
||||||
Dio dio = Dio();
|
Dio dio = Dio();
|
||||||
dio.interceptors.add(PrettyDioLogger(
|
dio.interceptors.add(PrettyDioLogger(
|
||||||
requestBody: true,
|
requestBody: false,
|
||||||
responseBody: true,
|
responseBody: false,
|
||||||
requestHeader: true,
|
requestHeader: true,
|
||||||
responseHeader: true,
|
responseHeader: true,
|
||||||
error: true,
|
error: true,
|
||||||
|
|||||||
39
packages/livestock/lib/data/model/local/live_tmp/car.dart
Normal file
39
packages/livestock/lib/data/model/local/live_tmp/car.dart
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import 'package:rasadyar_core/core.dart';
|
||||||
|
|
||||||
|
|
||||||
|
part 'car.g.dart';
|
||||||
|
|
||||||
|
|
||||||
|
@HiveType(typeId: 50)
|
||||||
|
class CarsLocal extends HiveObject {
|
||||||
|
@HiveField(0)
|
||||||
|
String? name;
|
||||||
|
|
||||||
|
@HiveField(1)
|
||||||
|
String? price;
|
||||||
|
|
||||||
|
CarsLocal({this.name, this.price});
|
||||||
|
|
||||||
|
factory CarsLocal.fromJson(Map<String, dynamic> json) {
|
||||||
|
return CarsLocal(name: json['name'] as String?, price: json['price'] as String?);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
return {'name': name, 'price': price};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Cars {
|
||||||
|
String? name;
|
||||||
|
String? price;
|
||||||
|
|
||||||
|
Cars({this.name, this.price});
|
||||||
|
|
||||||
|
factory Cars.fromJson(Map<String, dynamic> json) {
|
||||||
|
return Cars(name: json['name'] as String?, price: json['price'] as String?);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
return {'name': name, 'price': price};
|
||||||
|
}
|
||||||
|
}
|
||||||
41
packages/livestock/lib/data/model/local/live_tmp/car.g.dart
Normal file
41
packages/livestock/lib/data/model/local/live_tmp/car.g.dart
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
|
||||||
|
part of 'car.dart';
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// TypeAdapterGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
class CarsLocalAdapter extends TypeAdapter<CarsLocal> {
|
||||||
|
@override
|
||||||
|
final typeId = 50;
|
||||||
|
|
||||||
|
@override
|
||||||
|
CarsLocal read(BinaryReader reader) {
|
||||||
|
final numOfFields = reader.readByte();
|
||||||
|
final fields = <int, dynamic>{
|
||||||
|
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||||
|
};
|
||||||
|
return CarsLocal(name: fields[0] as String?, price: fields[1] as String?);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void write(BinaryWriter writer, CarsLocal obj) {
|
||||||
|
writer
|
||||||
|
..writeByte(2)
|
||||||
|
..writeByte(0)
|
||||||
|
..write(obj.name)
|
||||||
|
..writeByte(1)
|
||||||
|
..write(obj.price);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => typeId.hashCode;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) =>
|
||||||
|
identical(this, other) ||
|
||||||
|
other is CarsLocalAdapter &&
|
||||||
|
runtimeType == other.runtimeType &&
|
||||||
|
typeId == other.typeId;
|
||||||
|
}
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
import 'package:rasadyar_core/core.dart';
|
||||||
|
|
||||||
|
|
||||||
|
part 'livestock_local_model.g.dart';
|
||||||
|
|
||||||
|
@HiveType(typeId: liveStockDataLocalModelTypeId)
|
||||||
|
class LivestockLocalModel extends HiveObject {
|
||||||
|
|
||||||
|
|
||||||
|
@HiveField(0)
|
||||||
|
RancherLocal? rancher;
|
||||||
|
|
||||||
|
@HiveField(1)
|
||||||
|
HerdLocal? herd;
|
||||||
|
|
||||||
|
@HiveField(2)
|
||||||
|
List<LivestockLocal>? livestock;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@HiveType(typeId: liveStockDataRancherLocalModelTypeId)
|
||||||
|
class RancherLocal extends HiveObject {
|
||||||
|
|
||||||
|
@HiveField(0)
|
||||||
|
String? name;
|
||||||
|
|
||||||
|
@HiveField(1)
|
||||||
|
String? phone;
|
||||||
|
|
||||||
|
@HiveField(2)
|
||||||
|
String? image;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@HiveType(typeId: liveStockDataHerdLocalModelTypeId)
|
||||||
|
class HerdLocal extends HiveObject{
|
||||||
|
|
||||||
|
@HiveField(0)
|
||||||
|
LocationLocal? location;
|
||||||
|
|
||||||
|
@HiveField(1)
|
||||||
|
String? address;
|
||||||
|
|
||||||
|
@HiveField(2)
|
||||||
|
String? image;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@HiveType(typeId: liveStockDataLocationLocalModelTypeId)
|
||||||
|
class LocationLocal extends HiveObject {
|
||||||
|
|
||||||
|
@HiveField(0)
|
||||||
|
double? lat;
|
||||||
|
|
||||||
|
@HiveField(1)
|
||||||
|
double? lng;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@HiveType(typeId: liveStockDataLivestockLocalModelTypeId)
|
||||||
|
class LivestockLocal extends HiveObject {
|
||||||
|
|
||||||
|
|
||||||
|
@HiveField(0)
|
||||||
|
String? species;
|
||||||
|
|
||||||
|
@HiveField(1)
|
||||||
|
String? breed;
|
||||||
|
|
||||||
|
@HiveField(2)
|
||||||
|
String? dateOfBirth;
|
||||||
|
|
||||||
|
@HiveField(3)
|
||||||
|
String? sex;
|
||||||
|
|
||||||
|
@HiveField(4)
|
||||||
|
String? motherTag;
|
||||||
|
|
||||||
|
@HiveField(5)
|
||||||
|
String? fatherTag;
|
||||||
|
|
||||||
|
@HiveField(6)
|
||||||
|
String? tagNumber;
|
||||||
|
|
||||||
|
@HiveField(7)
|
||||||
|
String? tagType;
|
||||||
|
|
||||||
|
@HiveField(8)
|
||||||
|
String? image;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,217 @@
|
|||||||
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
|
||||||
|
part of 'livestock_local_model.dart';
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// TypeAdapterGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
class LivestockLocalModelAdapter extends TypeAdapter<LivestockLocalModel> {
|
||||||
|
@override
|
||||||
|
final typeId = 4;
|
||||||
|
|
||||||
|
@override
|
||||||
|
LivestockLocalModel read(BinaryReader reader) {
|
||||||
|
final numOfFields = reader.readByte();
|
||||||
|
final fields = <int, dynamic>{
|
||||||
|
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||||
|
};
|
||||||
|
return LivestockLocalModel()
|
||||||
|
..rancher = fields[0] as RancherLocal?
|
||||||
|
..herd = fields[1] as HerdLocal?
|
||||||
|
..livestock = (fields[2] as List?)?.cast<LivestockLocal>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void write(BinaryWriter writer, LivestockLocalModel obj) {
|
||||||
|
writer
|
||||||
|
..writeByte(3)
|
||||||
|
..writeByte(0)
|
||||||
|
..write(obj.rancher)
|
||||||
|
..writeByte(1)
|
||||||
|
..write(obj.herd)
|
||||||
|
..writeByte(2)
|
||||||
|
..write(obj.livestock);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => typeId.hashCode;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) =>
|
||||||
|
identical(this, other) ||
|
||||||
|
other is LivestockLocalModelAdapter &&
|
||||||
|
runtimeType == other.runtimeType &&
|
||||||
|
typeId == other.typeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
class RancherLocalAdapter extends TypeAdapter<RancherLocal> {
|
||||||
|
@override
|
||||||
|
final typeId = 5;
|
||||||
|
|
||||||
|
@override
|
||||||
|
RancherLocal read(BinaryReader reader) {
|
||||||
|
final numOfFields = reader.readByte();
|
||||||
|
final fields = <int, dynamic>{
|
||||||
|
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||||
|
};
|
||||||
|
return RancherLocal()
|
||||||
|
..name = fields[0] as String?
|
||||||
|
..phone = fields[1] as String?
|
||||||
|
..image = fields[2] as String?;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void write(BinaryWriter writer, RancherLocal obj) {
|
||||||
|
writer
|
||||||
|
..writeByte(3)
|
||||||
|
..writeByte(0)
|
||||||
|
..write(obj.name)
|
||||||
|
..writeByte(1)
|
||||||
|
..write(obj.phone)
|
||||||
|
..writeByte(2)
|
||||||
|
..write(obj.image);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => typeId.hashCode;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) =>
|
||||||
|
identical(this, other) ||
|
||||||
|
other is RancherLocalAdapter &&
|
||||||
|
runtimeType == other.runtimeType &&
|
||||||
|
typeId == other.typeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
class HerdLocalAdapter extends TypeAdapter<HerdLocal> {
|
||||||
|
@override
|
||||||
|
final typeId = 6;
|
||||||
|
|
||||||
|
@override
|
||||||
|
HerdLocal read(BinaryReader reader) {
|
||||||
|
final numOfFields = reader.readByte();
|
||||||
|
final fields = <int, dynamic>{
|
||||||
|
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||||
|
};
|
||||||
|
return HerdLocal()
|
||||||
|
..location = fields[0] as LocationLocal?
|
||||||
|
..address = fields[1] as String?
|
||||||
|
..image = fields[2] as String?;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void write(BinaryWriter writer, HerdLocal obj) {
|
||||||
|
writer
|
||||||
|
..writeByte(3)
|
||||||
|
..writeByte(0)
|
||||||
|
..write(obj.location)
|
||||||
|
..writeByte(1)
|
||||||
|
..write(obj.address)
|
||||||
|
..writeByte(2)
|
||||||
|
..write(obj.image);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => typeId.hashCode;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) =>
|
||||||
|
identical(this, other) ||
|
||||||
|
other is HerdLocalAdapter &&
|
||||||
|
runtimeType == other.runtimeType &&
|
||||||
|
typeId == other.typeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
class LocationLocalAdapter extends TypeAdapter<LocationLocal> {
|
||||||
|
@override
|
||||||
|
final typeId = 7;
|
||||||
|
|
||||||
|
@override
|
||||||
|
LocationLocal read(BinaryReader reader) {
|
||||||
|
final numOfFields = reader.readByte();
|
||||||
|
final fields = <int, dynamic>{
|
||||||
|
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||||
|
};
|
||||||
|
return LocationLocal()
|
||||||
|
..lat = (fields[0] as num?)?.toDouble()
|
||||||
|
..lng = (fields[1] as num?)?.toDouble();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void write(BinaryWriter writer, LocationLocal obj) {
|
||||||
|
writer
|
||||||
|
..writeByte(2)
|
||||||
|
..writeByte(0)
|
||||||
|
..write(obj.lat)
|
||||||
|
..writeByte(1)
|
||||||
|
..write(obj.lng);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => typeId.hashCode;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) =>
|
||||||
|
identical(this, other) ||
|
||||||
|
other is LocationLocalAdapter &&
|
||||||
|
runtimeType == other.runtimeType &&
|
||||||
|
typeId == other.typeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
class LivestockLocalAdapter extends TypeAdapter<LivestockLocal> {
|
||||||
|
@override
|
||||||
|
final typeId = 8;
|
||||||
|
|
||||||
|
@override
|
||||||
|
LivestockLocal read(BinaryReader reader) {
|
||||||
|
final numOfFields = reader.readByte();
|
||||||
|
final fields = <int, dynamic>{
|
||||||
|
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||||
|
};
|
||||||
|
return LivestockLocal()
|
||||||
|
..species = fields[0] as String?
|
||||||
|
..breed = fields[1] as String?
|
||||||
|
..dateOfBirth = fields[2] as String?
|
||||||
|
..sex = fields[3] as String?
|
||||||
|
..motherTag = fields[4] as String?
|
||||||
|
..fatherTag = fields[5] as String?
|
||||||
|
..tagNumber = fields[6] as String?
|
||||||
|
..tagType = fields[7] as String?
|
||||||
|
..image = fields[8] as String?;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void write(BinaryWriter writer, LivestockLocal obj) {
|
||||||
|
writer
|
||||||
|
..writeByte(9)
|
||||||
|
..writeByte(0)
|
||||||
|
..write(obj.species)
|
||||||
|
..writeByte(1)
|
||||||
|
..write(obj.breed)
|
||||||
|
..writeByte(2)
|
||||||
|
..write(obj.dateOfBirth)
|
||||||
|
..writeByte(3)
|
||||||
|
..write(obj.sex)
|
||||||
|
..writeByte(4)
|
||||||
|
..write(obj.motherTag)
|
||||||
|
..writeByte(5)
|
||||||
|
..write(obj.fatherTag)
|
||||||
|
..writeByte(6)
|
||||||
|
..write(obj.tagNumber)
|
||||||
|
..writeByte(7)
|
||||||
|
..write(obj.tagType)
|
||||||
|
..writeByte(8)
|
||||||
|
..write(obj.image);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => typeId.hashCode;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) =>
|
||||||
|
identical(this, other) ||
|
||||||
|
other is LivestockLocalAdapter &&
|
||||||
|
runtimeType == other.runtimeType &&
|
||||||
|
typeId == other.typeId;
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import 'package:rasadyar_core/core.dart';
|
||||||
|
import 'package:rasadyar_livestock/data/model/local/live_tmp/car.dart';
|
||||||
|
import 'package:rasadyar_livestock/data/model/local/live_tmp/livestock_local_model.dart';
|
||||||
|
import 'package:rasadyar_livestock/data/model/response/live_tmp/livestock_model.dart';
|
||||||
|
import 'package:rasadyar_livestock/data/utils/mapper.dart';
|
||||||
|
|
||||||
|
class LiveStockStorageService extends GetxService {
|
||||||
|
final String _liveStockBoxName = 'LiveStockBox';
|
||||||
|
late IsolatedBox<LivestockLocalModel> _LiveStockbox;
|
||||||
|
late IsolatedBox<CarsLocal> _carbox;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onInit() {
|
||||||
|
super.onInit();
|
||||||
|
wLog('LiveStockStorageService onInit');
|
||||||
|
IsolatedHive.openBox<LivestockLocalModel>(_liveStockBoxName).then((value) {
|
||||||
|
_LiveStockbox = value;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> saveLiveStockData(LivestockData livestockData) async {
|
||||||
|
LivestockLocalModel tmp = livestockData.toLocal();
|
||||||
|
await _LiveStockbox.add(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> saveBulkLiveStockData(Iterable<LivestockData> livesList) async {
|
||||||
|
var tmp = livesList.map((e) => e.toLocal()).toList();
|
||||||
|
await _LiveStockbox.addAll(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<List<LivestockData>> getLiveStockData() async {
|
||||||
|
var liveLocationList = await _LiveStockbox.values;
|
||||||
|
var res = liveLocationList.map((e) => e.toData()).toList();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<int> deleteLiveBox() async {
|
||||||
|
return await _LiveStockbox.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
106
packages/livestock/lib/data/utils/mapper.dart
Normal file
106
packages/livestock/lib/data/utils/mapper.dart
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
import '../model/local/live_tmp/livestock_local_model.dart';
|
||||||
|
import '../model/response/live_tmp/livestock_model.dart';
|
||||||
|
|
||||||
|
// Extension for LivestockData to convert to LivestockLocalModel
|
||||||
|
extension LivestockDataX on LivestockData {
|
||||||
|
LivestockLocalModel toLocal() {
|
||||||
|
return LivestockLocalModel()
|
||||||
|
..rancher = rancher?.toLocal()
|
||||||
|
..herd = herd?.toLocal()
|
||||||
|
..livestock = livestock?.map((e) => e.toLocal()).toList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extension for LivestockLocalModel to convert to LivestockData
|
||||||
|
extension LivestockLocalModelX on LivestockLocalModel {
|
||||||
|
LivestockData toData() {
|
||||||
|
return LivestockData(
|
||||||
|
rancher: rancher?.toData(),
|
||||||
|
herd: herd?.toData(),
|
||||||
|
livestock: livestock?.map((e) => e.toData()).toList(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extension for Rancher to convert to RancherLocal
|
||||||
|
extension RancherX on Rancher {
|
||||||
|
RancherLocal toLocal() {
|
||||||
|
return RancherLocal()
|
||||||
|
..name = name
|
||||||
|
..phone = phone
|
||||||
|
..image = image;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extension for RancherLocal to convert to Rancher
|
||||||
|
extension RancherLocalX on RancherLocal {
|
||||||
|
Rancher toData() {
|
||||||
|
return Rancher(name: name, phone: phone, image: image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extension for Herd to convert to HerdLocal
|
||||||
|
extension HerdX on Herd {
|
||||||
|
HerdLocal toLocal() {
|
||||||
|
return HerdLocal()
|
||||||
|
..location = location?.toLocal()
|
||||||
|
..address = address
|
||||||
|
..image = image;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extension for HerdLocal to convert to Herd
|
||||||
|
extension HerdLocalX on HerdLocal {
|
||||||
|
Herd toData() {
|
||||||
|
return Herd(location: location?.toData(), address: address, image: image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extension for Location to convert to LocationLocal
|
||||||
|
extension LocationX on Location {
|
||||||
|
LocationLocal toLocal() {
|
||||||
|
return LocationLocal()
|
||||||
|
..lat = lat
|
||||||
|
..lng = lng;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extension for LocationLocal to convert to Location
|
||||||
|
extension LocationLocalX on LocationLocal {
|
||||||
|
Location toData() {
|
||||||
|
return Location(lat: lat, lng: lng);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extension for Livestock to convert to LivestockLocal
|
||||||
|
extension LivestockX on Livestock {
|
||||||
|
LivestockLocal toLocal() {
|
||||||
|
return LivestockLocal()
|
||||||
|
..species = species
|
||||||
|
..breed = breed
|
||||||
|
..dateOfBirth = dateOfBirth
|
||||||
|
..sex = sex
|
||||||
|
..motherTag = motherTag
|
||||||
|
..fatherTag = fatherTag
|
||||||
|
..tagNumber = tagNumber
|
||||||
|
..tagType = tagType
|
||||||
|
..image = image;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extension for LivestockLocal to convert to Livestock
|
||||||
|
extension LivestockLocalX on LivestockLocal {
|
||||||
|
Livestock toData() {
|
||||||
|
return Livestock(
|
||||||
|
species: species,
|
||||||
|
breed: breed,
|
||||||
|
dateOfBirth: dateOfBirth,
|
||||||
|
sex: sex,
|
||||||
|
motherTag: motherTag,
|
||||||
|
fatherTag: fatherTag,
|
||||||
|
tagNumber: tagNumber,
|
||||||
|
tagType: tagType,
|
||||||
|
image: image,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
29
packages/livestock/lib/hive_registrar.g.dart
Normal file
29
packages/livestock/lib/hive_registrar.g.dart
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
// Generated by Hive CE
|
||||||
|
// Do not modify
|
||||||
|
// Check in to version control
|
||||||
|
|
||||||
|
import 'package:hive_ce/hive.dart';
|
||||||
|
import 'package:rasadyar_livestock/data/model/local/live_tmp/car.dart';
|
||||||
|
import 'package:rasadyar_livestock/data/model/local/live_tmp/livestock_local_model.dart';
|
||||||
|
|
||||||
|
extension HiveRegistrar on HiveInterface {
|
||||||
|
void registerAdapters() {
|
||||||
|
registerAdapter(CarsLocalAdapter());
|
||||||
|
registerAdapter(HerdLocalAdapter());
|
||||||
|
registerAdapter(LivestockLocalAdapter());
|
||||||
|
registerAdapter(LivestockLocalModelAdapter());
|
||||||
|
registerAdapter(LocationLocalAdapter());
|
||||||
|
registerAdapter(RancherLocalAdapter());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension IsolatedHiveRegistrar on IsolatedHiveInterface {
|
||||||
|
void registerAdapters() {
|
||||||
|
registerAdapter(CarsLocalAdapter());
|
||||||
|
registerAdapter(HerdLocalAdapter());
|
||||||
|
registerAdapter(LivestockLocalAdapter());
|
||||||
|
registerAdapter(LivestockLocalModelAdapter());
|
||||||
|
registerAdapter(LocationLocalAdapter());
|
||||||
|
registerAdapter(RancherLocalAdapter());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,14 +8,20 @@ import 'package:rasadyar_livestock/data/repository/auth/auth_repository.dart';
|
|||||||
import 'package:rasadyar_livestock/data/repository/auth/auth_repository_imp.dart';
|
import 'package:rasadyar_livestock/data/repository/auth/auth_repository_imp.dart';
|
||||||
import 'package:rasadyar_livestock/data/repository/livestock/livestock_repository.dart';
|
import 'package:rasadyar_livestock/data/repository/livestock/livestock_repository.dart';
|
||||||
import 'package:rasadyar_livestock/data/repository/livestock/livestock_repository_imp.dart';
|
import 'package:rasadyar_livestock/data/repository/livestock/livestock_repository_imp.dart';
|
||||||
|
import 'package:rasadyar_livestock/data/service/live_stock_storage_service.dart';
|
||||||
|
import 'package:rasadyar_livestock/hive_registrar.g.dart';
|
||||||
import 'package:rasadyar_livestock/presentation/routes/app_pages.dart';
|
import 'package:rasadyar_livestock/presentation/routes/app_pages.dart';
|
||||||
|
|
||||||
GetIt get diLiveStock => GetIt.instance;
|
GetIt get diLiveStock => GetIt.instance;
|
||||||
|
|
||||||
Future<void> setupLiveStockDI() async {
|
Future<void> setupLiveStockDI() async {
|
||||||
diLiveStock.registerSingleton(DioErrorHandler());
|
diLiveStock.registerSingleton(DioErrorHandler());
|
||||||
|
await IsolatedHive.initFlutter();
|
||||||
|
IsolatedHive.registerAdapters();
|
||||||
|
iLog("Sssssssssssssssssssss");
|
||||||
final tokenService = Get.find<TokenStorageService>();
|
final tokenService = Get.find<TokenStorageService>();
|
||||||
|
Get.put<LiveStockStorageService>(LiveStockStorageService());
|
||||||
|
|
||||||
|
|
||||||
if (tokenService.baseurl.value == null) {
|
if (tokenService.baseurl.value == null) {
|
||||||
await tokenService.saveBaseUrl('https://api.dam.rasadyar.net/');
|
await tokenService.saveBaseUrl('https://api.dam.rasadyar.net/');
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user