This commit is contained in:
Hamza-Ayed
2025-08-06 01:10:52 +03:00
parent 57b7574657
commit 441385069c
49 changed files with 2577 additions and 1822 deletions

View File

@@ -1,54 +1,54 @@
import 'dart:async';
import 'package:background_location/background_location.dart';
import 'package:get/get.dart';
import 'package:permission_handler/permission_handler.dart';
// import 'dart:async';
// import 'package:background_location/background_location.dart';
// import 'package:get/get.dart';
// import 'package:permission_handler/permission_handler.dart';
class LocationBackgroundController extends GetxController {
@override
void onInit() {
super.onInit();
requestLocationPermission();
configureBackgroundLocation();
}
// class LocationBackgroundController extends GetxController {
// @override
// void onInit() {
// super.onInit();
// requestLocationPermission();
// configureBackgroundLocation();
// }
Future<void> requestLocationPermission() async {
var status = await Permission.locationAlways.status;
if (!status.isGranted) {
await Permission.locationAlways.request();
}
}
// Future<void> requestLocationPermission() async {
// var status = await Permission.locationAlways.status;
// if (!status.isGranted) {
// await Permission.locationAlways.request();
// }
// }
Future<void> configureBackgroundLocation() async {
await BackgroundLocation.setAndroidNotification(
title: 'Location Tracking Active'.tr,
message: 'Your location is being tracked in the background.'.tr,
icon: '@mipmap/launcher_icon',
);
// Future<void> configureBackgroundLocation() async {
// await BackgroundLocation.setAndroidNotification(
// title: 'Location Tracking Active'.tr,
// message: 'Your location is being tracked in the background.'.tr,
// icon: '@mipmap/launcher_icon',
// );
BackgroundLocation.setAndroidConfiguration(3000);
BackgroundLocation.startLocationService();
BackgroundLocation.getLocationUpdates((location) {
// Handle location updates here
});
}
// BackgroundLocation.setAndroidConfiguration(3000);
// BackgroundLocation.startLocationService();
// BackgroundLocation.getLocationUpdates((location) {
// // Handle location updates here
// });
// }
startBackLocation() async {
Timer.periodic(const Duration(seconds: 3), (timer) {
getBackgroundLocation();
});
}
// startBackLocation() async {
// Timer.periodic(const Duration(seconds: 3), (timer) {
// getBackgroundLocation();
// });
// }
getBackgroundLocation() async {
var status = await Permission.locationAlways.status;
if (status.isGranted) {
await BackgroundLocation.startLocationService(
distanceFilter: 20, forceAndroidLocationManager: true);
BackgroundLocation.setAndroidConfiguration(
Duration.microsecondsPerSecond); // Set interval to 5 seconds
// getBackgroundLocation() async {
// var status = await Permission.locationAlways.status;
// if (status.isGranted) {
// await BackgroundLocation.startLocationService(
// distanceFilter: 20, forceAndroidLocationManager: true);
// BackgroundLocation.setAndroidConfiguration(
// Duration.microsecondsPerSecond); // Set interval to 5 seconds
BackgroundLocation.getLocationUpdates((location1) {});
} else {
await Permission.locationAlways.request();
}
}
}
// BackgroundLocation.getLocationUpdates((location1) {});
// } else {
// await Permission.locationAlways.request();
// }
// }
// }