10/3/1
This commit is contained in:
@@ -1,21 +1,69 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
import 'package:google_polyline_algorithm/google_polyline_algorithm.dart';
|
||||
import 'package:ride/constant/colors.dart';
|
||||
import 'package:ride/controller/functions/location_controller.dart';
|
||||
|
||||
import '../../../constant/credential.dart';
|
||||
import '../../../constant/links.dart';
|
||||
import '../../functions/crud.dart';
|
||||
|
||||
class MapDirction extends GetxController {
|
||||
class MapDirection extends GetxController {
|
||||
bool isLoading = true;
|
||||
List data = [];
|
||||
LatLngBounds? boundsdata;
|
||||
|
||||
LatLngBounds? boundsData;
|
||||
BitmapDescriptor carIcon = BitmapDescriptor.defaultMarker;
|
||||
final List<LatLng> polylineCoordinates = [];
|
||||
List<Polyline> polyLines = [];
|
||||
Set<Marker> markers = {};
|
||||
|
||||
getMap(LatLng origin, destination) async {
|
||||
void clearPolyline() {
|
||||
polyLines = [];
|
||||
polylineCoordinates.clear();
|
||||
update();
|
||||
}
|
||||
|
||||
void updateMarker() {
|
||||
// Remove the existing marker with the ID `MyLocation`.
|
||||
markers.remove(MarkerId('MyLocation'.tr));
|
||||
|
||||
// Add a new marker with the ID `MyLocation` at the current location of the user.
|
||||
LocationController locationController = Get.find<LocationController>();
|
||||
markers.add(Marker(
|
||||
markerId: MarkerId('MyLocation'.tr),
|
||||
position: locationController.myLocation,
|
||||
draggable: true,
|
||||
icon: carIcon,
|
||||
// infoWindow: const InfoWindow(
|
||||
// title: 'Time',
|
||||
// ),
|
||||
));
|
||||
|
||||
// Update the `markers` set and call the `update()` method on the controller to notify the view that the marker position has changed.
|
||||
update();
|
||||
|
||||
// Reload the marker after 3 seconds.
|
||||
Future.delayed(const Duration(seconds: 3), () {
|
||||
updateMarker();
|
||||
});
|
||||
}
|
||||
|
||||
void addCustomCarIcon() {
|
||||
ImageConfiguration config = ImageConfiguration(
|
||||
size: Size(Get.width * .6, Get.height * .6),
|
||||
// scale: 1.0,
|
||||
);
|
||||
BitmapDescriptor.fromAssetImage(config, 'assets/images/car.png')
|
||||
.then((value) {
|
||||
carIcon = value;
|
||||
update();
|
||||
});
|
||||
}
|
||||
|
||||
getMap(String origin, destination) async {
|
||||
isLoading = false;
|
||||
|
||||
update();
|
||||
@@ -34,7 +82,16 @@ class MapDirction extends GetxController {
|
||||
polylineCoordinates.add(LatLng(lat, lng));
|
||||
}
|
||||
if (polyLines.isNotEmpty) {
|
||||
// clearPolyline();
|
||||
clearPolyline();
|
||||
var polyline = Polyline(
|
||||
polylineId: PolylineId(response["routes"][0]["summary"]),
|
||||
points: polylineCoordinates,
|
||||
width: 10,
|
||||
color: AppColor.blueColor,
|
||||
);
|
||||
polyLines.add(polyline);
|
||||
// rideConfirm = false;
|
||||
update();
|
||||
} else {
|
||||
var polyline = Polyline(
|
||||
polylineId: PolylineId(response["routes"][0]["summary"]),
|
||||
@@ -43,7 +100,7 @@ class MapDirction extends GetxController {
|
||||
color: AppColor.blueColor,
|
||||
);
|
||||
|
||||
// polyLines.add(polyline);
|
||||
polyLines.add(polyline);
|
||||
// rideConfirm = false;
|
||||
update();
|
||||
}
|
||||
@@ -51,6 +108,15 @@ class MapDirction extends GetxController {
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
// Get the passenger location from the arguments.
|
||||
String passengerLocation = Get.arguments['passengerLocation'];
|
||||
String lat = Get.find<LocationController>().myLocation.latitude.toString();
|
||||
String lng = Get.find<LocationController>().myLocation.longitude.toString();
|
||||
String origin = '$lat,$lng';
|
||||
// Set the origin and destination coordinates for the Google Maps directions request.
|
||||
getMap(origin, passengerLocation);
|
||||
addCustomCarIcon();
|
||||
updateMarker();
|
||||
super.onInit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,6 +168,7 @@ class MapController extends GetxController {
|
||||
}
|
||||
|
||||
var rideId;
|
||||
late String driverToken;
|
||||
int carsOrder = 0;
|
||||
changeConfirmRide() async {
|
||||
PaymentController paymentController = Get.find<PaymentController>();
|
||||
@@ -175,6 +176,8 @@ class MapController extends GetxController {
|
||||
shouldFetch = true;
|
||||
isBottomSheetShown = false;
|
||||
timeToPassengerFromDriverAfterApplied = 60;
|
||||
driverToken =
|
||||
dataCarsLocationByPassenger['message'][carsOrder]['token'].toString();
|
||||
update();
|
||||
// print('rideConfirm= $rideConfirm');
|
||||
|
||||
@@ -189,7 +192,8 @@ class MapController extends GetxController {
|
||||
"endtime": durationToAdd.toString(),
|
||||
"price": totalPassenger.toString(),
|
||||
"passenger_id": box.read(BoxName.pasengerID).toString(),
|
||||
"driver_id": dataCarsLocationByPassenger['message'][0]['id'].toString(),
|
||||
"driver_id":
|
||||
dataCarsLocationByPassenger['message'][carsOrder]['id'].toString(),
|
||||
"status": "waiting",
|
||||
"price_for_driver": totalDriver.toString(),
|
||||
"price_for_passenger": totalME.toString(),
|
||||
@@ -214,9 +218,10 @@ class MapController extends GetxController {
|
||||
box.read(BoxName.phone).toString(),
|
||||
durationByPassenger.toString(),
|
||||
distanceByPassenger.toString(),
|
||||
paymentController.isWalletChecked.toString()
|
||||
paymentController.isWalletChecked.toString(),
|
||||
dataCarsLocationByPassenger['message'][carsOrder]['token'].toString(),
|
||||
];
|
||||
FirebasMessagesController().sendNotificationToDriverMAP(
|
||||
FirebaseMessagesController().sendNotificationToDriverMAP(
|
||||
'Order',
|
||||
jsonDecode(value)['message'].toString(),
|
||||
dataCarsLocationByPassenger['message'][carsOrder]['token'].toString(),
|
||||
@@ -410,6 +415,7 @@ class MapController extends GetxController {
|
||||
changeCancelRidePageShow();
|
||||
rideConfirm = false;
|
||||
shouldFetch = false;
|
||||
timeToPassengerFromDriverAfterApplied = 0;
|
||||
update();
|
||||
} else {
|
||||
clearPlaces();
|
||||
@@ -417,12 +423,13 @@ class MapController extends GetxController {
|
||||
data = [];
|
||||
rideConfirm = false;
|
||||
shouldFetch = false;
|
||||
timeToPassengerFromDriverAfterApplied = 0;
|
||||
changeCancelRidePageShow();
|
||||
remainingTime = 25;
|
||||
update();
|
||||
|
||||
await CRUD().post(link: AppLink.addCancelRideFromPassenger, payload: {
|
||||
"driverID": FirebasMessagesController()
|
||||
"driverID": FirebaseMessagesController()
|
||||
.driverID
|
||||
.toString(), // Convert to String
|
||||
"passengerID":
|
||||
|
||||
Reference in New Issue
Block a user