|
|
|
|
@ -18,8 +18,10 @@ import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
|
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:geolocator/geolocator.dart';
|
|
|
|
|
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
|
|
|
|
import 'package:google_maps_place_picker/google_maps_place_picker.dart';
|
|
|
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
|
|
import 'cmc_location_page.dart';
|
|
|
|
|
@ -45,38 +47,63 @@ class _NewCMCStepTowPageState extends State<NewCMCStepTowPage> {
|
|
|
|
|
bool showCurrentLocation = false;
|
|
|
|
|
|
|
|
|
|
Completer<GoogleMapController> _controller = Completer();
|
|
|
|
|
GoogleMapController googleMapController;
|
|
|
|
|
static CameraPosition _kGooglePlex = CameraPosition(
|
|
|
|
|
target: LatLng(37.42796133580664, -122.085749655962),
|
|
|
|
|
zoom: 14.4746,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final Set<Marker> markers = new Set();
|
|
|
|
|
LatLng currentPostion;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
if (widget.cmcInsertPresOrderRequestModel.latitude == null) {
|
|
|
|
|
setLatitudeAndLongitude();
|
|
|
|
|
} else {
|
|
|
|
|
latitude = widget.cmcInsertPresOrderRequestModel.latitude;
|
|
|
|
|
longitude = widget.cmcInsertPresOrderRequestModel.longitude;
|
|
|
|
|
void _getUserLocation() async {
|
|
|
|
|
if (await Permission.contacts.request().isGranted) {
|
|
|
|
|
// Either the permission was already granted before or the user just granted it.
|
|
|
|
|
var position = await GeolocatorPlatform.instance.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
|
|
|
|
|
|
|
|
|
|
currentPostion = LatLng(position.latitude, position.longitude);
|
|
|
|
|
setMap();
|
|
|
|
|
} else {
|
|
|
|
|
requestPermissions().then((value) async {
|
|
|
|
|
if (value[Permission.location].isGranted) {
|
|
|
|
|
var position = await GeolocatorPlatform.instance.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
|
|
|
|
|
|
|
|
|
|
currentPostion = LatLng(position.latitude, position.longitude);
|
|
|
|
|
setMap();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
_getUserLocation();
|
|
|
|
|
super.initState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setMap() {
|
|
|
|
|
markers.clear();
|
|
|
|
|
markers.add(
|
|
|
|
|
Marker(
|
|
|
|
|
markerId: MarkerId(
|
|
|
|
|
latitude.hashCode.toString(),
|
|
|
|
|
setState(() {
|
|
|
|
|
_kGooglePlex = CameraPosition(
|
|
|
|
|
target: currentPostion,
|
|
|
|
|
zoom: 14.4746,
|
|
|
|
|
);
|
|
|
|
|
googleMapController.animateCamera(
|
|
|
|
|
CameraUpdate.newCameraPosition(
|
|
|
|
|
CameraPosition(
|
|
|
|
|
target: currentPostion,
|
|
|
|
|
zoom: 20,
|
|
|
|
|
),
|
|
|
|
|
position: LatLng(latitude, longitude)),
|
|
|
|
|
);
|
|
|
|
|
_kGooglePlex = CameraPosition(
|
|
|
|
|
target: LatLng(latitude, longitude),
|
|
|
|
|
zoom: 14.4746,
|
|
|
|
|
);
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<Map<Permission, PermissionStatus>> requestPermissions() async {
|
|
|
|
|
var permissionResults = [
|
|
|
|
|
Permission.location,
|
|
|
|
|
Permission.locationAlways,
|
|
|
|
|
].request();
|
|
|
|
|
|
|
|
|
|
return permissionResults;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setLatitudeAndLongitude({bool isSetState = false, String latLong}) async {
|
|
|
|
|
@ -116,7 +143,7 @@ class _NewCMCStepTowPageState extends State<NewCMCStepTowPage> {
|
|
|
|
|
children: [
|
|
|
|
|
if (widget.model.addressesList.isNotEmpty)
|
|
|
|
|
Card(
|
|
|
|
|
margin: EdgeInsets.only(left: 12, right: 12, bottom: 12),
|
|
|
|
|
margin: EdgeInsets.only(left: 12, right: 12, bottom: 12, top: 12),
|
|
|
|
|
shape: cardRadius(12),
|
|
|
|
|
elevation: 3,
|
|
|
|
|
child: Container(
|
|
|
|
|
@ -183,14 +210,27 @@ class _NewCMCStepTowPageState extends State<NewCMCStepTowPage> {
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: GoogleMap(
|
|
|
|
|
mapType: MapType.normal,
|
|
|
|
|
markers: markers,
|
|
|
|
|
zoomControlsEnabled: false,
|
|
|
|
|
initialCameraPosition: _kGooglePlex,
|
|
|
|
|
onMapCreated: (GoogleMapController controller) {
|
|
|
|
|
_controller.complete(controller);
|
|
|
|
|
},
|
|
|
|
|
child: Stack(
|
|
|
|
|
alignment: Alignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
GoogleMap(
|
|
|
|
|
mapType: MapType.normal,
|
|
|
|
|
zoomControlsEnabled: false,
|
|
|
|
|
myLocationButtonEnabled: true,
|
|
|
|
|
myLocationEnabled: true,
|
|
|
|
|
initialCameraPosition: _kGooglePlex,
|
|
|
|
|
onCameraMove: ((_position) => _updatePosition(_position)),
|
|
|
|
|
onMapCreated: (GoogleMapController controller) {
|
|
|
|
|
googleMapController = controller;
|
|
|
|
|
_controller.complete(controller);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
Icon(
|
|
|
|
|
Icons.place,
|
|
|
|
|
color: CustomColors.accentColor,
|
|
|
|
|
size: 50,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Padding(
|
|
|
|
|
@ -207,7 +247,6 @@ class _NewCMCStepTowPageState extends State<NewCMCStepTowPage> {
|
|
|
|
|
navigateTo(
|
|
|
|
|
context,
|
|
|
|
|
NewCMCStepThreePage(
|
|
|
|
|
|
|
|
|
|
cmcInsertPresOrderRequestModel: widget.cmcInsertPresOrderRequestModel,
|
|
|
|
|
model: widget.model,
|
|
|
|
|
),
|
|
|
|
|
@ -221,6 +260,11 @@ class _NewCMCStepTowPageState extends State<NewCMCStepTowPage> {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _updatePosition(CameraPosition _position) {
|
|
|
|
|
latitude = _position.target.latitude;
|
|
|
|
|
longitude = _position.target.longitude;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void confirmSelectLocationDialog(List<AddressInfo> addresses) {
|
|
|
|
|
showDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
|