Previous Code
Previous Code
import 'package:flutter/material.dart';
import 'package:geocoding/geocoding.dart';
import 'package:geolocator/geolocator.dart';
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
ier.dart';
import 'notifier/cLocation_notifier.dart';
import 'notifier/currentLocation_notifier.dart';
@override
ConsumerState<MapScreen> createState() => _MapScreenState();
}
loadData() async {
Position position = await _getUserCurrentLocation();
setState(() {
ref.watch(currentLocationNotifier).currentLatLng = LatLng(position.latitude,
position.longitude);
ref.watch(currentLocationMarkerNotifier).locationMarker = [
Marker(
markerId: MarkerId('Current Location'),
position: ref.read(currentLocationNotifier).currentLatLng!,
infoWindow: InfoWindow(title:
ref.read(cLocationNotifier).currentLocation ?? ''),
),
];
googleMapController.animateCamera(
CameraUpdate.newCameraPosition(
new CameraPosition(
target: ref.read(currentLocationNotifier).currentLatLng!,
zoom: 14.0,
),
),
);
fetchAreaName();
});
}
//<------- Fetch Location ----------->
@override
void initState() {
loadData();
super.initState();
}
@override
void dispose() {
googleMapController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
extendBody: true,
extendBodyBehindAppBar: true,
backgroundColor: theme.colorScheme.onPrimary.withOpacity(1),
body: Stack(
alignment: AlignmentDirectional.bottomCenter,
children: [
GoogleMap(
initialCameraPosition: CameraPosition(
target: ref.read(currentLocationNotifier).currentLatLng!,
zoom: 14,
),
mapType: MapType.hybrid,
myLocationButtonEnabled: true,
myLocationEnabled: true,
markers:
Set<Marker>.of(ref.read(currentLocationMarkerNotifier).locationMarker!),
// polylines: Set<Polyline>.of(ref.read(provider)),
onMapCreated: (GoogleMapController controller) {
setState(() {
googleMapController = controller;
});
},
),
SizedBox(
width: double.maxFinite,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildNeemuchRDGopalbari(context),
],
),
),
],
),
);
}
googleMapController.animateCamera(
CameraUpdate.newCameraPosition(
new CameraPosition(
target: ref.read(destinationLatLngState),
zoom: 14.0,
),
),
);
// setState(() {});
// // ref.watch(locationPolyLineState.notifier).update((state) =>
Polyline(
// // polylineId: PolylineId('polyline'),
// // points: [
// // ref.read(currentLatLngState),
// // ref.read(destinationLatLngState)
// // ],
// // color: Colors.blue,
// // width: 3,
// // ));
}
},
);
});
}
}