import 'dart:async';
import 'package:flutter/[Link]';
import 'package:geocoding/[Link]';
import 'package:geolocator/[Link]';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:taxi_customer/core/app_export.dart';
import
'package:taxi_customer/presentation/map_screen/notifier/currentLocationMarker_notif
[Link]';
import 'notifier/cLocation_notifier.dart';
import 'notifier/currentLocation_notifier.dart';
class MapScreen extends ConsumerStatefulWidget {
const MapScreen({Key? key}) : super(key: key);
@override
ConsumerState<MapScreen> createState() => _MapScreenState();
}
class _MapScreenState extends ConsumerState<MapScreen> {
late GoogleMapController googleMapController;
Map<MarkerId, Marker> markers = {};
//<------ Current Location ---------->
loadData() async {
Position position = await _getUserCurrentLocation();
setState(() {
[Link](currentLocationNotifier).currentLatLng = LatLng([Link],
[Link]);
[Link](currentLocationMarkerNotifier).locationMarker = [
Marker(
markerId: MarkerId('Current Location'),
position: [Link](currentLocationNotifier).currentLatLng!,
infoWindow: InfoWindow(title:
[Link](cLocationNotifier).currentLocation ?? ''),
),
];
[Link](
[Link](
new CameraPosition(
target: [Link](currentLocationNotifier).currentLatLng!,
zoom: 14.0,
),
),
);
fetchAreaName();
});
}
//<------- Fetch Location ----------->
Future<Position> _getUserCurrentLocation() async {
await [Link]().catchError((error) {
print([Link]());
});
return await [Link]();
}
//<--------- Fetah Address ----------->
Future<void> fetchAreaName() async {
try {
final List<Placemark> placeMarks = await
placemarkFromCoordinates([Link](currentLocationNotifier).currentLatLng!.latitude,
[Link](currentLocationNotifier).currentLatLng!.longitude);
[Link](cLocationNotifier).currentLocation =
[Link]();
setState(() {});
} catch (e) {
print('Error fetching area name: $e');
}
}
@override
void initState() {
loadData();
[Link]();
}
@override
void dispose() {
[Link]();
[Link]();
}
@override
Widget build(BuildContext context) {
return Scaffold(
extendBody: true,
extendBodyBehindAppBar: true,
backgroundColor: [Link](1),
body: Stack(
alignment: [Link],
children: [
GoogleMap(
initialCameraPosition: CameraPosition(
target: [Link](currentLocationNotifier).currentLatLng!,
zoom: 14,
),
mapType: [Link],
myLocationButtonEnabled: true,
myLocationEnabled: true,
markers:
Set<Marker>.of([Link](currentLocationMarkerNotifier).locationMarker!),
// polylines: Set<Polyline>.of([Link](provider)),
onMapCreated: (GoogleMapController controller) {
setState(() {
googleMapController = controller;
});
},
),
SizedBox(
width: [Link],
child: Column(
mainAxisSize: [Link],
crossAxisAlignment: [Link],
children: [
_buildNeemuchRDGopalbari(context),
],
),
),
],
),
);
}
Widget _buildNeemuchRDGopalbari(BuildContext context) {
return Container(
padding: [Link](24.h),
height: 200.h,
decoration: [Link](
borderRadius: BorderRadiusStyle.customBorderTL30,
),
child: Column(
mainAxisSize: [Link],
crossAxisAlignment: [Link],
mainAxisAlignment: [Link],
children: [
Text(
"msg_where_do_you_want".tr,
style: [Link],
),
SizedBox(height: 13.v),
_buildIndicatedContainer(
value: [Link](cLocationNotifier).currentLocation ?? '',
),
SizedBox(height: 13.v),
_buildIndicatedContainer(value:
[Link](destinationLocationState)??'Select Destination', isDestination: true),
],
),
);
}
Widget _buildIndicatedContainer({bool isDestination = false, String value = ''})
{
return Consumer(builder: (context, ref, _) {
return GestureDetector(
child: Row(
children: [
Container(
height: 40.0,
width: 28.0,
decoration: BoxDecoration(
color: isDestination ? Color(0xff3422F2) : [Link],
borderRadius: [Link](15.0),
),
child: Padding(
padding: isDestination ? [Link](bottom: 5.0) :
[Link](top: 5.0),
child: Align(
alignment: isDestination ? [Link] :
[Link],
child: Container(
height: 10.0,
width: 10.0,
decoration: BoxDecoration(
color: isDestination ? [Link] : [Link],
shape: [Link],
),
),
),
),
),
const SizedBox(
width: 10.0,
),
Expanded(
child: Text(
value,
maxLines: 1,
style: isDestination ? CustomTextStyles.labelLargePoppinsff000000 :
CustomTextStyles.bodySmallGray500_1,
),
),
],
),
onTap: () async{
final check =await
[Link]([Link]);
if(check == true)
{
[Link](currentLocationMarkerNotifier).locationMarker!.clear();
[Link](currentLocationMarkerNotifier).locationMarker = [
Marker(
markerId: MarkerId('Current Location'),
position: [Link](currentLocationNotifier).currentLatLng!,
infoWindow: InfoWindow(title: 'Current Location'),
),
Marker(
markerId: MarkerId('Destination Location'),
position: [Link](destinationLatLngState),
infoWindow: InfoWindow(title: 'Destination Location'),
),
];
[Link](
[Link](
new CameraPosition(
target: [Link](destinationLatLngState),
zoom: 14.0,
),
),
);
// setState(() {});
// // [Link]([Link]).update((state) =>
Polyline(
// // polylineId: PolylineId('polyline'),
// // points: [
// // [Link](currentLatLngState),
// // [Link](destinationLatLngState)
// // ],
// // color: [Link],
// // width: 3,
// // ));
}
},
);
});
}
}
// final locationMarkerState = StateProvider<List<Marker>>((ref) {
// return [];
// });
final locationPolyLineState = StateProvider<Polyline>((ref) {
return Polyline(polylineId: PolylineId(""));
});
// final currentLocationState = StateProvider<String>((ref) {
// return '';
// });
final destinationLatLngState = StateProvider<LatLng>((ref) {
return LatLng(24.9291, 67.0450);
});
final destinationLocationState = StateProvider<String>((ref) {
return '';
});