|
|
|
|
@ -7,6 +7,7 @@ import 'package:diplomaticquarterapp/config/config.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/core/model/pharmacies/order_model.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/core/service/parmacyModule/order-preview-service.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/locator.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
@ -59,6 +60,7 @@ class _TrackDriverState extends State<TrackDriver> {
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
|
|
_order = widget.order;
|
|
|
|
|
DEST_LOCATION = _order.shippingAddress.getLocation();
|
|
|
|
|
@ -69,7 +71,6 @@ class _TrackDriverState extends State<TrackDriver> {
|
|
|
|
|
initMarkerUpdateStream();
|
|
|
|
|
startUpdatingDriverLocation();
|
|
|
|
|
|
|
|
|
|
super.initState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
@ -98,6 +99,7 @@ class _TrackDriverState extends State<TrackDriver> {
|
|
|
|
|
delta.from.latitude,
|
|
|
|
|
delta.from.longitude,
|
|
|
|
|
),
|
|
|
|
|
onTap: onSourceMarkerTap
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
_markers.removeWhere((m) => m.markerId.value == 'sourcePin');
|
|
|
|
|
@ -121,10 +123,10 @@ class _TrackDriverState extends State<TrackDriver> {
|
|
|
|
|
markers: _markers,
|
|
|
|
|
polylines: _polylines,
|
|
|
|
|
mapType: MapType.normal,
|
|
|
|
|
initialCameraPosition: _orderDeliveryLocationCamera(),
|
|
|
|
|
initialCameraPosition: CameraPosition(target: DEST_LOCATION, zoom: 4),
|
|
|
|
|
onMapCreated: (GoogleMapController controller) {
|
|
|
|
|
_controller.complete(controller);
|
|
|
|
|
showPinsOnMap();
|
|
|
|
|
// showPinsOnMap();
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
// floatingActionButton: FloatingActionButton.extended(
|
|
|
|
|
@ -144,22 +146,27 @@ class _TrackDriverState extends State<TrackDriver> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CameraPosition _orderDeliveryLocationCamera(){
|
|
|
|
|
|
|
|
|
|
final CameraPosition orderDeliveryLocCamera = CameraPosition(
|
|
|
|
|
bearing: CAMERA_BEARING,
|
|
|
|
|
target: DEST_LOCATION,
|
|
|
|
|
tilt: CAMERA_TILT,
|
|
|
|
|
zoom: CAMERA_ZOOM);
|
|
|
|
|
return orderDeliveryLocCamera;
|
|
|
|
|
if(DEST_LOCATION != null){
|
|
|
|
|
final CameraPosition orderDeliveryLocCamera = CameraPosition(
|
|
|
|
|
bearing: CAMERA_BEARING,
|
|
|
|
|
target: DEST_LOCATION,
|
|
|
|
|
tilt: CAMERA_TILT,
|
|
|
|
|
zoom: CAMERA_ZOOM);
|
|
|
|
|
return orderDeliveryLocCamera;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CameraPosition _driverLocationCamera(){
|
|
|
|
|
final CameraPosition driverLocCamera = CameraPosition(
|
|
|
|
|
bearing: CAMERA_BEARING,
|
|
|
|
|
target: SOURCE_LOCATION,
|
|
|
|
|
tilt: CAMERA_TILT,
|
|
|
|
|
zoom: CAMERA_ZOOM);
|
|
|
|
|
return driverLocCamera;
|
|
|
|
|
if(DEST_LOCATION != null) {
|
|
|
|
|
final CameraPosition driverLocCamera = CameraPosition(
|
|
|
|
|
bearing: CAMERA_BEARING,
|
|
|
|
|
target: SOURCE_LOCATION,
|
|
|
|
|
tilt: CAMERA_TILT,
|
|
|
|
|
zoom: CAMERA_ZOOM);
|
|
|
|
|
return driverLocCamera;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -176,16 +183,6 @@ class _TrackDriverState extends State<TrackDriver> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> _fitCameraBetweenBothPoints() async {
|
|
|
|
|
final GoogleMapController controller = await _controller.future;
|
|
|
|
|
final CameraPosition driverLocCamera = CameraPosition(
|
|
|
|
|
bearing: CAMERA_BEARING,
|
|
|
|
|
target: SOURCE_LOCATION,
|
|
|
|
|
tilt: CAMERA_TILT,
|
|
|
|
|
zoom: CAMERA_ZOOM);
|
|
|
|
|
controller.animateCamera(CameraUpdate.newCameraPosition(driverLocCamera));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void showPinsOnMap() {
|
|
|
|
|
// source pin
|
|
|
|
|
if(SOURCE_LOCATION != null){
|
|
|
|
|
@ -195,7 +192,9 @@ class _TrackDriverState extends State<TrackDriver> {
|
|
|
|
|
_markers.add(Marker(
|
|
|
|
|
markerId: MarkerId('sourcePin'),
|
|
|
|
|
position: pinPosition,
|
|
|
|
|
icon: sourceIcon
|
|
|
|
|
icon: sourceIcon,
|
|
|
|
|
infoWindow: InfoWindow(title: TranslationBase.of(context).driver),
|
|
|
|
|
onTap: onSourceMarkerTap
|
|
|
|
|
));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
@ -208,7 +207,9 @@ class _TrackDriverState extends State<TrackDriver> {
|
|
|
|
|
_markers.add(Marker(
|
|
|
|
|
markerId: MarkerId('destPin'),
|
|
|
|
|
position: destPosition,
|
|
|
|
|
icon: destinationIcon
|
|
|
|
|
icon: destinationIcon,
|
|
|
|
|
infoWindow: InfoWindow(title: TranslationBase.of(context).deliveryLocation),
|
|
|
|
|
onTap: onDestinationMarkerTap
|
|
|
|
|
));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
@ -218,36 +219,7 @@ class _TrackDriverState extends State<TrackDriver> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void updatePinOnMap() async {
|
|
|
|
|
// create a new CameraPosition instance
|
|
|
|
|
// every time the location changes, so the camera
|
|
|
|
|
// follows the pin as it moves with an animation
|
|
|
|
|
CameraPosition cPosition = CameraPosition(
|
|
|
|
|
zoom: CAMERA_ZOOM,
|
|
|
|
|
tilt: CAMERA_TILT,
|
|
|
|
|
bearing: CAMERA_BEARING,
|
|
|
|
|
target: SOURCE_LOCATION,
|
|
|
|
|
);
|
|
|
|
|
final GoogleMapController controller = await _controller.future;
|
|
|
|
|
controller.animateCamera(CameraUpdate.newCameraPosition(cPosition));
|
|
|
|
|
|
|
|
|
|
_latLngStream.addLatLng(LatLngInfo(SOURCE_LOCATION.latitude, SOURCE_LOCATION.longitude, "sourcePin"));
|
|
|
|
|
|
|
|
|
|
// do this inside the setState() so Flutter gets notified
|
|
|
|
|
// that a widget update is due
|
|
|
|
|
// setState(() {
|
|
|
|
|
// // updated position
|
|
|
|
|
// var pinPosition = SOURCE_LOCATION;
|
|
|
|
|
//
|
|
|
|
|
// // the trick is to remove the marker (by id)
|
|
|
|
|
// // and add it again at the updated location
|
|
|
|
|
// _markers.removeWhere((m) => m.markerId.value == 'sourcePin');
|
|
|
|
|
// _markers.add(Marker(
|
|
|
|
|
// markerId: MarkerId('sourcePin'),
|
|
|
|
|
// position: pinPosition, // updated position
|
|
|
|
|
// icon: sourceIcon
|
|
|
|
|
// ));
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
drawRoute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -283,9 +255,14 @@ class _TrackDriverState extends State<TrackDriver> {
|
|
|
|
|
int driverId = int.tryParse(_order.driverID);
|
|
|
|
|
|
|
|
|
|
Future.doWhile(() async{
|
|
|
|
|
await Future.delayed(Duration(seconds: frequencyInSeconds));
|
|
|
|
|
if(isLocationUpdating){
|
|
|
|
|
|
|
|
|
|
await Future.delayed(Duration(seconds: frequencyInSeconds));
|
|
|
|
|
|
|
|
|
|
showLoading();
|
|
|
|
|
LatLng driverLocation = (await _orderServices.getDriverLocation(driverId));
|
|
|
|
|
hideLoading();
|
|
|
|
|
|
|
|
|
|
if(driverLocation != null){
|
|
|
|
|
if(SOURCE_LOCATION == null || DEST_LOCATION == null){
|
|
|
|
|
SOURCE_LOCATION = driverLocation;
|
|
|
|
|
@ -294,12 +271,26 @@ class _TrackDriverState extends State<TrackDriver> {
|
|
|
|
|
}
|
|
|
|
|
SOURCE_LOCATION = driverLocation;
|
|
|
|
|
updatePinOnMap();
|
|
|
|
|
updateMapCamera();
|
|
|
|
|
}else{
|
|
|
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return isLocationUpdating;
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
showLoading(){
|
|
|
|
|
if(SOURCE_LOCATION == null){
|
|
|
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hideLoading(){
|
|
|
|
|
if(SOURCE_LOCATION == null){
|
|
|
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stopUpdatingDriverLocation(){
|
|
|
|
|
@ -316,4 +307,37 @@ class _TrackDriverState extends State<TrackDriver> {
|
|
|
|
|
int getMarkerIconSize(){
|
|
|
|
|
return 140;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateMapCamera() async{
|
|
|
|
|
if(SOURCE_LOCATION != null && DEST_LOCATION != null){
|
|
|
|
|
|
|
|
|
|
// 'package:google_maps_flutter_platform_interface/src/types/location.dart': Failed assertion: line 72 pos 16: 'southwest.latitude <= northeast.latitude': is not true.
|
|
|
|
|
LatLngBounds bound;
|
|
|
|
|
if(SOURCE_LOCATION.latitude <= DEST_LOCATION.latitude){
|
|
|
|
|
bound = LatLngBounds(southwest: SOURCE_LOCATION, northeast: DEST_LOCATION);
|
|
|
|
|
}else{
|
|
|
|
|
bound = LatLngBounds(southwest: DEST_LOCATION, northeast: SOURCE_LOCATION);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(bound == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
CameraUpdate camera = CameraUpdate.newLatLngBounds(bound, 50);
|
|
|
|
|
final GoogleMapController controller = await _controller.future;
|
|
|
|
|
controller.animateCamera(camera);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool showSrcMarkerTitle = false;
|
|
|
|
|
onSourceMarkerTap() async{
|
|
|
|
|
// showSrcMarkerTitle = !showSrcMarkerTitle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool showDestMarkerTitle = false;
|
|
|
|
|
onDestinationMarkerTap() async{
|
|
|
|
|
// showDestMarkerTitle = !showDestMarkerTitle;
|
|
|
|
|
// Marker m = _markers.firstWhere((m) => m.markerId.value == 'destPin');
|
|
|
|
|
// if(showDestMarkerTitle){
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|