This commit is contained in:
Hamza-Ayed
2024-05-21 16:46:49 +03:00
parent 908b5979a8
commit 5fb6a706c8
17 changed files with 193 additions and 191 deletions

View File

@@ -6,6 +6,7 @@ import 'package:SEFER/constant/style.dart';
import 'package:SEFER/controller/functions/crud.dart';
import 'package:SEFER/controller/functions/device_info.dart';
import 'package:SEFER/main.dart';
import 'package:SEFER/views/home/Captin/home_captain/home_captin.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:image_cropper/image_cropper.dart';
@@ -194,12 +195,12 @@ class AI extends GetxController {
);
} else {
await addDriverEgypt();
await addRegistrationCarEgypt();
// await addRegistrationCarEgypt();
if (isCarSaved && isDriverSaved) {
DeviceController().getDeviceSerialNumber();
box.write(BoxName.phoneVerified, '1');
Get.offAll(() => const MyApp());
Get.offAll(() => HomeCaptain());
// Get.offAll(() => HomeCaptain());
}
}
@@ -208,6 +209,18 @@ class AI extends GetxController {
Future<void> addDriverEgypt() async {
try {
print(box.read(BoxName.driverID).toString());
print(box.read(BoxName.phoneDriver)?.toString() ?? '');
print(responseIdEgyptBack['gender']);
print(responseIdEgyptDriverLicense['license_type']);
print(responseIdEgyptBack['nationalID']);
print(responseIdEgyptDriverLicense['issue_date']);
print(responseIdEgyptDriverLicense['expiry_date']);
print(responseIdEgyptDriverLicense['license_categories']);
print(responseIdEgyptFront['card_id']);
print(responseIdEgyptDriverLicense['issue_date']);
print(responseIdEgyptFront['dob'] != null
? responseIdEgyptFront['dob'] + '-01-01'.toString()
: '');
// Extract values from box or set defaults
var firstName = responseIdEgyptDriverLicense['firstName'] ?? '';
@@ -229,12 +242,14 @@ class AI extends GetxController {
var cardId = responseIdEgyptFront['card_id'] ?? '';
var occupation = responseIdEgyptBack['occupation'] ?? '';
var education = responseIdEgyptBack['occupation'] ?? '';
var licenseIssueDate = responseIdEgyptDriverLicense['issue_date'] ?? '';
var licenseIssueDate =
responseIdEgyptDriverLicense['issue_date'].toString() ?? '';
var religion = responseIdEgyptBack['religion'] ?? '';
var status = responseIdEgyptBack['fullName'] ?? '';
var birthdate = responseIdEgyptFront['dob'] != null
? responseIdEgyptFront['dob'] + '-01-01'
? DateTime.parse(responseIdEgyptFront['dob'] + '-01-01').toString()
: '';
var maritalStatus = responseIdEgyptBack['maritalStatus'] ?? '';
var site = responseIdEgyptDriverLicense['address'] ?? '';
var employmentType = responseIdEgyptDriverLicense['employmentType'] ?? '';
@@ -245,7 +260,7 @@ class AI extends GetxController {
'last_name': lastName,
'email': email,
'phone': phone,
'driverId': driverId,
'id': driverId,
'password': password,
'gender': gender,
'license_type': licenseType,
@@ -267,6 +282,7 @@ class AI extends GetxController {
'site': site,
'employmentType': employmentType,
};
print(payload);
isLoading = true;
update();
// Make POST request

View File

@@ -1,72 +1,28 @@
import 'dart:async';
import 'package:SEFER/constant/box_name.dart';
import 'package:SEFER/controller/auth/captin/login_captin_controller.dart';
import 'package:background_location/background_location.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:permission_handler/permission_handler.dart';
import '../../main.dart';
class LocationBackgroundController extends GetxController {
@override
Future<void> onInit() async {
void onInit() {
super.onInit();
await requestLocationPermission();
await configureBackgroundLocation();
requestLocationPermission();
configureBackgroundLocation();
}
Future<void> requestLocationPermission() async {
var status = await Permission.locationAlways.status;
print('Initial status: $status');
if (status == PermissionStatus.denied ||
status == PermissionStatus.restricted) {
// Show dialog to inform the driver about background GPS location usage
await Get.dialog(
AlertDialog(
title: Text('Location Permission'.tr),
content: Text(
'We use GPS location in the background to enable you to receive orders.'
.tr),
actions: [
TextButton(
onPressed: () async {
Get.back(); // Close the dialog
// Request permission
status = await Permission.locationAlways.request();
print('Requested status: $status');
_handlePermissionStatus(status);
},
child: Text('OK'),
),
],
),
);
} else {
_handlePermissionStatus(status);
}
}
void _handlePermissionStatus(PermissionStatus status) async {
status = await Permission.locationAlways.status;
if (!status.isGranted) {
// Open app settings if permission is permanently denied
openAppSettings();
box.write(BoxName.locationPermission, 'true');
Get.find<LoginCaptinController>().update();
} else if (status.isGranted) {
// Permission granted
box.write(BoxName.locationPermission, 'true');
Get.find<LoginCaptinController>().update();
await Permission.locationAlways.request();
}
}
Future<void> configureBackgroundLocation() async {
await BackgroundLocation.setAndroidNotification(
title: "Sefer Driver ",
title: "Background Location",
message: "Tracking location...",
icon: "app_icon",
icon: "@mipmap/ic_launcher",
);
BackgroundLocation.setAndroidConfiguration(1000);

View File

@@ -10,8 +10,6 @@ import 'package:SEFER/controller/functions/crud.dart';
import 'package:SEFER/controller/home/payment/captain_wallet_controller.dart';
import 'package:SEFER/main.dart';
import '../home/captin/map_driver_controller.dart';
// LocationController.dart
class LocationController extends GetxController {
LocationData? _currentLocation;
@@ -41,6 +39,7 @@ class LocationController extends GetxController {
// startLocationUpdates();
totalPoints = Get.put(CaptainWalletController()).totalPoints;
// isActive = Get.put(HomeCaptainController()).isActive;
}
Future<void> startLocationUpdates() async {
@@ -49,37 +48,39 @@ class LocationController extends GetxController {
Timer.periodic(const Duration(seconds: 5), (timer) async {
try {
totalPoints = Get.find<CaptainWalletController>().totalPoints;
isActive = Get.find<HomeCaptainController>().isActive;
print('isActive $isActive');
print(totalPoints);
if (isActive) {
if (double.parse(totalPoints) > -300) {
print('total point is $totalPoints');
// if (isActive) {
if (double.parse(totalPoints) > -300) {
print('total point is $totalPoints');
await getLocation();
await getLocation();
// if (box.read(BoxName.driverID) != null) {
await CRUD()
.post(link: AppLink.addCarsLocationByPassenger, payload: {
'driver_id': box.read(BoxName.driverID).toString(),
'latitude': myLocation.latitude.toString(),
'longitude': myLocation.longitude.toString(),
'heading': heading.toString(),
'speed': (speed * 3.6).toStringAsFixed(1),
'distance': totalDistance == 0
? '0'
: totalDistance < 1
? totalDistance.toStringAsFixed(3)
: totalDistance.toStringAsFixed(1),
'status': box.read(BoxName.statusDriverLocation).toString()
});
// Animate camera to user location (optional)
// if (Get.find<HomeCaptainController>().rideId == 'rideId') {
// Get.find<MapDriverController>()
// .mapController!
// .animateCamera(CameraUpdate.newLatLng(LatLng(
// Get.find<LocationController>().myLocation.latitude,
// Get.find<LocationController>().myLocation.longitude,
// )));
// }
// if (box.read(BoxName.driverID) != null) {
await CRUD()
.post(link: AppLink.addCarsLocationByPassenger, payload: {
'driver_id': box.read(BoxName.driverID).toString(),
'latitude': myLocation.latitude.toString(),
'longitude': myLocation.longitude.toString(),
'heading': heading.toString(),
'speed': (speed * 3.6).toStringAsFixed(1),
'distance': totalDistance == 0
? '0'
: totalDistance < 1
? totalDistance.toStringAsFixed(3)
: totalDistance.toStringAsFixed(1),
'status': box.read(BoxName.statusDriverLocation).toString()
});
// Animate camera to user location (optional)
// if (Get.find<HomeCaptainController>().rideId == 'rideId') {
// Get.find<MapDriverController>()
// .mapController!
// .animateCamera(CameraUpdate.newLatLng(LatLng(
// Get.find<LocationController>().myLocation.latitude,
// Get.find<LocationController>().myLocation.longitude,
// )));
}
Get.find<HomeCaptainController>()
.mapHomeCaptainController!
.animateCamera(CameraUpdate.newLatLng(LatLng(