12/24/1
This commit is contained in:
@@ -5,14 +5,12 @@ import 'dart:math' as math;
|
||||
import 'dart:ui';
|
||||
import 'package:SEFER/constant/univeries_polygon.dart';
|
||||
import 'package:SEFER/controller/firebase/local_notification.dart';
|
||||
import 'package:SEFER/views/widgets/mysnakbar.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_confetti/flutter_confetti.dart';
|
||||
import 'package:vector_math/vector_math.dart' show radians, degrees;
|
||||
|
||||
import 'package:SEFER/controller/functions/tts.dart';
|
||||
import 'package:SEFER/views/home/map_page_passenger.dart';
|
||||
import 'package:SEFER/views/widgets/my_dialog.dart';
|
||||
import 'package:SEFER/views/widgets/my_textField.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
@@ -34,9 +32,12 @@ import '../../main.dart';
|
||||
import '../../models/model/locations.dart';
|
||||
import '../../models/model/painter_copoun.dart';
|
||||
import '../../print.dart';
|
||||
import '../../views/home/map_widget.dart/cancel_raide_page.dart';
|
||||
import '../../views/home/map_widget.dart/car_details_widget_to_go.dart';
|
||||
import '../../views/home/map_widget.dart/select_driver_mishwari.dart';
|
||||
import '../../views/widgets/elevated_btn.dart';
|
||||
import '../../views/widgets/error_snakbar.dart';
|
||||
import '../../views/widgets/mydialoug.dart';
|
||||
import '../firebase/firbase_messge.dart';
|
||||
import '../functions/audio_record1.dart';
|
||||
import '../functions/crud.dart';
|
||||
@@ -565,8 +566,7 @@ class MapPassengerController extends GetxController {
|
||||
}
|
||||
|
||||
void changeCancelRidePageShow() {
|
||||
// rideConfirm == true
|
||||
// ?
|
||||
showCancelRideBottomSheet();
|
||||
isCancelRidePageShown = !isCancelRidePageShown;
|
||||
// : cancelRide();
|
||||
update();
|
||||
@@ -1791,16 +1791,17 @@ class MapPassengerController extends GetxController {
|
||||
return;
|
||||
}
|
||||
driversStatusForSearchWindow = 'Your order is being prepared'.tr;
|
||||
Log.print('driversStatusForSearchWindow: ${driversStatusForSearchWindow}');
|
||||
Log.print('driversStatusForSearchWindow: $driversStatusForSearchWindow');
|
||||
update();
|
||||
await postRideDetailsToServer();
|
||||
driversStatusForSearchWindow = 'Your order sent to drivers'.tr;
|
||||
delayAndFetchRideStatusForAllDriverAvailable(rideId);
|
||||
await notifyAvailableDrivers();
|
||||
|
||||
driversStatusForSearchWindow = 'The drivers are reviewing your request'.tr;
|
||||
Log.print('driversStatusForSearchWindow: ${driversStatusForSearchWindow}');
|
||||
Log.print('driversStatusForSearchWindow: $driversStatusForSearchWindow');
|
||||
update();
|
||||
delayAndFetchRideStatusForAllDriverAvailable(rideId);
|
||||
|
||||
// update();
|
||||
}
|
||||
|
||||
@@ -1829,9 +1830,9 @@ class MapPassengerController extends GetxController {
|
||||
}
|
||||
|
||||
// await postRideDetailsToServer();
|
||||
await notifyAvailableDrivers();
|
||||
delayAndFetchRideStatusForAllDriverAvailable(rideId);
|
||||
update();
|
||||
// update();
|
||||
await notifyAvailableDrivers();
|
||||
}
|
||||
|
||||
bool isDriversDataValid() {
|
||||
@@ -2023,7 +2024,7 @@ class MapPassengerController extends GetxController {
|
||||
tick = 0;
|
||||
await addRideToNotificationDriverAvailable();
|
||||
Timer.periodic(const Duration(seconds: 1), (timer) async {
|
||||
if (attemptCounter >= maxAttempts || isApplied) {
|
||||
if (attemptCounter >= maxAttempts || isApplied == true) {
|
||||
timer.cancel();
|
||||
_rideStatusStreamController.close(); // Close the stream when done
|
||||
return;
|
||||
@@ -2034,9 +2035,9 @@ class MapPassengerController extends GetxController {
|
||||
|
||||
try {
|
||||
var res = await getRideStatus(rideId);
|
||||
Log.print('res:2022 ${res}');
|
||||
Log.print('res:2022 $res');
|
||||
String rideStatusDelayed = res.toString();
|
||||
Log.print('rideStatusDelayed: ${rideStatusDelayed}');
|
||||
Log.print('rideStatusDelayed: $rideStatusDelayed');
|
||||
|
||||
_rideStatusStreamController
|
||||
.add(rideStatusDelayed); // Emit the ride status
|
||||
@@ -2051,6 +2052,7 @@ class MapPassengerController extends GetxController {
|
||||
//
|
||||
} else if (rideStatusDelayed == 'Apply' ||
|
||||
rideStatusDelayed == 'Applied') {
|
||||
isApplied = true;
|
||||
rideAppliedFromDriver(isApplied);
|
||||
timer.cancel();
|
||||
// Close stream after applying
|
||||
@@ -2525,7 +2527,7 @@ class MapPassengerController extends GetxController {
|
||||
noCarString = false;
|
||||
dataCarsLocationByPassenger = jsonDecode(res);
|
||||
Log.print(
|
||||
'dataCarsLocationByPassenger:getCarsLocationByPassengerAndReloadMarker ${dataCarsLocationByPassenger}');
|
||||
'dataCarsLocationByPassenger:getCarsLocationByPassengerAndReloadMarker $dataCarsLocationByPassenger');
|
||||
|
||||
// Check if 'message' is present and not null
|
||||
if (dataCarsLocationByPassenger != null &&
|
||||
@@ -3084,7 +3086,7 @@ class MapPassengerController extends GetxController {
|
||||
changeCancelRidePageShow();
|
||||
if (rideId != 'yet') {
|
||||
Log.print('cancelRide: 1');
|
||||
FirebaseMessagesController().sendNotificationToDriverMAP(
|
||||
await FirebaseMessagesController().sendNotificationToDriverMAP(
|
||||
'Cancel Trip'.tr,
|
||||
'Trip Cancelled'.tr,
|
||||
driverToken.toString(),
|
||||
@@ -3698,6 +3700,11 @@ class MapPassengerController extends GetxController {
|
||||
controller.animateCamera(
|
||||
CameraUpdate.newLatLng(passengerLocation),
|
||||
);
|
||||
// Future.delayed(const Duration(milliseconds: 500), () {
|
||||
// markers.forEach((marker) {
|
||||
// controller.showMarkerInfoWindow(marker.markerId);
|
||||
// });
|
||||
// });
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -4011,7 +4018,7 @@ class MapPassengerController extends GetxController {
|
||||
late String startNameAddress = '';
|
||||
late String endNameAddress = '';
|
||||
|
||||
getMap(String origin, destination) async {
|
||||
getDirectionMap(String origin, destination) async {
|
||||
isLoading = true;
|
||||
update();
|
||||
remainingTime = 25; //to make cancel every call
|
||||
@@ -4043,22 +4050,7 @@ class MapPassengerController extends GetxController {
|
||||
isLoading = false;
|
||||
newStartPointLocation = LatLng(
|
||||
data[0]["start_location"]['lat'], data[0]["start_location"]['lng']);
|
||||
markers.add(
|
||||
Marker(
|
||||
markerId: const MarkerId('start'),
|
||||
position: newStartPointLocation,
|
||||
icon: startIcon,
|
||||
),
|
||||
);
|
||||
markers.add(
|
||||
Marker(
|
||||
markerId: const MarkerId('end'),
|
||||
position: LatLng(
|
||||
data[0]["end_location"]['lat'], data[0]["end_location"]['lng']),
|
||||
icon: endIcon,
|
||||
),
|
||||
);
|
||||
update();
|
||||
|
||||
durationToRide = data[0]['duration']['value'];
|
||||
final points =
|
||||
decodePolyline(response["routes"][0]["overview_polyline"]["points"]);
|
||||
@@ -4081,31 +4073,176 @@ class MapPassengerController extends GetxController {
|
||||
LatLngBounds(northeast: northeast, southwest: southwest);
|
||||
|
||||
// Fit the camera to the bounds
|
||||
var cameraUpdate = CameraUpdate.newLatLngBounds(boundsData, 160);
|
||||
var cameraUpdate = CameraUpdate.newLatLngBounds(boundsData, 100);
|
||||
mapController!.animateCamera(cameraUpdate);
|
||||
|
||||
// getDistanceFromText(data[0]['distance']['text']);
|
||||
double distanceOfTrip = (data[0]['distance']['value']) / 1000;
|
||||
distance = distanceOfTrip;
|
||||
durationToAdd = Duration(seconds: durationToRide);
|
||||
hours = durationToAdd.inHours;
|
||||
minutes = (durationToAdd.inMinutes % 60).round();
|
||||
// updateCameraForDistanceAfterGetMap();
|
||||
markers.clear();
|
||||
update();
|
||||
markers.add(
|
||||
Marker(
|
||||
markerId: const MarkerId('start'),
|
||||
position: newStartPointLocation,
|
||||
icon: startIcon,
|
||||
infoWindow: InfoWindow(
|
||||
title: startNameAddress,
|
||||
snippet: '',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Add end marker
|
||||
markers.add(
|
||||
Marker(
|
||||
markerId: const MarkerId('end'),
|
||||
position: LatLng(
|
||||
data[0]["end_location"]['lat'], data[0]["end_location"]['lng']),
|
||||
icon: endIcon,
|
||||
infoWindow: InfoWindow(
|
||||
title: endNameAddress,
|
||||
snippet:
|
||||
'$distance ${'KM'.tr} ⌛ ${hours > 0 ? '${'Your Ride Duration is '.tr}$hours ${'H and'.tr} $minutes ${'m'.tr}' : '${'Your Ride Duration is '.tr} $minutes ${'m'.tr}'}'),
|
||||
),
|
||||
);
|
||||
// // Show info windows automatically
|
||||
// Future.delayed(const Duration(milliseconds: 500), () {
|
||||
// mapController?.showMarkerInfoWindow(const MarkerId('start'));
|
||||
// });
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
mapController?.showMarkerInfoWindow(const MarkerId('end'));
|
||||
});
|
||||
update();
|
||||
|
||||
if (polyLines.isNotEmpty) {
|
||||
clearPolyline();
|
||||
} else {
|
||||
var polyline = Polyline(
|
||||
polylineId: PolylineId(response["routes"][0]["summary"]),
|
||||
points: polylineCoordinates,
|
||||
width: 10,
|
||||
color: Colors.blue,
|
||||
);
|
||||
|
||||
polyLines.add(polyline);
|
||||
_animatePolyline(polylineCoordinates);
|
||||
rideConfirm = false;
|
||||
isMarkersShown = true;
|
||||
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _animatePolyline(List<LatLng> coordinates) async {
|
||||
// Initial animation
|
||||
polyLines.clear();
|
||||
List<LatLng> animatedPoints = [];
|
||||
|
||||
// Draw initial polyline
|
||||
for (int i = 0; i < coordinates.length; i++) {
|
||||
animatedPoints.add(coordinates[i]);
|
||||
polyLines.clear();
|
||||
polyLines.add(
|
||||
Polyline(
|
||||
polylineId: const PolylineId('animated_route'),
|
||||
points: List<LatLng>.from(animatedPoints),
|
||||
width: 4,
|
||||
color: AppColor.primaryColor,
|
||||
endCap: Cap.roundCap,
|
||||
startCap: Cap.roundCap,
|
||||
geodesic: true,
|
||||
),
|
||||
);
|
||||
|
||||
update();
|
||||
await Future.delayed(const Duration(milliseconds: 1));
|
||||
}
|
||||
|
||||
// Color change animations
|
||||
for (int cycle = 0; cycle < 6; cycle++) {
|
||||
// Change to green
|
||||
polyLines.clear();
|
||||
polyLines.add(
|
||||
Polyline(
|
||||
polylineId: const PolylineId('animated_route'),
|
||||
points: coordinates,
|
||||
width: 4,
|
||||
color: AppColor.bronze,
|
||||
endCap: Cap.roundCap,
|
||||
startCap: Cap.roundCap,
|
||||
geodesic: true,
|
||||
),
|
||||
);
|
||||
update();
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
|
||||
// Change back to primary color
|
||||
polyLines.clear();
|
||||
polyLines.add(
|
||||
Polyline(
|
||||
polylineId: const PolylineId('animated_route'),
|
||||
points: coordinates,
|
||||
width: 4,
|
||||
color: AppColor.writeColor,
|
||||
endCap: Cap.roundCap,
|
||||
startCap: Cap.roundCap,
|
||||
geodesic: true,
|
||||
),
|
||||
);
|
||||
update();
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
}
|
||||
}
|
||||
// Add this method to your controller class
|
||||
// Future<void> _animatePolyline(List<LatLng> coordinates) async {
|
||||
// // Clear existing polylines
|
||||
// polyLines.clear();
|
||||
|
||||
// // Create segments for animation
|
||||
// List<LatLng> animatedPoints = [];
|
||||
|
||||
// // Calculate step size for smoother animation
|
||||
// int stepSize = (coordinates.length / 20).round();
|
||||
// stepSize = stepSize < 1 ? 1 : stepSize;
|
||||
|
||||
// for (int i = 0; i < coordinates.length; i += stepSize) {
|
||||
// // Add points gradually
|
||||
// animatedPoints.add(coordinates[i]);
|
||||
|
||||
// if (animatedPoints.length > 1) {
|
||||
// // Remove previous polyline
|
||||
// if (polyLines.isNotEmpty) {
|
||||
// polyLines.clear();
|
||||
// }
|
||||
// // Add new polyline segment
|
||||
// polyLines.add(
|
||||
// Polyline(
|
||||
// polylineId: const PolylineId('animated_route'),
|
||||
// points: List<LatLng>.from(animatedPoints),
|
||||
// width: 4,
|
||||
// color: Colors.blue,
|
||||
// ),
|
||||
// );
|
||||
|
||||
// // Update camera position to follow animation
|
||||
// if (mapController != null) {
|
||||
// final bounds = LatLngBounds(
|
||||
// southwest: animatedPoints.reduce((value, element) => LatLng(
|
||||
// min(value.latitude, element.latitude),
|
||||
// min(value.longitude, element.longitude))),
|
||||
// northeast: animatedPoints.reduce((value, element) => LatLng(
|
||||
// max(value.latitude, element.latitude),
|
||||
// max(value.longitude, element.longitude))),
|
||||
// );
|
||||
|
||||
// mapController!.animateCamera(
|
||||
// CameraUpdate.newLatLngBounds(bounds, 100),
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
// update();
|
||||
// await Future.delayed(const Duration(milliseconds: 50));
|
||||
// }
|
||||
// }
|
||||
|
||||
String shortenAddress(String fullAddress) {
|
||||
// Split the address into parts
|
||||
List<String> parts = fullAddress.split('،');
|
||||
@@ -4871,7 +5008,7 @@ class MapPassengerController extends GetxController {
|
||||
try {
|
||||
var d = jsonDecode(res);
|
||||
driversForMishwari = d['message'];
|
||||
Log.print('driversForMishwari: ${driversForMishwari}');
|
||||
Log.print('driversForMishwari: $driversForMishwari');
|
||||
update();
|
||||
} catch (e) {
|
||||
// Handle invalid JSON format
|
||||
|
||||
Reference in New Issue
Block a user