This commit is contained in:
Hamza-Ayed
2023-12-31 00:11:49 +03:00
parent 1b9b0dc9e8
commit c2dc5ec44c
21 changed files with 792 additions and 496 deletions

View File

@@ -180,7 +180,7 @@ class HomeCaptainController extends GetxController {
@override
void onInit() async {
addToken();
await addToken();
onButtonSelected();
getPaymentToday();
getAllPayment();
@@ -191,11 +191,11 @@ class HomeCaptainController extends GetxController {
}
addToken() async {
box.write(BoxName.statusDriverLocation, 'off');
await CRUD().post(link: AppLink.addTokensDriver, payload: {
'token': box.read(BoxName.tokenDriver),
'captain_id': box.read(BoxName.driverID).toString()
}).then((value) => print('Token Added'));
box.write(BoxName.statusDriverLocation, 'off');
}
getPaymentToday() async {

View File

@@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_font_icons/flutter_font_icons.dart';
import 'package:get/get.dart';
import 'package:ride/controller/home/captin/home_captain_controller.dart';
import 'package:ride/controller/home/captin/map_driver_controller.dart';
import 'package:ride/controller/home/captin/widget/zones_controller.dart';
import '../../../../constant/colors.dart';

View File

@@ -25,22 +25,26 @@ import '../payment/payment_controller.dart';
class MapPassengerController extends GetxController {
bool isLoading = true;
TextEditingController placeController = TextEditingController();
TextEditingController placeDestinationController = TextEditingController();
TextEditingController placeStartController = TextEditingController();
TextEditingController sosPhonePassengerProfile = TextEditingController();
final sosFormKey = GlobalKey<FormState>();
List data = [];
List<LatLng> bounds = [];
List places = [];
List placesStart = [];
List placesDestination = [];
LatLngBounds? boundsdata;
List<Marker> markers = [];
List<Polyline> polyLines = [];
late LatLng myLocation;
late LatLng newMyLocation = const LatLng(32.115295, 36.064773);
late LatLng newStartPointLocation = const LatLng(32.115295, 36.064773);
LatLng myDestination = const LatLng(32.115295, 36.064773);
final List<LatLng> polylineCoordinates = [];
List<LatLng> carsLocationByPassenger = [];
List<LatLng> driverCarsLocationToPassengerAfterApplied = [];
BitmapDescriptor markerIcon = BitmapDescriptor.defaultMarker;
BitmapDescriptor tripIcon = BitmapDescriptor.defaultMarker;
BitmapDescriptor carIcon = BitmapDescriptor.defaultMarker;
double height = 150;
DateTime currentTime = DateTime.now();
@@ -50,6 +54,7 @@ class MapPassengerController extends GetxController {
double widthMenu = 0;
double heightPickerContainer = 90;
double mainBottomMenuMap = Get.height * .2;
bool startLocationFromMap = false;
bool heightMenuBool = false;
bool isPickerShown = false;
bool isBottomSheetShown = false;
@@ -87,10 +92,14 @@ class MapPassengerController extends GetxController {
double progressTimerRideBegin = 0;
int remainingTimeTimerRideBegin = 60;
String stringRemainingTimeRideBegin = '';
String hintTextStartPoint = 'Search for your Start point'.tr;
String currentLocationString = 'Current Location'.tr;
String hintTextDestinationPoint = 'Search for your destination'.tr;
late String rideId;
bool noCarString = false;
bool isCashSelectedBeforeConfirmRide = false;
bool isPassengerChosen = false;
bool currentLocationToFormPlaces = false;
late String driverToken;
int carsOrder = 0;
String? mapAPIKEY;
@@ -105,6 +114,41 @@ class MapPassengerController extends GetxController {
update();
}
void getCurrentLocationFormString() async {
currentLocationToFormPlaces = true;
await getLocation();
currentLocationString = myLocation.toString();
newStartPointLocation = myLocation;
update();
}
void convertHintTextStartNewPlaces(int index) {
if (placesStart.isEmpty) {
hintTextStartPoint = 'Search for your Start point'.tr;
update();
} else {
hintTextStartPoint = placesStart[index]['name'];
double lat = placesStart[index]['geometry']['location']['lat'];
double lng = placesStart[index]['geometry']['location']['lng'];
newStartPointLocation = LatLng(lat, lng);
update();
}
}
void convertHintTextDestinationNewPlaces(int index) {
if (placesDestination.isEmpty) {
hintTextDestinationPoint = 'Search for your destination'.tr;
update();
} else {
hintTextDestinationPoint = placesDestination[index]['name'];
double lat = placesDestination[index]['geometry']['location']['lat'];
double lng = placesDestination[index]['geometry']['location']['lng'];
newMyLocation = LatLng(lat, lng);
update();
}
}
// final mainBottomMenuMap = GlobalKey<AnimatedContainer>();
void changeBottomSheetShown() {
isBottomSheetShown = !isBottomSheetShown;
@@ -261,8 +305,15 @@ class MapPassengerController extends GetxController {
timerToPassengerFromDriverAfterApplied?.cancel();
}
void clearPlaces() {
places = [];
void clearPlacesDestination() {
placesDestination = [];
hintTextDestinationPoint = 'Search for your destination'.tr;
update();
}
void clearPlacesStart() {
placesStart = [];
hintTextStartPoint = 'Search for your Start point'.tr;
update();
}
@@ -558,7 +609,7 @@ class MapPassengerController extends GetxController {
}
restCounter() {
clearPlaces();
clearPlacesDestination();
clearPolyline();
data = [];
rideConfirm = false;
@@ -568,7 +619,7 @@ class MapPassengerController extends GetxController {
}
Future<void> cancelRideAfterRejectFromAll() async {
clearPlaces();
clearPlacesDestination();
clearPolyline();
data = [];
await CRUD().post(link: AppLink.updateDriverOrder, payload: {
@@ -591,7 +642,7 @@ class MapPassengerController extends GetxController {
print("rideConfirm=$rideConfirm");
if (rideConfirm == false) {
clearPlaces();
clearPlacesDestination();
clearPolyline();
data = [];
changeCancelRidePageShow();
@@ -604,7 +655,7 @@ class MapPassengerController extends GetxController {
timeToPassengerFromDriverAfterApplied = 0;
update();
} else {
clearPlaces();
clearPlacesDestination();
clearPolyline();
data = [];
await CRUD().post(link: AppLink.updateDriverOrder, payload: {
@@ -634,15 +685,24 @@ class MapPassengerController extends GetxController {
void changeMainBottomMenuMap() {
isMainBottomMenuMap = !isMainBottomMenuMap;
mainBottomMenuMap =
isMainBottomMenuMap == true ? Get.height * .2 : Get.height * .66;
isMainBottomMenuMap == true ? Get.height * .2 : Get.height * .7;
if (heightMenuBool == true) {
getDrawerMenu();
}
update();
}
changeHeight() {
if (places.isEmpty) {
changeHeightPlaces() {
if (placesDestination.isEmpty) {
height = 0;
update();
}
height = 150;
update();
}
changeHeightStartPlaces() {
if (placesStart.isEmpty) {
height = 0;
update();
}
@@ -659,12 +719,24 @@ class MapPassengerController extends GetxController {
Future getPlaces() async {
var url =
// '${AppLink.googleMapsLink}place/nearbysearch/json?location=${mylocation.longitude}&radius=25000&language=ar&keyword=&key=${placeController.text}${AK.mapAPIKEY}';
'${AppLink.googleMapsLink}place/nearbysearch/json?keyword=${placeController.text}&location=${myLocation.latitude},${myLocation.longitude}&radius=50000&language=en&key=${AK.mapAPIKEY.toString()}';
'${AppLink.googleMapsLink}place/nearbysearch/json?keyword=${placeDestinationController.text}&location=${myLocation.latitude},${myLocation.longitude}&radius=50000&language=en&key=${AK.mapAPIKEY.toString()}';
var response = await CRUD().getGoogleApi(link: url, payload: {});
places = response['results'];
print(places);
placesDestination = response['results'];
print(placesDestination);
update();
}
Future getPlacesStart() async {
var url =
// '${AppLink.googleMapsLink}place/nearbysearch/json?location=${mylocation.longitude}&radius=25000&language=ar&keyword=&key=${placeController.text}${AK.mapAPIKEY}';
'${AppLink.googleMapsLink}place/nearbysearch/json?keyword=${placeStartController.text}&location=${myLocation.latitude},${myLocation.longitude}&radius=50000&language=en&key=${AK.mapAPIKEY.toString()}';
var response = await CRUD().getGoogleApi(link: url, payload: {});
placesStart = response['results'];
print(placesStart);
update();
}
@@ -693,9 +765,21 @@ class MapPassengerController extends GetxController {
});
}
void addCustomTripIcon() {
ImageConfiguration config = ImageConfiguration(
size: Size(Get.width * .6, Get.height * .6),
);
BitmapDescriptor.fromAssetImage(config, 'assets/images/picker.png')
.then((value) {
tripIcon = value;
update();
});
}
void addCustomCarIcon() {
ImageConfiguration config = ImageConfiguration(
size: Size(Get.width * .6, Get.height * .6),
// size: Size(20, 20),
// scale: 1.0,
);
BitmapDescriptor.fromAssetImage(config, 'assets/images/car.png')
@@ -742,10 +826,10 @@ class MapPassengerController extends GetxController {
: null)!;
// Print location details
print('Accuracy: ${_locationData.accuracy}');
print('Latitude: ${_locationData.latitude}');
print('Longitude: ${_locationData.longitude}');
print('Time: ${_locationData.time}');
// print('Accuracy: ${_locationData.accuracy}');
// print('Latitude: ${_locationData.latitude}');
// print('Longitude: ${_locationData.longitude}');
// print('Time: ${_locationData.time}');
isLoading = false;
update();
}
@@ -926,19 +1010,23 @@ class MapPassengerController extends GetxController {
getMap(String origin, destination) async {
var origin1 = fromString(origin);
var destination1 = fromString(destination);
isLoading = false;
isLoading = true;
update();
myDestination = destination1;
myLocation = origin1;
update();
await getCarsLocationByPassenger();
// print(carsLocationByPassenger);
isLoading = false;
update();
var url =
('${AppLink.googleMapsLink}directions/json?&language=en&avoid=tolls|ferries&destination=$destination&origin=$origin&key=${AK.mapAPIKEY}');
var response = await CRUD().getGoogleApi(link: url, payload: {});
data = response['routes'][0]['legs'];
print(data);
isLoading = false;
update();
durationToRide = data[0]['duration']['value'];
final points =
decodePolyline(response["routes"][0]["overview_polyline"]["points"]);
@@ -1137,83 +1225,6 @@ class MapPassengerController extends GetxController {
// buttomSheetMapPage();
changeBottomSheetShown();
}
// Get.bottomSheet(
// Container(
// height: 130,
// decoration: const BoxDecoration(
// color: AppColor.secondaryColor,
// borderRadius: BorderRadius.only(
// topLeft: Radius.circular(15), topRight: Radius.circular(15))),
// child: data.isEmpty
// ? Center(
// child: Text(
// 'Where are you want to go..',
// style: AppStyle.title,
// ))
// : Center(
// child: Column(
// children: [
// Row(
// mainAxisAlignment: MainAxisAlignment.spaceAround,
// children: [
// Text(
// 'distance is ${data[0]['distance']['text']}',
// style: AppStyle.title,
// ),
// Text(
// 'duration is ${data[0]['duration']['text']}',
// style: AppStyle.title,
// ),
// ],
// ),
// Row(
// mainAxisAlignment: MainAxisAlignment.spaceAround,
// children: [
// Text(
// 'Cost for .21/km ${cost.toStringAsFixed(2)} ',
// style: AppStyle.title,
// ),
// Text(
// 'costDuration ${averageDuration.toStringAsFixed(2)} is ${costDuration.toStringAsFixed(2)} ',
// style: AppStyle.title,
// ),
// ],
// ),
// Row(
// mainAxisAlignment: MainAxisAlignment.spaceAround,
// children: [
// Text(
// 'Cost for passenger ${totalPassenger.toStringAsFixed(2)} ',
// style: AppStyle.title,
// ),
// Text(
// 'totaME ${totaME.toStringAsFixed(2)} ',
// style: AppStyle.title,
// ),
// ],
// ),
// Text(
// 'totalDriver ${totalDriver.toStringAsFixed(2)}',
// style: AppStyle.title,
// ),
// ],
// ),
// ),
// ),
// elevation: 6,
// enableDrag: true,
// isScrollControlled: true,
// isDismissible: true,
// useRootNavigator: true,
// backgroundColor: Colors.transparent,
// barrierColor: AppColor.accentColor.withOpacity(.4),
// persistent: true,
// shape: ShapeBorder.lerp(
// RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
// RoundedRectangleBorder(borderRadius: BorderRadius.circular(6)),
// 0.5),
// );
}
addToken() async {
@@ -1234,6 +1245,7 @@ class MapPassengerController extends GetxController {
getNearestDriverByPassengerLocation();
addCustomPicker();
addCustomCarIcon();
addCustomTripIcon();
startMarkerReloading();
cardNumber = await SecureStorage().readData(BoxName.cardNumber);
super.onInit();