5/11/6
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:SEFER/controller/functions/location_background_controller.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -39,34 +40,8 @@ class LoginCaptinController extends GetxController {
|
||||
}
|
||||
|
||||
Future<void> getLocationPermission() async {
|
||||
bool serviceEnabled;
|
||||
PermissionStatus permissionGranted;
|
||||
Get.put(LocationBackgroundController()).requestLocationPermission();
|
||||
|
||||
// Check if location services are enabled
|
||||
serviceEnabled = await location.serviceEnabled();
|
||||
if (!serviceEnabled) {
|
||||
serviceEnabled = await location.requestService();
|
||||
if (!serviceEnabled) {
|
||||
// Location services are still not enabled, handle the error
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the app has permission to access location
|
||||
permissionGranted = await location.hasPermission();
|
||||
if (permissionGranted == PermissionStatus.denied) {
|
||||
permissionGranted = await location.requestPermission();
|
||||
if (permissionGranted != PermissionStatus.granted) {
|
||||
// Location permission is still not granted, handle the error
|
||||
permissionGranted = await location.requestPermission();
|
||||
return;
|
||||
}
|
||||
}
|
||||
print('permisson is ${permissionGranted.toString()}');
|
||||
if ('PermissionStatus.granted' == permissionGranted.toString()) {
|
||||
box.write(BoxName.locationPermission, 'true');
|
||||
update();
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
@@ -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}");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ class SplashScreenController extends GetxController
|
||||
}
|
||||
|
||||
void startTimer() {
|
||||
Timer(const Duration(seconds: 4), () {
|
||||
Timer(const Duration(seconds: 5), () {
|
||||
box.read(BoxName.onBoarding) == null
|
||||
? Get.off(() => OnBoardingPage())
|
||||
: box.read(BoxName.emailDriver) != null
|
||||
|
||||
Reference in New Issue
Block a user