10/14/1
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:SEFER/constant/links.dart';
|
||||
@@ -5,7 +7,7 @@ import 'package:SEFER/constant/style.dart';
|
||||
import 'package:SEFER/main.dart';
|
||||
import 'package:SEFER/views/widgets/elevated_btn.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
|
||||
import 'dart:math' as math;
|
||||
import '../../../constant/box_name.dart';
|
||||
import '../../../constant/table_names.dart';
|
||||
import '../../functions/crud.dart';
|
||||
@@ -24,15 +26,73 @@ class OrderRequestController extends GetxController {
|
||||
final locationController = Get.put(LocationController());
|
||||
BitmapDescriptor startIcon = BitmapDescriptor.defaultMarker;
|
||||
BitmapDescriptor endIcon = BitmapDescriptor.defaultMarker;
|
||||
final arguments = Get.arguments;
|
||||
var myList;
|
||||
late int hours;
|
||||
late int minutes;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
getRefusedOrderByCaptain();
|
||||
// getRefusedOrderByCaptain();
|
||||
initilizeOrderPage();
|
||||
addCustomStartIcon();
|
||||
addCustomEndIcon();
|
||||
// calculateConsumptionFuel();
|
||||
update();
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
late LatLngBounds bounds;
|
||||
late List<LatLng> pointsDirection;
|
||||
late String body;
|
||||
late double latPassengerLocation;
|
||||
late double lngPassengerLocation;
|
||||
late double lngPassengerDestination;
|
||||
late double latPassengerDestination;
|
||||
initilizeOrderPage() {
|
||||
final myListString = arguments['myListString'];
|
||||
// final myList = arguments['DriverList'];
|
||||
if (arguments['DriverList'] == null || arguments['DriverList'].isEmpty) {
|
||||
myList = jsonDecode(myListString);
|
||||
} else {
|
||||
myList = arguments['DriverList'];
|
||||
}
|
||||
|
||||
body = arguments['body'];
|
||||
Duration durationToAdd = Duration(seconds: int.parse(myList[4]));
|
||||
hours = durationToAdd.inHours;
|
||||
minutes = (durationToAdd.inMinutes % 60).round();
|
||||
startTimerSpeed(myList[6].toString(), body.toString());
|
||||
var coords = myList[0].split(',');
|
||||
var coordDestination = myList[1].split(',');
|
||||
|
||||
// Parse to double
|
||||
latPassengerLocation = double.parse(coords[0]);
|
||||
lngPassengerLocation = double.parse(coords[1]);
|
||||
latPassengerDestination = double.parse(coordDestination[0]);
|
||||
lngPassengerDestination = double.parse(coordDestination[1]);
|
||||
|
||||
pointsDirection = [
|
||||
LatLng(latPassengerLocation, lngPassengerLocation),
|
||||
LatLng(latPassengerDestination, lngPassengerDestination)
|
||||
]; // Calculate the midpoint between the two points
|
||||
// Calculate the minimum and maximum latitude and longitude values
|
||||
double minLatitude =
|
||||
math.min(pointsDirection[0].latitude, pointsDirection[1].latitude);
|
||||
double maxLatitude =
|
||||
math.max(pointsDirection[0].latitude, pointsDirection[1].latitude);
|
||||
double minLongitude =
|
||||
math.min(pointsDirection[0].longitude, pointsDirection[1].longitude);
|
||||
double maxLongitude =
|
||||
math.max(pointsDirection[0].longitude, pointsDirection[1].longitude);
|
||||
// Create a bounding box using the calculated values
|
||||
bounds = LatLngBounds(
|
||||
southwest: LatLng(minLatitude, minLongitude),
|
||||
northeast: LatLng(maxLatitude, maxLongitude),
|
||||
);
|
||||
update();
|
||||
}
|
||||
|
||||
getRideDEtailsForBackgroundOrder() async {
|
||||
await CRUD().get(link: AppLink.getRidesDetails, payload: {
|
||||
'id': box.read(BoxName.myList)[2].toString(),
|
||||
@@ -44,9 +104,10 @@ class OrderRequestController extends GetxController {
|
||||
|
||||
ImageConfiguration config = ImageConfiguration(
|
||||
size: const Size(30, 30), devicePixelRatio: Get.pixelRatio);
|
||||
BitmapDescriptor.fromAssetImage(config, 'assets/images/A.png',
|
||||
mipmaps: false)
|
||||
.then((value) {
|
||||
BitmapDescriptor.asset(
|
||||
config,
|
||||
'assets/images/A.png',
|
||||
).then((value) {
|
||||
startIcon = value;
|
||||
update();
|
||||
});
|
||||
@@ -55,9 +116,10 @@ class OrderRequestController extends GetxController {
|
||||
void addCustomEndIcon() {
|
||||
ImageConfiguration config = ImageConfiguration(
|
||||
size: const Size(30, 30), devicePixelRatio: Get.pixelRatio);
|
||||
BitmapDescriptor.fromAssetImage(config, 'assets/images/b.png',
|
||||
mipmaps: false)
|
||||
.then((value) {
|
||||
BitmapDescriptor.asset(
|
||||
config,
|
||||
'assets/images/b.png',
|
||||
).then((value) {
|
||||
endIcon = value;
|
||||
update();
|
||||
});
|
||||
@@ -74,46 +136,6 @@ class OrderRequestController extends GetxController {
|
||||
12; //todo in register car add mpg in box
|
||||
}
|
||||
|
||||
void getRefusedOrderByCaptain() async {
|
||||
// Get today's date in YYYY-MM-DD format
|
||||
String today = DateTime.now().toString().substring(0, 10);
|
||||
|
||||
String driverId = box.read(BoxName.driverID).toString();
|
||||
|
||||
String customQuery = '''
|
||||
SELECT COUNT(*) AS count
|
||||
FROM ${TableName.driverOrdersRefuse}
|
||||
WHERE driver_id = '$driverId'
|
||||
AND DATE(created_at) = '$today'
|
||||
''';
|
||||
|
||||
try {
|
||||
List<Map<String, dynamic>> results =
|
||||
await sql.getCustomQuery(customQuery);
|
||||
countRefuse = results[0]['count'].toString();
|
||||
print(countRefuse);
|
||||
update();
|
||||
if (int.parse(countRefuse) > 3) {
|
||||
box.write(BoxName.statusDriverLocation, 'on');
|
||||
locationController.stopLocationUpdates();
|
||||
Get.defaultDialog(
|
||||
// backgroundColor: CupertinoColors.destructiveRed,
|
||||
barrierDismissible: false,
|
||||
title: 'You Are Stopped For this Day !'.tr,
|
||||
content: Text(
|
||||
'You Refused 3 Rides this Day that is the reason \nSee you Tomorrow!'
|
||||
.tr,
|
||||
style: AppStyle.title,
|
||||
),
|
||||
confirm: MyElevatedButton(
|
||||
title: 'Ok , See you Tomorrow'.tr,
|
||||
onPressed: () => Get.back()));
|
||||
} else {
|
||||
box.write(BoxName.statusDriverLocation, 'off');
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
bool _timerActive = false;
|
||||
|
||||
Future<void> startTimer(String driverID, String orderID) async {
|
||||
|
||||
Reference in New Issue
Block a user