5/19/1
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import 'dart:async';
|
||||
import 'package:SEFER/constant/box_name.dart';
|
||||
import 'package:SEFER/constant/colors.dart';
|
||||
import 'package:SEFER/controller/auth/captin/login_captin_controller.dart';
|
||||
import 'package:SEFER/views/widgets/elevated_btn.dart';
|
||||
import 'package:background_location/background_location.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
@@ -13,7 +12,7 @@ class LocationBackgroundController extends GetxController {
|
||||
@override
|
||||
Future<void> onInit() async {
|
||||
super.onInit();
|
||||
// await requestLocationPermission();
|
||||
await requestLocationPermission();
|
||||
await configureBackgroundLocation();
|
||||
}
|
||||
|
||||
@@ -23,10 +22,33 @@ class LocationBackgroundController extends GetxController {
|
||||
|
||||
if (status == PermissionStatus.denied ||
|
||||
status == PermissionStatus.restricted) {
|
||||
// Request permission
|
||||
status = await Permission.locationAlways.request();
|
||||
print('Requested status: $status');
|
||||
// Show dialog to inform the driver about background GPS location usage
|
||||
await Get.dialog(
|
||||
AlertDialog(
|
||||
title: Text('Location Permission'.tr),
|
||||
content: Text(
|
||||
'We use GPS location in the background to enable you to receive orders.'
|
||||
.tr),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
Get.back(); // Close the dialog
|
||||
// Request permission
|
||||
status = await Permission.locationAlways.request();
|
||||
print('Requested status: $status');
|
||||
_handlePermissionStatus(status);
|
||||
},
|
||||
child: Text('OK'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
_handlePermissionStatus(status);
|
||||
}
|
||||
}
|
||||
|
||||
void _handlePermissionStatus(PermissionStatus status) async {
|
||||
status = await Permission.locationAlways.status;
|
||||
if (!status.isGranted) {
|
||||
// Open app settings if permission is permanently denied
|
||||
|
||||
Reference in New Issue
Block a user