9/24/1-backLocation
This commit is contained in:
@@ -355,12 +355,12 @@ class AI extends GetxController {
|
||||
|
||||
if (status1['status'] == 'success') {
|
||||
isDriverSaved = true;
|
||||
// CRUD().post(
|
||||
// link: '${AppLink.seferGizaServer}/auth/captin/register.php',
|
||||
// payload: payload);
|
||||
// CRUD().post(
|
||||
// link: '${AppLink.seferAlexandriaServer}/auth/captin/register.php',
|
||||
// payload: payload);
|
||||
CRUD().post(
|
||||
link: '${AppLink.seferGizaServer}/auth/captin/register.php',
|
||||
payload: payload);
|
||||
CRUD().post(
|
||||
link: '${AppLink.seferAlexandriaServer}/auth/captin/register.php',
|
||||
payload: payload);
|
||||
Get.snackbar('Success', 'Driver data saved successfully',
|
||||
backgroundColor: AppColor.greenColor);
|
||||
} else {
|
||||
@@ -416,55 +416,55 @@ class AI extends GetxController {
|
||||
isCarSaved = true;
|
||||
Get.snackbar('Success', 'message',
|
||||
backgroundColor: AppColor.greenColor);
|
||||
// CRUD().post(
|
||||
// link:
|
||||
// '${AppLink.seferAlexandriaServer}/ride/RegisrationCar/add.php',
|
||||
// payload: {
|
||||
// 'driverID': box.read(BoxName.driverID),
|
||||
// 'vin': responseIdCardDriverEgyptBack['chassis'].toString(),
|
||||
// 'car_plate':
|
||||
// responseIdCardDriverEgyptFront['car_plate'].toString(),
|
||||
// 'make': responseIdCardDriverEgyptBack['make'].toString(),
|
||||
// 'model': responseIdCardDriverEgyptBack['model'],
|
||||
// 'year': responseIdCardDriverEgyptBack['year'].toString(),
|
||||
// 'expiration_date':
|
||||
// responseIdCardDriverEgyptFront['LicenseExpirationDate']
|
||||
// .toString(),
|
||||
// 'color': responseIdCardDriverEgyptBack['color'],
|
||||
// 'owner': responseIdCardDriverEgyptFront['owner'],
|
||||
// 'color_hex':
|
||||
// responseIdCardDriverEgyptBack['color_hex'].toString(),
|
||||
// 'address': responseIdCardDriverEgyptFront['address'].toString(),
|
||||
// 'displacement':
|
||||
// responseIdCardDriverEgyptBack['engine'].toString(),
|
||||
// 'fuel': responseIdCardDriverEgyptBack['fuel'].toString(),
|
||||
// 'registration_date':
|
||||
// '${responseIdCardDriverEgyptBack['inspection_date']}',
|
||||
// });
|
||||
// CRUD().post(
|
||||
// link: '${AppLink.seferGizaServer}/ride/RegisrationCar/add.php',
|
||||
// payload: {
|
||||
// 'driverID': box.read(BoxName.driverID),
|
||||
// 'vin': responseIdCardDriverEgyptBack['chassis'].toString(),
|
||||
// 'car_plate':
|
||||
// responseIdCardDriverEgyptFront['car_plate'].toString(),
|
||||
// 'make': responseIdCardDriverEgyptBack['make'].toString(),
|
||||
// 'model': responseIdCardDriverEgyptBack['model'],
|
||||
// 'year': responseIdCardDriverEgyptBack['year'].toString(),
|
||||
// 'expiration_date':
|
||||
// responseIdCardDriverEgyptFront['LicenseExpirationDate']
|
||||
// .toString(),
|
||||
// 'color': responseIdCardDriverEgyptBack['color'],
|
||||
// 'owner': responseIdCardDriverEgyptFront['owner'],
|
||||
// 'color_hex':
|
||||
// responseIdCardDriverEgyptBack['color_hex'].toString(),
|
||||
// 'address': responseIdCardDriverEgyptFront['address'].toString(),
|
||||
// 'displacement':
|
||||
// responseIdCardDriverEgyptBack['engine'].toString(),
|
||||
// 'fuel': responseIdCardDriverEgyptBack['fuel'].toString(),
|
||||
// 'registration_date':
|
||||
// '${responseIdCardDriverEgyptBack['inspection_date']}',
|
||||
// });
|
||||
CRUD().post(
|
||||
link:
|
||||
'${AppLink.seferAlexandriaServer}/ride/RegisrationCar/add.php',
|
||||
payload: {
|
||||
'driverID': box.read(BoxName.driverID),
|
||||
'vin': responseIdCardDriverEgyptBack['chassis'].toString(),
|
||||
'car_plate':
|
||||
responseIdCardDriverEgyptFront['car_plate'].toString(),
|
||||
'make': responseIdCardDriverEgyptBack['make'].toString(),
|
||||
'model': responseIdCardDriverEgyptBack['model'],
|
||||
'year': responseIdCardDriverEgyptBack['year'].toString(),
|
||||
'expiration_date':
|
||||
responseIdCardDriverEgyptFront['LicenseExpirationDate']
|
||||
.toString(),
|
||||
'color': responseIdCardDriverEgyptBack['color'],
|
||||
'owner': responseIdCardDriverEgyptFront['owner'],
|
||||
'color_hex':
|
||||
responseIdCardDriverEgyptBack['color_hex'].toString(),
|
||||
'address': responseIdCardDriverEgyptFront['address'].toString(),
|
||||
'displacement':
|
||||
responseIdCardDriverEgyptBack['engine'].toString(),
|
||||
'fuel': responseIdCardDriverEgyptBack['fuel'].toString(),
|
||||
'registration_date':
|
||||
'${responseIdCardDriverEgyptBack['inspection_date']}',
|
||||
});
|
||||
CRUD().post(
|
||||
link: '${AppLink.seferGizaServer}/ride/RegisrationCar/add.php',
|
||||
payload: {
|
||||
'driverID': box.read(BoxName.driverID),
|
||||
'vin': responseIdCardDriverEgyptBack['chassis'].toString(),
|
||||
'car_plate':
|
||||
responseIdCardDriverEgyptFront['car_plate'].toString(),
|
||||
'make': responseIdCardDriverEgyptBack['make'].toString(),
|
||||
'model': responseIdCardDriverEgyptBack['model'],
|
||||
'year': responseIdCardDriverEgyptBack['year'].toString(),
|
||||
'expiration_date':
|
||||
responseIdCardDriverEgyptFront['LicenseExpirationDate']
|
||||
.toString(),
|
||||
'color': responseIdCardDriverEgyptBack['color'],
|
||||
'owner': responseIdCardDriverEgyptFront['owner'],
|
||||
'color_hex':
|
||||
responseIdCardDriverEgyptBack['color_hex'].toString(),
|
||||
'address': responseIdCardDriverEgyptFront['address'].toString(),
|
||||
'displacement':
|
||||
responseIdCardDriverEgyptBack['engine'].toString(),
|
||||
'fuel': responseIdCardDriverEgyptBack['fuel'].toString(),
|
||||
'registration_date':
|
||||
'${responseIdCardDriverEgyptBack['inspection_date']}',
|
||||
});
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
@@ -8,19 +8,13 @@ class LocationBackgroundController extends GetxController {
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
requestLocationPermission();
|
||||
configureBackgroundLocation();
|
||||
}
|
||||
|
||||
Future<void> requestLocationPermission() async {
|
||||
var status = await Permission.locationAlways.status;
|
||||
if (!status.isGranted) {
|
||||
status = await Permission.locationAlways.request();
|
||||
}
|
||||
|
||||
if (status.isGranted) {
|
||||
configureBackgroundLocation();
|
||||
} else {
|
||||
// Handle permission denial
|
||||
print("Location permission denied");
|
||||
await Permission.locationAlways.request();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,36 +25,29 @@ class LocationBackgroundController extends GetxController {
|
||||
icon: '@mipmap/launcher_icon',
|
||||
);
|
||||
|
||||
// Set the location update interval to 5 seconds
|
||||
BackgroundLocation.setAndroidConfiguration(5000);
|
||||
BackgroundLocation.setAndroidConfiguration(3000);
|
||||
BackgroundLocation.startLocationService();
|
||||
|
||||
BackgroundLocation.getLocationUpdates((location) {
|
||||
// Handle location updates here
|
||||
print("Latitude: ${location.latitude}, Longitude: ${location.longitude}");
|
||||
});
|
||||
|
||||
startBackLocation();
|
||||
}
|
||||
|
||||
void startBackLocation() async {
|
||||
Timer.periodic(const Duration(seconds: 5), (timer) async {
|
||||
await getBackgroundLocation();
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> getBackgroundLocation() async {
|
||||
startBackLocation() async {
|
||||
Timer.periodic(const Duration(seconds: 3), (timer) {
|
||||
getBackgroundLocation();
|
||||
});
|
||||
}
|
||||
|
||||
getBackgroundLocation() async {
|
||||
var status = await Permission.locationAlways.status;
|
||||
if (status.isGranted) {
|
||||
// The location service is already started in configureBackgroundLocation
|
||||
// No need to call startLocationService again
|
||||
BackgroundLocation.getLocationUpdates((location) {
|
||||
// Handle location updates here
|
||||
print(
|
||||
"Latitude: ${location.latitude}, Longitude: ${location.longitude}");
|
||||
});
|
||||
await BackgroundLocation.startLocationService(
|
||||
distanceFilter: 20, forceAndroidLocationManager: true);
|
||||
BackgroundLocation.setAndroidConfiguration(
|
||||
Duration.microsecondsPerSecond); // Set interval to 5 seconds
|
||||
|
||||
BackgroundLocation.getLocationUpdates((location1) {});
|
||||
} else {
|
||||
// Request permission if not granted
|
||||
await Permission.locationAlways.request();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class LocationController extends GetxController {
|
||||
} else if (latitude >= 29.904975 &&
|
||||
latitude <= 30.143372 &&
|
||||
longitude >= 30.787030 &&
|
||||
longitude <= 31.238843) {
|
||||
longitude <= 31.215009) {
|
||||
return 'Giza';
|
||||
} else if (latitude >= 30.396286 &&
|
||||
latitude <= 31.654458 &&
|
||||
@@ -61,7 +61,7 @@ class LocationController extends GetxController {
|
||||
longitude <= 32.626259) {
|
||||
return 'Alexandria';
|
||||
} else {
|
||||
return 'Outside';
|
||||
return 'Cairo';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,15 +102,7 @@ class LocationController extends GetxController {
|
||||
endpoint = AppLink.addCarsLocationAlexandriaEndpoint;
|
||||
Log.print('Endpoint: $endpoint');
|
||||
break;
|
||||
case 'Outside':
|
||||
// Handle cases outside of Cairo, Giza, and Alexandria
|
||||
print('Location outside Cairo, Giza, or Alexandria');
|
||||
|
||||
box.write(BoxName.serverChosen, AppLink.seferCairoServer);
|
||||
endpoint = AppLink
|
||||
.addCarsLocationCairoEndpoint; // Fallback to Cairo endpoint
|
||||
Log.print('Fallback Endpoint: $endpoint');
|
||||
break;
|
||||
default:
|
||||
// Handle any other unexpected cases
|
||||
print('Unknown location area');
|
||||
|
||||
@@ -1,16 +1,60 @@
|
||||
import 'package:location/location.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
import '../../constant/box_name.dart';
|
||||
import '../../main.dart';
|
||||
import '../../print.dart';
|
||||
import '../../views/widgets/mydialoug.dart';
|
||||
import '../auth/captin/login_captin_controller.dart';
|
||||
|
||||
class LocationPermissions {
|
||||
late Location location;
|
||||
// late Location location;
|
||||
|
||||
Future locationPermissions() async {
|
||||
location = Location();
|
||||
var permissionStatus = await location.requestPermission();
|
||||
if (permissionStatus == PermissionStatus.denied) {
|
||||
// The user denied the location permission.
|
||||
Get.defaultDialog(title: 'GPS Required Allow !.'.tr, middleText: '');
|
||||
return null;
|
||||
}
|
||||
// Future locationPermissions() async {
|
||||
// location = Location();
|
||||
// var permissionStatus = await location.requestPermission();
|
||||
// if (permissionStatus == PermissionStatus.denied) {
|
||||
// // The user denied the location permission.
|
||||
// Get.defaultDialog(title: 'GPS Required Allow !.'.tr, middleText: '');
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
Future<void> getPermissionLocation() async {
|
||||
final PermissionStatus status = await Permission.locationAlways.status;
|
||||
if (!await Permission.locationAlways.serviceStatus.isEnabled) {
|
||||
Log.print('status.isGranted: ${status.isGranted}');
|
||||
// box.write(BoxName.locationPermission, 'true');
|
||||
await Permission.locationAlways.request();
|
||||
Get.put(LoginDriverController()).update();
|
||||
MyDialog().getDialog(
|
||||
'Enable Location Permission'.tr, // {en:ar}
|
||||
'Allowing location access will help us display orders near you. Please enable it now.'
|
||||
.tr, // {en:ar}
|
||||
() async {
|
||||
Get.back();
|
||||
box.write(BoxName.locationPermission, 'true');
|
||||
await Permission.locationAlways.request();
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> getPermissionLocation1() async {
|
||||
PermissionStatus status = await Permission.locationWhenInUse.request();
|
||||
|
||||
if (status.isGranted) {
|
||||
// After granting when in use, request "always" location permission
|
||||
status = await Permission.locationAlways.request();
|
||||
|
||||
if (status.isGranted) {
|
||||
print("Background location permission granted");
|
||||
} else {
|
||||
print("Background location permission denied");
|
||||
}
|
||||
} else {
|
||||
print("Location permission denied");
|
||||
await openAppSettings();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,12 @@ import 'dart:io';
|
||||
import 'package:SEFER/views/widgets/mydialoug.dart';
|
||||
import 'package:flutter_overlay_window/flutter_overlay_window.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:location/location.dart';
|
||||
// import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
import '../../constant/box_name.dart';
|
||||
import '../../main.dart';
|
||||
import '../../print.dart';
|
||||
import '../auth/captin/login_captin_controller.dart';
|
||||
|
||||
Future<void> getPermissionOverlay() async {
|
||||
@@ -26,24 +28,55 @@ Future<void> getPermissionOverlay() async {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> getPermissionLocation() async {
|
||||
final PermissionStatus status = await Permission.location.status;
|
||||
if (!status.isGranted) {
|
||||
// Log.print('status.isGranted: ${status.isGranted}');
|
||||
box.write(BoxName.locationPermission, 'true');
|
||||
await Permission.location.request();
|
||||
Get.find<LoginDriverController>().update();
|
||||
// MyDialog().getDialog(
|
||||
// 'Enable Location Permission'.tr, // {en:ar}
|
||||
// 'Allowing location access will help us display orders near you. Please enable it now.'
|
||||
// .tr, // {en:ar}
|
||||
// () async {
|
||||
// Get.back();
|
||||
// box.write(BoxName.locationPermission, 'true');
|
||||
// await Permission.location.request();
|
||||
// },
|
||||
// );
|
||||
// Future<void> getPermissionLocation() async {
|
||||
// // final PermissionStatus status = await Permission.location.status;
|
||||
// // if (!status.isGranted) {
|
||||
// // Log.print('status.isGranted: ${status.isGranted}');
|
||||
// // // box.write(BoxName.locationPermission, 'true');
|
||||
// // await Permission.location.request();
|
||||
// // Get.find<LoginDriverController>().update();
|
||||
// // MyDialog().getDialog(
|
||||
// // 'Enable Location Permission'.tr, // {en:ar}
|
||||
// // 'Allowing location access will help us display orders near you. Please enable it now.'
|
||||
// // .tr, // {en:ar}
|
||||
// // () async {
|
||||
// // Get.back();
|
||||
// // box.write(BoxName.locationPermission, 'true');
|
||||
// // await Permission.location.request();
|
||||
// // },
|
||||
// // );
|
||||
// // }
|
||||
// }
|
||||
final location = Location();
|
||||
Future<void> getLocationPermission() async {
|
||||
bool serviceEnabled;
|
||||
PermissionStatus permissionGranted;
|
||||
|
||||
// Check if location services are enabled
|
||||
serviceEnabled = await location.serviceEnabled();
|
||||
if (!serviceEnabled) {
|
||||
serviceEnabled = await location.requestService();
|
||||
if (!serviceEnabled) {
|
||||
// Location services are still not enabled, handle the error
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the app has permission to access location
|
||||
permissionGranted = await location.hasPermission();
|
||||
if (permissionGranted == PermissionStatus.denied) {
|
||||
permissionGranted = await location.requestPermission();
|
||||
if (permissionGranted != PermissionStatus.granted) {
|
||||
// Location permission is still not granted, handle the error
|
||||
permissionGranted = await location.requestPermission();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (permissionGranted.toString() == 'PermissionStatus.granted') {
|
||||
box.write(BoxName.locationPermission, 'true');
|
||||
Get.find<LoginDriverController>().update();
|
||||
}
|
||||
// update();
|
||||
}
|
||||
|
||||
Future<void> getOverLay(String myListString) async {
|
||||
|
||||
Reference in New Issue
Block a user