feat : profile and map
This commit is contained in:
@@ -1,20 +1,23 @@
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_inspection/data/utils/marker_generator.dart';
|
||||
import 'package:rasadyar_inspection/data/model/response/poultry_location/poultry_location_model.dart';
|
||||
import 'package:rasadyar_inspection/data/repositories/inspection/inspection_repository_imp.dart';
|
||||
import 'package:rasadyar_inspection/injection/inspection_di.dart';
|
||||
import 'package:rasadyar_inspection/presentation/widget/base_page/logic.dart';
|
||||
|
||||
import '../filter/view.dart';
|
||||
|
||||
class InspectionMapLogic extends GetxController with GetTickerProviderStateMixin {
|
||||
|
||||
final BaseLogic baseLogic = Get.find<BaseLogic>();
|
||||
|
||||
Rx<LatLng> currentLocation = LatLng(35.824891, 50.948025).obs;
|
||||
RxList<LatLng> allMarkers = <LatLng>[].obs;
|
||||
RxList<LatLng> markers = <LatLng>[].obs;
|
||||
Rx<LatLng> currentLocation = LatLng(34.798315281272544, 48.51479142983491).obs;
|
||||
Rx<Resource<List<PoultryLocationModel>>> allPoultryLocation =
|
||||
Resource<List<PoultryLocationModel>>.loading().obs;
|
||||
|
||||
RxList<PoultryLocationModel> markers = <PoultryLocationModel>[].obs;
|
||||
|
||||
Timer? _debounceTimer;
|
||||
RxBool isLoading = false.obs;
|
||||
RxBool isSelectedDetailsLocation = false.obs;
|
||||
@@ -33,55 +36,7 @@ class InspectionMapLogic extends GetxController with GetTickerProviderStateMixin
|
||||
late DraggableBottomSheetController detailsLocationBottomSheetController;
|
||||
late final BottomSheetManager bottomSheetManager;
|
||||
|
||||
Future<void> determineCurrentPosition() async {
|
||||
isLoading.value = true;
|
||||
final position = await Geolocator.getCurrentPosition(
|
||||
locationSettings: AndroidSettings(accuracy: LocationAccuracy.best),
|
||||
);
|
||||
final latLng = LatLng(position.latitude, position.longitude);
|
||||
|
||||
currentLocation.value = latLng;
|
||||
markers.add(latLng);
|
||||
animatedMapController.animateTo(
|
||||
dest: latLng,
|
||||
zoom: 18,
|
||||
curve: Curves.easeInOut,
|
||||
duration: const Duration(seconds: 1),
|
||||
);
|
||||
isLoading.value = false;
|
||||
}
|
||||
|
||||
void debouncedUpdateVisibleMarkers({required LatLng center}) {
|
||||
_debounceTimer?.cancel();
|
||||
_debounceTimer = Timer(const Duration(milliseconds: 300), () {
|
||||
final filtered = filterNearbyMarkers({
|
||||
'markers': allMarkers,
|
||||
'centerLat': center.latitude,
|
||||
'centerLng': center.longitude,
|
||||
'radius': 2000.0,
|
||||
});
|
||||
|
||||
markers.addAll(filtered);
|
||||
});
|
||||
}
|
||||
|
||||
List<LatLng> filterNearbyMarkers(Map<String, dynamic> args) {
|
||||
final List<LatLng> rawMarkers = args['markers'];
|
||||
final double centerLat = args['centerLat'];
|
||||
final double centerLng = args['centerLng'];
|
||||
final double radiusInMeters = args['radius'];
|
||||
final center = LatLng(centerLat, centerLng);
|
||||
final distance = Distance();
|
||||
|
||||
return rawMarkers
|
||||
.where((marker) => distance(center, marker) <= radiusInMeters)
|
||||
.toList();
|
||||
}
|
||||
|
||||
Future<void> generatedMarkers() async {
|
||||
final generatedMarkers = await generateLocationsUsingCompute(100000);
|
||||
allMarkers.value = generatedMarkers;
|
||||
}
|
||||
InspectionRepositoryImp inspectionRepository = diInspection.get<InspectionRepositoryImp>();
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
@@ -92,6 +47,7 @@ class InspectionMapLogic extends GetxController with GetTickerProviderStateMixin
|
||||
curve: Curves.easeInOut,
|
||||
cancelPreviousAnimations: true,
|
||||
);
|
||||
fetchAllPoultryLocations();
|
||||
|
||||
filterBottomSheetController = DraggableBottomSheetController(
|
||||
initialHeight: 350,
|
||||
@@ -105,7 +61,6 @@ class InspectionMapLogic extends GetxController with GetTickerProviderStateMixin
|
||||
maxHeight: 200,
|
||||
);
|
||||
|
||||
|
||||
detailsLocationBottomSheetController = DraggableBottomSheetController(
|
||||
initialHeight: Get.height * 0.5,
|
||||
minHeight: Get.height * 0.37,
|
||||
@@ -114,13 +69,10 @@ class InspectionMapLogic extends GetxController with GetTickerProviderStateMixin
|
||||
|
||||
slidController = SlidableController(this).obs;
|
||||
bottomSheetManager = BottomSheetManager({
|
||||
filterBottomSheetController:
|
||||
() => filterWidget(filterIndex: filterIndex, showIndex: showIndex),
|
||||
selectedLocationBottomSheetController:
|
||||
() => selectedLocationWidget(
|
||||
showHint:
|
||||
selectedLocationBottomSheetController.isVisible.value &&
|
||||
showSlideHint,
|
||||
filterBottomSheetController: () =>
|
||||
filterWidget(filterIndex: filterIndex, showIndex: showIndex),
|
||||
selectedLocationBottomSheetController: () => selectedLocationWidget(
|
||||
showHint: selectedLocationBottomSheetController.isVisible.value && showSlideHint,
|
||||
sliderController: slidController.value,
|
||||
trigger: triggerSlidableAnimation,
|
||||
toggle: selectedLocationBottomSheetController.toggle,
|
||||
@@ -132,8 +84,63 @@ class InspectionMapLogic extends GetxController with GetTickerProviderStateMixin
|
||||
@override
|
||||
void onReady() {
|
||||
super.onReady();
|
||||
determineCurrentPosition();
|
||||
generatedMarkers();
|
||||
//determineCurrentPosition();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
slidController.close();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
Future<void> determineCurrentPosition() async {
|
||||
isLoading.value = true;
|
||||
final position = await Geolocator.getCurrentPosition(
|
||||
locationSettings: AndroidSettings(accuracy: LocationAccuracy.best),
|
||||
);
|
||||
final latLng = LatLng(position.latitude, position.longitude);
|
||||
|
||||
/*currentLocation.value = latLng;
|
||||
markers.add(PoultryLocationModel(
|
||||
lat: latLng.latitude,
|
||||
long: latLng.longitude
|
||||
));*/
|
||||
animatedMapController.animateTo(
|
||||
dest: latLng,
|
||||
zoom: 18,
|
||||
curve: Curves.easeInOut,
|
||||
duration: const Duration(seconds: 1),
|
||||
);
|
||||
isLoading.value = false;
|
||||
}
|
||||
|
||||
void debouncedUpdateVisibleMarkers({required LatLng center}) {
|
||||
_debounceTimer?.cancel();
|
||||
_debounceTimer = Timer(const Duration(milliseconds: 300), () {
|
||||
final filtered = filterNearbyMarkers(
|
||||
allPoultryLocation.value.data ?? [],
|
||||
center.latitude,
|
||||
center.longitude,
|
||||
10000, // Radius in meters
|
||||
);
|
||||
|
||||
markers.addAll(filtered);
|
||||
});
|
||||
}
|
||||
|
||||
List<PoultryLocationModel> filterNearbyMarkers(
|
||||
List<PoultryLocationModel> allMarkers,
|
||||
double centerLat,
|
||||
double centerLng,
|
||||
double radiusInMeters,
|
||||
) {
|
||||
final center = LatLng(centerLat, centerLng);
|
||||
final distance = Distance();
|
||||
|
||||
return allMarkers.where((marker) {
|
||||
var tmp =LatLng(marker.lat ?? 0, marker.long ?? 0);
|
||||
return distance(center,tmp ) <= radiusInMeters;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
Future<void> triggerSlidableAnimation() async {
|
||||
@@ -144,9 +151,23 @@ class InspectionMapLogic extends GetxController with GetTickerProviderStateMixin
|
||||
showSlideHint = false;
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
slidController.close();
|
||||
super.onClose();
|
||||
Future<void> fetchAllPoultryLocations() async {
|
||||
isLoading.value = true;
|
||||
allPoultryLocation.value = Resource<List<PoultryLocationModel>>.loading();
|
||||
await safeCall(
|
||||
call: () => inspectionRepository.getNearbyLocation(),
|
||||
onSuccess: (result) {
|
||||
if (result != null) {
|
||||
allPoultryLocation.value = Resource<List<PoultryLocationModel>>.success(result);
|
||||
} else {
|
||||
allPoultryLocation.value = Resource<List<PoultryLocationModel>>.error(
|
||||
'No locations found',
|
||||
);
|
||||
}
|
||||
},
|
||||
onError: (error, stackTrace) {
|
||||
allPoultryLocation.value = Resource<List<PoultryLocationModel>>.error(error.toString());
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user