From 15ec3ec9b98dc68dbe204c96d26298ddf5c4170f Mon Sep 17 00:00:00 2001 From: Zohaib Iqbal Kambrani <> Date: Wed, 24 Feb 2021 18:18:26 +0300 Subject: [PATCH] Translation Track Driver, enhancement, initial camera --- lib/config/localized_values.dart | 2 + lib/pages/pharmacy/order/TrackDriver.dart | 142 +++++++++++++--------- lib/uitl/translations_delegate_base.dart | 2 + 3 files changed, 87 insertions(+), 59 deletions(-) diff --git a/lib/config/localized_values.dart b/lib/config/localized_values.dart index 614f3a54..6ab1a723 100644 --- a/lib/config/localized_values.dart +++ b/lib/config/localized_values.dart @@ -379,6 +379,8 @@ const Map localizedValues = { "OrderNo": {"en": "Order No", "ar": "رقم الطلب"}, "OrderDetails": {"en": "Order Details", "ar": "تفاصيل الطلب"}, "DeliveryDriverTrack": {"en": "Driver Tracking", "ar": "تتبع السائق"}, + "DeliveryLocation": {"en": "Delivery Location", "ar": "موقع التسليم"}, + "Driver": {"en": "Driver", "ar": "السائق"}, "VitalSign": {"en": "Vital Sign", "ar": "العلامة حيوية"}, "MonthlyReports": {"en": "Monthly Reports", "ar": "تقارير شهرية"}, "km": {"en": "KMs:", "ar": "كم"}, diff --git a/lib/pages/pharmacy/order/TrackDriver.dart b/lib/pages/pharmacy/order/TrackDriver.dart index 89e75e19..3b8779dd 100644 --- a/lib/pages/pharmacy/order/TrackDriver.dart +++ b/lib/pages/pharmacy/order/TrackDriver.dart @@ -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 { @override void initState() { + super.initState(); _order = widget.order; DEST_LOCATION = _order.shippingAddress.getLocation(); @@ -69,7 +71,6 @@ class _TrackDriverState extends State { initMarkerUpdateStream(); startUpdatingDriverLocation(); - super.initState(); } @override @@ -98,6 +99,7 @@ class _TrackDriverState extends State { delta.from.latitude, delta.from.longitude, ), + onTap: onSourceMarkerTap ); _markers.removeWhere((m) => m.markerId.value == 'sourcePin'); @@ -121,10 +123,10 @@ class _TrackDriverState extends State { 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 { } 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 { } - Future _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 { _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 { _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 { } 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 { 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 { } 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 { int getMarkerIconSize(){ return 140; } -} \ No newline at end of file + + 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){ + // } + } +} diff --git a/lib/uitl/translations_delegate_base.dart b/lib/uitl/translations_delegate_base.dart index 557dc6f7..9ed7b478 100644 --- a/lib/uitl/translations_delegate_base.dart +++ b/lib/uitl/translations_delegate_base.dart @@ -563,6 +563,8 @@ class TranslationBase { String get shippedMethod => localizedValues['shippedMethod'][locale.languageCode]; String get orderDetail => localizedValues['orderDetail'][locale.languageCode]; String get deliveryDriverTrack => localizedValues['DeliveryDriverTrack'][locale.languageCode]; + String get deliveryLocation => localizedValues['DeliveryLocation'][locale.languageCode]; + String get driver => localizedValues['Driver'][locale.languageCode]; String get subtotal => localizedValues['subtotal'][locale.languageCode]; String get shipping => localizedValues['shipping'][locale.languageCode]; String get shipBy => localizedValues['shipBy'][locale.languageCode];