feat : cashing map from internet
This commit is contained in:
1
packages/livestock/lib/data/common/constant.dart
Normal file
1
packages/livestock/lib/data/common/constant.dart
Normal file
@@ -0,0 +1 @@
|
||||
const String mapStoreKey = 'mapStoreLiveStock';
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_livestock/data/common/constant.dart';
|
||||
import 'package:rasadyar_livestock/data/common/dio_exception_handeler.dart';
|
||||
import 'package:rasadyar_livestock/data/data_source/remote/auth/auth_remote.dart';
|
||||
import 'package:rasadyar_livestock/data/data_source/remote/auth/auth_remote_imp.dart';
|
||||
@@ -25,11 +26,14 @@ Future<void> setupLiveStockDI() async {
|
||||
await tokenService.saveBaseUrl('https://api.dam.rasadyar.net/');
|
||||
}
|
||||
|
||||
await FMTCStore(mapStoreKey).manage.create();
|
||||
|
||||
|
||||
// First register AppInterceptor with lazy callbacks
|
||||
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) {
|
||||
@@ -37,7 +41,7 @@ Future<void> setupLiveStockDI() async {
|
||||
authRequest: {'refresh': tokenService.refreshToken.value},
|
||||
);
|
||||
return newToken?.access;
|
||||
}*/
|
||||
}
|
||||
return null;
|
||||
},
|
||||
saveTokenCallback: (String newToken) async {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_livestock/data/common/constant.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/injection/live_stock_di.dart';
|
||||
import 'package:rasadyar_livestock/presentation/page/root/logic.dart';
|
||||
|
||||
@@ -21,9 +22,11 @@ class MapWidgetLogic extends GetxController with GetTickerProviderStateMixin {
|
||||
Timer? _debounceTimer;
|
||||
RxBool isLoading = false.obs;
|
||||
|
||||
late FMTCTileProvider tileProvider;
|
||||
|
||||
RxList<LatLng> markerLocations = RxList();
|
||||
RootLogic rootLogic = Get.find<RootLogic>();
|
||||
LivestockRepository repository = diLiveStock.get<LivestockRepository>();
|
||||
LivestockRepository repository = diLiveStock.get<LivestockRepository>();
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
@@ -53,6 +56,10 @@ class MapWidgetLogic extends GetxController with GetTickerProviderStateMixin {
|
||||
errorLocationType.remove(ErrorLocationType.serviceDisabled);
|
||||
}
|
||||
});
|
||||
|
||||
tileProvider = FMTCTileProvider(stores: {mapStoreKey: BrowseStoreStrategy.readUpdateCreate});
|
||||
|
||||
repository.addLocations(generateRandomLocations(currentLocation.value, 10, 100));
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -60,6 +67,7 @@ class MapWidgetLogic extends GetxController with GetTickerProviderStateMixin {
|
||||
super.onReady();
|
||||
determineCurrentPosition();
|
||||
getLoc();
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -156,9 +164,38 @@ class MapWidgetLogic extends GetxController with GetTickerProviderStateMixin {
|
||||
await safeCall(
|
||||
call: () async => repository.getLocations(),
|
||||
onSuccess: (result) {
|
||||
iLog("OOOpssss => ${result.length}");
|
||||
markerLocations.addAll(result);
|
||||
},
|
||||
onError: (error, stackTrace) {},
|
||||
);
|
||||
}
|
||||
|
||||
List<LatLng> generateRandomLocations(LatLng currentPosition, double radiusInKm, int count) {
|
||||
final random = Random();
|
||||
final locations = <LatLng>[];
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
// فاصله تصادفی (۰ تا radius)
|
||||
final distance = random.nextDouble() * radiusInKm * 1000; // متر
|
||||
// زاویه تصادفی (۰ تا ۲π)
|
||||
final angle = random.nextDouble() * 2 * pi;
|
||||
|
||||
// فاصله به درجه
|
||||
final dx = distance * cos(angle);
|
||||
final dy = distance * sin(angle);
|
||||
|
||||
// 1 درجه lat ≈ 111km
|
||||
final newLat = currentPosition.latitude + (dy / 111000.0);
|
||||
|
||||
// 1 درجه lon ≈ 111km * cos(lat)
|
||||
final newLng = currentPosition.longitude +
|
||||
(dx / (111000.0 * cos(currentPosition.latitude * pi / 180)));
|
||||
|
||||
locations.add(LatLng(newLat, newLng));
|
||||
}
|
||||
|
||||
return locations;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -104,6 +104,7 @@ class MapWidget extends GetView<MapWidgetLogic> {
|
||||
flags: InteractiveFlag.all & ~InteractiveFlag.rotate,
|
||||
),
|
||||
initialZoom: 15,
|
||||
|
||||
onPositionChanged: (camera, hasGesture) {
|
||||
controller.currentZoom.value = camera.zoom;
|
||||
/* controller.debouncedUpdateVisibleMarkers(
|
||||
@@ -117,6 +118,7 @@ class MapWidget extends GetView<MapWidgetLogic> {
|
||||
TileLayer(
|
||||
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||
userAgentPackageName: 'ir.mnpc.rasadyar',
|
||||
tileProvider: controller.tileProvider,
|
||||
),
|
||||
|
||||
ObxValue((markers) {
|
||||
@@ -153,8 +155,6 @@ class MapWidget extends GetView<MapWidgetLogic> {
|
||||
top: 15,
|
||||
left: 20,
|
||||
child: ObxValue((status) {
|
||||
|
||||
|
||||
return Text("Connection: ${status.value}", style: TextStyle(fontSize: 20));
|
||||
}, NetworkStatus().isConnected),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user