Update: 2026-06-15 01:38:09
This commit is contained in:
@@ -21,7 +21,7 @@ import 'package:siro_rider/controller/functions/crud.dart';
|
|||||||
import 'package:siro_rider/main.dart';
|
import 'package:siro_rider/main.dart';
|
||||||
import 'package:siro_rider/views/home/map_page_passenger.dart';
|
import 'package:siro_rider/views/home/map_page_passenger.dart';
|
||||||
|
|
||||||
import 'package:location/location.dart';
|
import 'package:location/location.dart' as loc;
|
||||||
|
|
||||||
import '../../env/env.dart';
|
import '../../env/env.dart';
|
||||||
import '../../print.dart';
|
import '../../print.dart';
|
||||||
@@ -450,7 +450,7 @@ class LoginController extends GetxController {
|
|||||||
void loginTester() async {
|
void loginTester() async {
|
||||||
isloading = true;
|
isloading = true;
|
||||||
update();
|
update();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var fingerPrint = await DeviceHelper.getDeviceFingerprint();
|
var fingerPrint = await DeviceHelper.getDeviceFingerprint();
|
||||||
var payload = {
|
var payload = {
|
||||||
@@ -467,7 +467,8 @@ class LoginController extends GetxController {
|
|||||||
|
|
||||||
if (response.statusCode == 200 || response.statusCode == 201) {
|
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||||
var jsonDecoeded = jsonDecode(response.body);
|
var jsonDecoeded = jsonDecode(response.body);
|
||||||
if (jsonDecoeded['status'] == 'success' && jsonDecoeded['data'][0]['verified'].toString() == '1') {
|
if (jsonDecoeded['status'] == 'success' &&
|
||||||
|
jsonDecoeded['data'][0]['verified'].toString() == '1') {
|
||||||
var d = jsonDecoeded['data'][0];
|
var d = jsonDecoeded['data'][0];
|
||||||
var jwt = jsonDecoeded['jwt'];
|
var jwt = jsonDecoeded['jwt'];
|
||||||
|
|
||||||
@@ -510,12 +511,12 @@ class LoginController extends GetxController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final location = Location();
|
final location = loc.Location();
|
||||||
|
|
||||||
// late PermissionStatus permissionGranted = PermissionStatus.denied;
|
// late PermissionStatus permissionGranted = PermissionStatus.denied;
|
||||||
Future<void> getLocationPermission() async {
|
Future<void> getLocationPermission() async {
|
||||||
bool serviceEnabled;
|
bool serviceEnabled;
|
||||||
PermissionStatus permissionGranted;
|
loc.PermissionStatus permissionGranted;
|
||||||
|
|
||||||
// Check if location services are enabled
|
// Check if location services are enabled
|
||||||
serviceEnabled = await location.serviceEnabled();
|
serviceEnabled = await location.serviceEnabled();
|
||||||
@@ -529,15 +530,16 @@ class LoginController extends GetxController {
|
|||||||
|
|
||||||
// Check if the app has permission to access location
|
// Check if the app has permission to access location
|
||||||
permissionGranted = await location.hasPermission();
|
permissionGranted = await location.hasPermission();
|
||||||
if (permissionGranted == PermissionStatus.denied) {
|
if (permissionGranted == loc.PermissionStatus.denied) {
|
||||||
permissionGranted = await location.requestPermission();
|
permissionGranted = await location.requestPermission();
|
||||||
if (permissionGranted != PermissionStatus.granted) {
|
if (permissionGranted != loc.PermissionStatus.granted) {
|
||||||
// Location permission is still not granted, handle the error
|
// Location permission is still not granted, handle the error
|
||||||
permissionGranted = await location.requestPermission();
|
permissionGranted = await location.requestPermission();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (permissionGranted.toString() == 'PermissionStatus.granted') {
|
if (permissionGranted.toString() == 'PermissionStatus.granted' ||
|
||||||
|
permissionGranted == loc.PermissionStatus.granted) {
|
||||||
box.write(BoxName.locationPermission, 'true');
|
box.write(BoxName.locationPermission, 'true');
|
||||||
}
|
}
|
||||||
update();
|
update();
|
||||||
@@ -561,7 +563,8 @@ class LoginController extends GetxController {
|
|||||||
final DateTime lastUpload = DateTime.parse(lastUploadStr);
|
final DateTime lastUpload = DateTime.parse(lastUploadStr);
|
||||||
final Duration diff = DateTime.now().difference(lastUpload);
|
final Duration diff = DateTime.now().difference(lastUpload);
|
||||||
if (diff.inHours < 12) {
|
if (diff.inHours < 12) {
|
||||||
Log.print("sendPassengerLocation: Location uploaded recently (${diff.inHours}h ago). Skipping.");
|
Log.print(
|
||||||
|
"sendPassengerLocation: Location uploaded recently (${diff.inHours}h ago). Skipping.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -576,11 +579,13 @@ class LoginController extends GetxController {
|
|||||||
// التحقق من الصلاحيات والسكوت الممنهج لتفادي النوافذ المزعجة
|
// التحقق من الصلاحيات والسكوت الممنهج لتفادي النوافذ المزعجة
|
||||||
LocationPermission permission = await Geolocator.checkPermission();
|
LocationPermission permission = await Geolocator.checkPermission();
|
||||||
if (permission == LocationPermission.denied) {
|
if (permission == LocationPermission.denied) {
|
||||||
Log.print("sendPassengerLocation: Permission is denied. Skipping silently.");
|
Log.print(
|
||||||
|
"sendPassengerLocation: Permission is denied. Skipping silently.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (permission == LocationPermission.deniedForever) {
|
if (permission == LocationPermission.deniedForever) {
|
||||||
Log.print("sendPassengerLocation: Permission permanently denied. Skipping silently.");
|
Log.print(
|
||||||
|
"sendPassengerLocation: Permission permanently denied. Skipping silently.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -590,7 +595,8 @@ class LoginController extends GetxController {
|
|||||||
timeLimit: const Duration(seconds: 5),
|
timeLimit: const Duration(seconds: 5),
|
||||||
);
|
);
|
||||||
|
|
||||||
Log.print("sendPassengerLocation: Got location: ${position.latitude}, ${position.longitude}");
|
Log.print(
|
||||||
|
"sendPassengerLocation: Got location: ${position.latitude}, ${position.longitude}");
|
||||||
|
|
||||||
// إرسال البيانات إلى السيرفر
|
// إرسال البيانات إلى السيرفر
|
||||||
final response = await CRUD().post(
|
final response = await CRUD().post(
|
||||||
@@ -604,10 +610,12 @@ class LoginController extends GetxController {
|
|||||||
Log.print("sendPassengerLocation response: $response");
|
Log.print("sendPassengerLocation response: $response");
|
||||||
|
|
||||||
if (response != 'failure' && response != null) {
|
if (response != 'failure' && response != null) {
|
||||||
final decoded = response is Map ? response : jsonDecode(response.toString());
|
final decoded =
|
||||||
|
response is Map ? response : jsonDecode(response.toString());
|
||||||
if (decoded['status'] == 'success') {
|
if (decoded['status'] == 'success') {
|
||||||
box.write(cacheKey, DateTime.now().toIso8601String());
|
box.write(cacheKey, DateTime.now().toIso8601String());
|
||||||
Log.print("sendPassengerLocation: Location logged and cached successfully.");
|
Log.print(
|
||||||
|
"sendPassengerLocation: Location logged and cached successfully.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user