feat :
1 - search in map with api 2 - show details in selected location
This commit is contained in:
@@ -8,14 +8,20 @@ import 'package:rasadyar_inspection/data/repositories/inspection/inspection_repo
|
||||
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>();
|
||||
|
||||
InspectionRepositoryImp inspectionRepository = diInspection.get<InspectionRepositoryImp>();
|
||||
|
||||
final distance = Distance();
|
||||
|
||||
Rx<LatLng> currentLocation = LatLng(34.798315281272544, 48.51479142983491).obs;
|
||||
|
||||
Rx<Resource<List<PoultryLocationModel>>> allPoultryLocation =
|
||||
Resource<List<PoultryLocationModel>>.loading().obs;
|
||||
Resource<List<PoultryLocationModel>>.initial().obs;
|
||||
|
||||
Rx<Resource<List<PoultryLocationModel>>> searchedPoultryLocation =
|
||||
Resource<List<PoultryLocationModel>>.initial().obs;
|
||||
|
||||
RxList<Marker> markers = <Marker>[].obs;
|
||||
RxList<PoultryLocationModel> markers2 = <PoultryLocationModel>[].obs;
|
||||
@@ -28,19 +34,9 @@ class InspectionMapLogic extends GetxController with GetTickerProviderStateMixin
|
||||
RxInt showIndex = 0.obs;
|
||||
bool showSlideHint = true;
|
||||
RxInt currentZoom = 15.obs;
|
||||
|
||||
late Rx<SlidableController> slidController;
|
||||
|
||||
Rx<MapController> mapController = MapController().obs;
|
||||
late final AnimatedMapController animatedMapController;
|
||||
|
||||
late DraggableBottomSheetController filterBottomSheetController;
|
||||
late DraggableBottomSheetController selectedLocationBottomSheetController;
|
||||
late DraggableBottomSheetController detailsLocationBottomSheetController;
|
||||
late final BottomSheetManager bottomSheetManager;
|
||||
|
||||
InspectionRepositoryImp inspectionRepository = diInspection.get<InspectionRepositoryImp>();
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
@@ -50,38 +46,16 @@ class InspectionMapLogic extends GetxController with GetTickerProviderStateMixin
|
||||
curve: Curves.easeInOut,
|
||||
cancelPreviousAnimations: true,
|
||||
);
|
||||
|
||||
fetchAllPoultryLocations();
|
||||
|
||||
filterBottomSheetController = DraggableBottomSheetController(
|
||||
initialHeight: 350,
|
||||
minHeight: 200,
|
||||
maxHeight: Get.height * 0.5,
|
||||
);
|
||||
|
||||
selectedLocationBottomSheetController = DraggableBottomSheetController(
|
||||
initialHeight: 200,
|
||||
minHeight: 100,
|
||||
maxHeight: 200,
|
||||
);
|
||||
|
||||
detailsLocationBottomSheetController = DraggableBottomSheetController(
|
||||
initialHeight: Get.height * 0.5,
|
||||
minHeight: Get.height * 0.37,
|
||||
maxHeight: Get.height * 0.5,
|
||||
);
|
||||
|
||||
slidController = SlidableController(this).obs;
|
||||
bottomSheetManager = BottomSheetManager({
|
||||
filterBottomSheetController: () =>
|
||||
filterWidget(filterIndex: filterIndex, showIndex: showIndex),
|
||||
selectedLocationBottomSheetController: () => selectedLocationWidget(
|
||||
showHint: selectedLocationBottomSheetController.isVisible.value && showSlideHint,
|
||||
sliderController: slidController.value,
|
||||
trigger: triggerSlidableAnimation,
|
||||
toggle: selectedLocationBottomSheetController.toggle,
|
||||
),
|
||||
detailsLocationBottomSheetController: () => markerDetailsWidget(),
|
||||
});
|
||||
debounce(baseLogic.searchValue, (callback) {
|
||||
if (callback != null &&
|
||||
callback.trim().isNotEmpty &&
|
||||
searchedPoultryLocation.value.status != ResourceStatus.loading) {
|
||||
searchPoultryLocations();
|
||||
}
|
||||
}, time: Duration(seconds: 2));
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -92,7 +66,6 @@ class InspectionMapLogic extends GetxController with GetTickerProviderStateMixin
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
slidController.close();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
@@ -132,9 +105,9 @@ class InspectionMapLogic extends GetxController with GetTickerProviderStateMixin
|
||||
center.longitude,
|
||||
radius * 1000,
|
||||
);
|
||||
|
||||
markers2.addAll(filtered);
|
||||
|
||||
final existingIds = markers2.map((e) => e.id).toSet();
|
||||
final uniqueFiltered = filtered.where((e) => !existingIds.contains(e.id)).toList();
|
||||
markers2.addAll(uniqueFiltered);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -154,9 +127,9 @@ class InspectionMapLogic extends GetxController with GetTickerProviderStateMixin
|
||||
|
||||
Future<void> triggerSlidableAnimation() async {
|
||||
await Future.delayed(Duration(milliseconds: 200));
|
||||
await slidController.value.openEndActionPane();
|
||||
//await slidController.value.openEndActionPane();
|
||||
await Future.delayed(Duration(milliseconds: 200));
|
||||
await slidController.value.close();
|
||||
//await slidController.value.close();
|
||||
showSlideHint = false;
|
||||
}
|
||||
|
||||
@@ -184,6 +157,25 @@ class InspectionMapLogic extends GetxController with GetTickerProviderStateMixin
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> searchPoultryLocations() async {
|
||||
searchedPoultryLocation.value = Resource<List<PoultryLocationModel>>.loading();
|
||||
await safeCall(
|
||||
call: () => inspectionRepository.getNearbyLocation(value: baseLogic.searchValue.value),
|
||||
onSuccess: (result) {
|
||||
if (result != null || result!.isNotEmpty) {
|
||||
searchedPoultryLocation.value = Resource<List<PoultryLocationModel>>.success(result);
|
||||
} else {
|
||||
searchedPoultryLocation.value = Resource<List<PoultryLocationModel>>.empty();
|
||||
}
|
||||
},
|
||||
onError: (error, stackTrace) {
|
||||
searchedPoultryLocation.value = Resource<List<PoultryLocationModel>>.error(
|
||||
error.toString(),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
double getVisibleRadiusKm({
|
||||
required double zoom,
|
||||
required double screenWidthPx,
|
||||
|
||||
Reference in New Issue
Block a user