feat : local location loading

This commit is contained in:
2025-08-19 11:56:04 +03:30
parent 7c3c1280b2
commit b2f26cdffd
4 changed files with 24 additions and 20 deletions

View File

@@ -10,6 +10,6 @@ abstract class LivestockRepository {
Future<bool> createTaggingLiveStock({required LivestockData data});
/* Future<List<LatLng>> getLocations();
Future<void> addLocations(List<LatLng> latList);*/
Future<List<LatLng>> getLocations();
Future<void> addLocations(List<LatLng> latList);
}

View File

@@ -1,4 +1,3 @@
import 'package:latlong2/latlong.dart';
import 'package:rasadyar_core/core.dart';
import 'package:rasadyar_core/data/services/network_status.dart';
import 'package:rasadyar_livestock/data/data_source/local/tmp/tmp_local_data-source.dart';
@@ -11,8 +10,9 @@ import 'livestock_repository.dart';
class LivestockRepositoryImp implements LivestockRepository {
final LivestockRemoteDataSource livestockRemote;
final TmpLocalDataSource tmpLocalDataSource;
LivestockRepositoryImp({required this.livestockRemote});
LivestockRepositoryImp({required this.livestockRemote,required this.tmpLocalDataSource});
@override
Future<LocationDetails?> getLocationDetails({
@@ -29,7 +29,7 @@ class LivestockRepositoryImp implements LivestockRepository {
Future<bool> createTaggingLiveStock({required LivestockData data}) async {
return await livestockRemote.createTaggingLiveStock(data: data);
}
/*
@override
Future<List<LatLng>> getLocations() async {
if (NetworkStatus().isConnected.value) {
@@ -47,17 +47,17 @@ class LivestockRepositoryImp implements LivestockRepository {
LatLng(35.832000, 50.956055),
];
} else {
*//*var res = await tmpLocalDataSource.getLocations();
var res = await tmpLocalDataSource.getLocations();
return res.map((e) => LatLng(e.lat ?? 0.0, e.long ?? 0.0)).toList();*//*
return res.map((e) => LatLng(e.lat ?? 0.0, e.long ?? 0.0)).toList();
}
}
@override
Future<void> addLocations(List<LatLng> latList) async {
*//* await tmpLocalDataSource.addLocations(
await tmpLocalDataSource.addLocations(
latList.map((e) => TmpLocations(lat: e.latitude, long: e.longitude)).toList(),
);*//*
);
iLog("it is done");
}*/
}
}

View File

@@ -8,21 +8,19 @@ 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/livestock/livestock_repository.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 '../data/data_source/local/tmp/tmp_local_data-source.dart';
GetIt get diLiveStock => GetIt.instance;
Future<void> setupLiveStockDI() async {
diLiveStock.registerSingleton(DioErrorHandler());
await IsolatedHive.initFlutter();
IsolatedHive.registerAdapters();
iLog("Sssssssssssssssssssss");
final tokenService = Get.find<TokenStorageService>();
if (tokenService.baseurl.value == null) {
await tokenService.saveBaseUrl('https://api.dam.rasadyar.net/');
}
@@ -31,7 +29,7 @@ Future<void> setupLiveStockDI() async {
diLiveStock.registerLazySingleton<AppInterceptor>(
() => AppInterceptor(
refreshTokenCallback: () async {
/* // Use lazy access to avoid circular dependency
/* // Use lazy access to avoid circular dependency
final authRepository = diLiveStock.get<AuthRepository>();
final hasAuthenticated = await authRepository.hasAuthenticated();
if (hasAuthenticated) {
@@ -80,8 +78,14 @@ Future<void> setupLiveStockDI() async {
diLiveStock.registerLazySingleton<LivestockRemoteDataSource>(
() => LivestockRemoteDataSourceImp(),
);
diLiveStock.registerLazySingleton<TmpLocalDataSource>(() => TmpLocalDataSource());
diLiveStock.registerLazySingleton<LivestockRepository>(
() => LivestockRepositoryImp(livestockRemote: diLiveStock.get<LivestockRemoteDataSource>()),
() => LivestockRepositoryImp(
livestockRemote: diLiveStock.get<LivestockRemoteDataSource>(),
tmpLocalDataSource: diLiveStock.get<TmpLocalDataSource>(),
),
);
//endregion

View File

@@ -23,7 +23,7 @@ class MapWidgetLogic extends GetxController with GetTickerProviderStateMixin {
RxList<LatLng> markerLocations = RxList();
RootLogic rootLogic = Get.find<RootLogic>();
late LivestockRepository repository ;
LivestockRepository repository = diLiveStock.get<LivestockRepository>();
@override
void onInit() {
@@ -59,7 +59,7 @@ class MapWidgetLogic extends GetxController with GetTickerProviderStateMixin {
void onReady() {
super.onReady();
determineCurrentPosition();
// getLoc();
getLoc();
}
@override
@@ -151,7 +151,7 @@ class MapWidgetLogic extends GetxController with GetTickerProviderStateMixin {
return rawMarkers.where((marker) => distance(center, marker) <= radiusInMeters).toList();
}
/* Future<void> getLoc() async {
Future<void> getLoc() async {
await Future.delayed(Duration(seconds: 3));
await safeCall(
call: () async => repository.getLocations(),
@@ -160,5 +160,5 @@ class MapWidgetLogic extends GetxController with GetTickerProviderStateMixin {
},
onError: (error, stackTrace) {},
);
}*/
}
}