4/3/7
This commit is contained in:
@@ -1,67 +1,67 @@
|
||||
// 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();
|
||||
// }
|
||||
//
|
||||
// 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: "Background Location",
|
||||
// message: "Tracking location...",
|
||||
// icon: "@mipmap/ic_launcher",
|
||||
// );
|
||||
//
|
||||
// BackgroundLocation.setAndroidConfiguration(1000);
|
||||
// BackgroundLocation.startLocationService();
|
||||
// BackgroundLocation.getLocationUpdates((location) {
|
||||
// // Handle location updates here
|
||||
// print("New location: ${location.latitude}, ${location.longitude}");
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// startBackLocation() async {
|
||||
// Timer.periodic(const Duration(seconds: 5), (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
|
||||
//
|
||||
// BackgroundLocation.getLocationUpdates((location1) {
|
||||
// print('''\n
|
||||
// Latitude: ${location1.latitude.toString()}
|
||||
// Longitude: ${location1.longitude.toString()}
|
||||
// Altitude: ${location1.altitude.toString()}
|
||||
// Accuracy: ${location1.accuracy.toString()}
|
||||
// Bearing: ${location1.bearing.toString()}
|
||||
// Speed: ${location1.speed.toString()}
|
||||
//
|
||||
//
|
||||
// ''');
|
||||
// });
|
||||
// } else {
|
||||
// await Permission.locationAlways.request();
|
||||
// print('Location permission not granted');
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
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();
|
||||
}
|
||||
|
||||
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: "Background Location",
|
||||
message: "Tracking location...",
|
||||
icon: "@mipmap/ic_launcher",
|
||||
);
|
||||
|
||||
BackgroundLocation.setAndroidConfiguration(1000);
|
||||
BackgroundLocation.startLocationService();
|
||||
BackgroundLocation.getLocationUpdates((location) {
|
||||
// Handle location updates here
|
||||
print("New location: ${location.latitude}, ${location.longitude}");
|
||||
});
|
||||
}
|
||||
|
||||
startBackLocation() async {
|
||||
Timer.periodic(const Duration(seconds: 5), (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
|
||||
|
||||
BackgroundLocation.getLocationUpdates((location1) {
|
||||
print('''\n
|
||||
Latitude: ${location1.latitude.toString()}
|
||||
Longitude: ${location1.longitude.toString()}
|
||||
Altitude: ${location1.altitude.toString()}
|
||||
Accuracy: ${location1.accuracy.toString()}
|
||||
Bearing: ${location1.bearing.toString()}
|
||||
Speed: ${location1.speed.toString()}
|
||||
|
||||
|
||||
''');
|
||||
});
|
||||
} else {
|
||||
await Permission.locationAlways.request();
|
||||
print('Location permission not granted');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,10 +11,12 @@ import 'package:get_storage/get_storage.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:wakelock_plus/wakelock_plus.dart';
|
||||
import 'constant/api_key.dart';
|
||||
import 'constant/box_name.dart';
|
||||
import 'constant/credential.dart';
|
||||
import 'constant/info.dart';
|
||||
import 'controller/firebase/firbase_messge.dart';
|
||||
import 'controller/firebase/local_notification.dart';
|
||||
import 'controller/functions/location_background_controller.dart';
|
||||
import 'controller/functions/location_controller.dart';
|
||||
import 'controller/local/local_controller.dart';
|
||||
import 'controller/local/translations.dart';
|
||||
@@ -56,9 +58,9 @@ void main() async {
|
||||
|
||||
print(Get.deviceLocale!.countryCode);
|
||||
Stripe.publishableKey = AK.publishableKey;
|
||||
// if (box.read(BoxName.driverID) != null) {
|
||||
// Get.put(LocationBackgroundController());
|
||||
// }
|
||||
if (box.read(BoxName.driverID) != null) {
|
||||
Get.put(LocationBackgroundController());
|
||||
}
|
||||
if (Platform.isAndroid || Platform.isIOS) {
|
||||
await Firebase.initializeApp(
|
||||
options: DefaultFirebaseOptions.currentPlatform,
|
||||
|
||||
Reference in New Issue
Block a user