Update: 2026-06-30 23:32:14

This commit is contained in:
Hamza-Ayed
2026-06-30 23:32:15 +03:00
parent 808066f4a6
commit d2ce4bdb16
7 changed files with 277 additions and 17 deletions

View File

@@ -1,4 +1,5 @@
import 'package:geolocator/geolocator.dart';
import 'package:siro_rider/services/geofencing_service.dart';
class GeoLocation {
Future<Position> getCurrentLocation() async {
@@ -28,7 +29,16 @@ class GeoLocation {
}
// When we reach here, permissions are granted and we can fetch the location.
return await Geolocator.getCurrentPosition(
final position = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.high);
// Update Geofences based on the fresh location
try {
SiroGeofencingService.syncZonesWithServer(position.latitude, position.longitude);
} catch (e) {
// Ignore errors so it doesn't break the main location flow
}
return position;
}
}

View File

@@ -1,5 +1,8 @@
import 'dart:async';
import 'dart:io';
import 'package:http/http.dart' as http;
import 'package:geolocator/geolocator.dart';
import 'package:siro_rider/constant/links.dart';
import 'package:siro_rider/app_bindings.dart';
import 'package:siro_rider/controller/functions/crud.dart';
import 'package:siro_rider/views/home/HomePage/contact_us.dart';
@@ -36,6 +39,36 @@ DbSql sql = DbSql.instance;
Future<void> backgroundMessageHandler(RemoteMessage message) async {
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
Log.print("Handling a background message: ${message.messageId}");
if (message.data.isNotEmpty) {
try {
await GetStorage.init();
final storage = GetStorage();
final passengerId = storage.read('passenger_id') ?? '';
if (passengerId.toString().isEmpty) return;
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) return;
LocationPermission permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied || permission == LocationPermission.deniedForever) return;
final position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
final url = Uri.parse('${AppLink.server}/api/location/sync_location.php');
await http.post(url, body: {
'passenger_id': passengerId.toString(),
'lat': position.latitude.toString(),
'lng': position.longitude.toString(),
'source': 'silent_push',
});
// Update geofences on device silently
await SiroGeofencingService.syncZonesWithServer(position.latitude, position.longitude);
} catch (e) {
Log.print("Silent push location update failed: $e");
}
}
}
void main() {

View File

@@ -72,7 +72,7 @@ class SiroGeofencingService {
try {
for (var region in regions) {
final geofence = Geofence(
id: region['zone_name'],
id: region['id'].toString(),
location: Location(
latitude: double.parse(region['latitude'].toString()),
longitude: double.parse(region['longitude'].toString())),