7/22/1 location background
This commit is contained in:
@@ -8,13 +8,19 @@ class LocationBackgroundController extends GetxController {
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
requestLocationPermission();
|
||||
configureBackgroundLocation();
|
||||
}
|
||||
|
||||
Future<void> requestLocationPermission() async {
|
||||
var status = await Permission.locationAlways.status;
|
||||
if (!status.isGranted) {
|
||||
await Permission.locationAlways.request();
|
||||
status = await Permission.locationAlways.request();
|
||||
}
|
||||
|
||||
if (status.isGranted) {
|
||||
configureBackgroundLocation();
|
||||
} else {
|
||||
// Handle permission denial
|
||||
print("Location permission denied");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,29 +31,36 @@ class LocationBackgroundController extends GetxController {
|
||||
icon: "@mipmap/ic_launcher",
|
||||
);
|
||||
|
||||
BackgroundLocation.setAndroidConfiguration(1000);
|
||||
// Set the location update interval to 5 seconds
|
||||
BackgroundLocation.setAndroidConfiguration(5000);
|
||||
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();
|
||||
});
|
||||
}
|
||||
|
||||
startBackLocation() async {
|
||||
Timer.periodic(const Duration(seconds: 5), (timer) {
|
||||
getBackgroundLocation();
|
||||
});
|
||||
}
|
||||
|
||||
getBackgroundLocation() async {
|
||||
Future<void> 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) {});
|
||||
// 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}");
|
||||
});
|
||||
} else {
|
||||
// Request permission if not granted
|
||||
await Permission.locationAlways.request();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ class SplashScreen extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Get.put(LocationBackgroundController());
|
||||
// Get.put(LocationBackgroundController());
|
||||
return Scaffold(
|
||||
backgroundColor:
|
||||
AppColor.secondaryColor, // Set your desired background color
|
||||
|
||||
@@ -161,24 +161,24 @@ GetBuilder<HomeCaptainController> leftMainMenuCaptainIcons() {
|
||||
),
|
||||
),
|
||||
),
|
||||
AnimatedContainer(
|
||||
duration: const Duration(microseconds: 200),
|
||||
width: controller.widthMapTypeAndTraffic,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.secondaryColor,
|
||||
border: Border.all(color: AppColor.blueColor),
|
||||
borderRadius: BorderRadius.circular(15)),
|
||||
child: IconButton(
|
||||
onPressed: () async {
|
||||
Get.to(() => EgyptCardAI());
|
||||
},
|
||||
icon: const Icon(
|
||||
FontAwesome5.grin_tears,
|
||||
size: 29,
|
||||
color: AppColor.blueColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
// AnimatedContainer(
|
||||
// duration: const Duration(microseconds: 200),
|
||||
// width: controller.widthMapTypeAndTraffic,
|
||||
// decoration: BoxDecoration(
|
||||
// color: AppColor.secondaryColor,
|
||||
// border: Border.all(color: AppColor.blueColor),
|
||||
// borderRadius: BorderRadius.circular(15)),
|
||||
// child: IconButton(
|
||||
// onPressed: () async {
|
||||
// Get.to(() => EgyptCardAI());
|
||||
// },
|
||||
// icon: const Icon(
|
||||
// FontAwesome5.grin_tears,
|
||||
// size: 29,
|
||||
// color: AppColor.blueColor,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
],
|
||||
)),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user