This commit is contained in:
Hamza-Ayed
2023-08-10 18:01:47 +03:00
parent 766354ac99
commit f0c90127fe
16 changed files with 908 additions and 188 deletions

View File

@@ -9,6 +9,7 @@ import 'package:ride/constant/credential.dart';
import 'package:ride/constant/links.dart';
import 'package:ride/constant/style.dart';
import 'package:ride/controller/functions/crud.dart';
import 'package:ride/views/home/map_widget.dart/buttom_sheet_map_show.dart';
class MapController extends GetxController {
bool isloading = true;
@@ -20,12 +21,43 @@ class MapController extends GetxController {
List<Marker> markers = [];
List<Polyline> polylines = [];
late LatLng mylocation;
late LatLng newMylocation = const LatLng(32.115295, 36.064773);
LatLng mydestination = const LatLng(32.115295, 36.064773);
final List<LatLng> polylineCoordinates = [];
BitmapDescriptor markerIcon = BitmapDescriptor.defaultMarker;
double height = 200;
final location = Location();
late LocationData currentLocation;
double heightMenu = 70;
double heightPickerContainer = 90;
bool heightMenuBool = false;
bool isPickerShown = false;
bool isButtomSheetShown = false;
double heightButtomSheetShown = 240;
void changeButtomSheetShown() {
isButtomSheetShown = !isButtomSheetShown;
heightButtomSheetShown = isButtomSheetShown == true ? 240 : 0;
update();
}
void getDrawerMenu() {
heightMenuBool = !heightMenuBool;
heightMenu = heightMenuBool == true ? 100 : 0;
update();
}
void clearPlaces() {
places = [];
update();
}
void changePickerShown() {
isPickerShown = !isPickerShown;
heightPickerContainer = isPickerShown == true ? 150 : 90;
update();
}
changeHeight() {
if (places.isEmpty) {
height = 0;
@@ -108,10 +140,10 @@ class MapController extends GetxController {
(_locationData.latitude != null && _locationData.longitude != null
? LatLng(_locationData.latitude!, _locationData.longitude!)
: null)!;
print('accuracy' + _locationData.accuracy.toString());
print(_locationData.latitude);
print(_locationData.time);
print('//////////////////////////////////////');
// print('accuracy' + _locationData.accuracy.toString());
// print(_locationData.latitude);
// print(_locationData.time);
// print('//////////////////////////////////////');
update();
}
@@ -200,85 +232,130 @@ class MapController extends GetxController {
return distance;
}
late double totaME;
late double tax;
late double totalPassenger;
late double totalDriver;
late double averageDuration;
late double costDuration;
late double cost;
void bottomSheet() {
String distanceText = data[0]['distance']['text'];
String durationText = data[0]['duration']['text'];
double distance = getDistanceFromText(distanceText);
double duration = getDistanceFromText(durationText);
double cost = distance * 0.21;
double costDuration = duration * 0.05;
double totalPassenger = cost + costDuration;
Get.bottomSheet(
Container(
height: 130,
color: AppColor.secondaryColor,
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 ',
style: AppStyle.title,
),
Text(
'Cost duration .05/m $costDuration ',
style: AppStyle.title,
),
],
),
Text(
'Total cost $totalPassenger ',
style: AppStyle.title,
),
],
),
),
),
elevation: 6,
enableDrag: true,
isDismissible: true,
useRootNavigator: true,
backgroundColor: AppColor.secondaryColor,
barrierColor: AppColor.accentColor.withOpacity(.4),
persistent: true,
);
if (data.isNotEmpty) {
String distanceText = data[0]['distance']['text'];
String durationText = data[0]['duration']['text'];
double distance = getDistanceFromText(distanceText);
double duration = getDistanceFromText(durationText);
if (distanceText.contains('km')) {
cost = distance * 0.21;
} else {
cost = distance * 0.21 / 1000;
}
averageDuration = duration / distance;
costDuration = duration * averageDuration * 0.016;
totalDriver = cost + costDuration;
totalPassenger = totalDriver + (totalDriver * .16);
tax = totalPassenger * .04;
totaME = totalPassenger - totalDriver - tax;
if (totalPassenger < 1) {
totalPassenger = 1;
if (totalDriver < .5) {
totalDriver = .85;
totaME = .11;
} else {
totalDriver = .95;
totaME = .05;
}
}
}
buttomSheetMapPage();
// 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),
// );
}
List<LatLng> polylineCoordinate = [];
double calculateCost(double distance) {
const double costRate = 0.27;
// double distanceInKm = distance / 1000; // convert distance to kilometers
double cost = costRate * distance;
return cost;
}
@override
void onInit() {
// getPolyLine();
// getMap();
addCustomPicker();
getLocation();
addCustomPicker();
super.onInit();
}
}

View File

@@ -0,0 +1,15 @@
import 'package:get/get.dart';
class MyMenuController extends GetxController {
bool isDrawerOpen = true;
void getDrawerMenu() {
if (isDrawerOpen == true) {
isDrawerOpen = false;
} else {
isDrawerOpen = true;
}
print(isDrawerOpen);
update();
}
}