import 'dart:io'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:maplibre_gl/maplibre_gl.dart'; import 'package:Intaleq/controller/home/points_for_rider_controller.dart'; import '../../../constant/colors.dart'; import '../../../constant/style.dart'; import '../../../controller/home/map_passenger_controller.dart'; import '../../widgets/mycircular.dart'; import '../../widgets/mydialoug.dart'; class GoogleMapPassengerWidget extends StatelessWidget { GoogleMapPassengerWidget({super.key}); final WayPointController wayPointController = Get.put(WayPointController()); @override Widget build(BuildContext context) { return GetBuilder( builder: (controller) => controller.isLoading ? const MyCircularProgressIndicator() : Positioned( bottom: Get.height * .2, top: 0, left: 0, right: 0, child: MapLibreMap( onMapCreated: controller.onMapCreated, onStyleLoadedCallback: () => controller.onStyleLoaded(), styleString: "assets/style.json", // ✅ Performance: Smoother zoom limits for low-end devices minMaxZoomPreference: controller.lowPerf ? const MinMaxZoomPreference(6, 17) : const MinMaxZoomPreference(6, 18), initialCameraPosition: CameraPosition( target: controller.passengerLocation, zoom: controller.lowPerf ? 14.5 : 15, ), // ✅ Map Settings myLocationEnabled: true, trackCameraPosition: true, // ✅ Camera Movement Logic onCameraIdle: () { if (controller.mapController != null) { final position = controller.mapController!.cameraPosition; if (position != null) { print('✅ onCameraIdle targeted: ${position.target}'); // 1. Always update current view target (for pickers) controller .updateCurrentLocationFromCamera(position.target); } } }, onMapLongClick: (point, latlng) { MyDialog().getDialog('Are you want to go to this site'.tr, '', () async { controller.clearPolyline(); if (controller.carsLocationByPassenger.isNotEmpty) { await controller.getDirectionMap( '${controller.passengerLocation.latitude},${controller.passengerLocation.longitude}', '${latlng.latitude},${latlng.longitude}', ); Get.back(); // Close Dialog await controller.bottomSheet(); controller.showBottomSheet1(); } else { Get.back(); Get.snackbar( 'We Are Sorry That we dont have cars in your Location!' .tr, '', colorText: AppColor.redColor, duration: const Duration(seconds: 5), backgroundColor: AppColor.secondaryColor, icon: const Icon(Icons.error, color: AppColor.redColor), titleText: Text('Error'.tr, style: const TextStyle(color: AppColor.redColor)), messageText: Text( 'We Are Sorry That we dont have cars in your Location!' .tr, style: AppStyle.title), ); } }); }, onMapClick: (point, latlng) { controller.hidePlaces(); }, ), ), ); } }