5/11/6
This commit is contained in:
@@ -5,28 +5,26 @@ import 'package:background_location/background_location.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
import '../../constant/box_name.dart';
|
||||
import '../../main.dart';
|
||||
|
||||
class LocationBackgroundController extends GetxController {
|
||||
@override
|
||||
Future<void> onInit() async {
|
||||
super.onInit();
|
||||
await requestLocationPermission();
|
||||
// await requestLocationPermission();
|
||||
await configureBackgroundLocation();
|
||||
}
|
||||
|
||||
Future<void> requestLocationPermission() async {
|
||||
var status = await Permission.locationAlways.status;
|
||||
if (!status.isGranted) {
|
||||
Get.defaultDialog(
|
||||
title: 'Grant Location'.tr,
|
||||
middleText:
|
||||
'We use location to get accurate and nearest passengers for you'
|
||||
.tr,
|
||||
confirm: MyElevatedButton(
|
||||
kolor: AppColor.greenColor,
|
||||
title: 'Grant Location'.tr,
|
||||
onPressed: () async {
|
||||
await Permission.locationAlways.request();
|
||||
}));
|
||||
print(status);
|
||||
if (status.isDenied) {
|
||||
await Permission.locationAlways.request();
|
||||
if (status.isGranted) {
|
||||
box.write(BoxName.locationPermission, 'true');
|
||||
update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,11 +35,11 @@ class LocationBackgroundController extends GetxController {
|
||||
icon: "@mipmap/ic_launcher",
|
||||
);
|
||||
|
||||
BackgroundLocation.setAndroidConfiguration(1000);
|
||||
BackgroundLocation.setAndroidConfiguration(500);
|
||||
BackgroundLocation.startLocationService();
|
||||
BackgroundLocation.getLocationUpdates((location) {
|
||||
// Handle location updates here
|
||||
print("New location: ${location.latitude}, ${location.longitude}");
|
||||
print("Background location: ${location.latitude}, ${location.longitude}");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user