7/22/1 location background

This commit is contained in:
Hamza-Ayed
2024-07-22 20:08:42 +03:00
parent d6410e45a4
commit dea83d970c
8 changed files with 95 additions and 54 deletions

View File

@@ -32,7 +32,7 @@ def keystorePropertiesFile = rootProject.file('key.properties')
android {
namespace "com.sefer_driver"
compileSdkVersion 34
compileSdk 34
ndkVersion flutter.ndkVersion
compileOptions {
@@ -47,19 +47,29 @@ android {
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.sefer_driver"
applicationId = "com.sefer_driver"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion 23
targetSdkVersion 34
versionCode 63
versionName '1.5.63'
// manifestPlaceholders = [mapsApiKey: 'android/app/src/main/AndroidManifest.xml']
minSdk = 23
targetSdk = flutter.targetSdkVersion
versionCode = 64
versionName = '1.5.64'
}
// defaultConfig {
// // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
// applicationId ="com.sefer_driver"
// // You can update the following values to match your application needs.
// // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
// minSdkVersion= 23
// targetSdk= 34
// versionCode= 63
// versionName ='1.5.63'
// // manifestPlaceholders = [mapsApiKey: 'android/app/src/main/AndroidManifest.xml']
// }
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
@@ -84,5 +94,6 @@ flutter {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// implementation platform('com.google.firebase:firebase-bom:32.1.1')
implementation 'com.stripe:paymentsheet:20.47.0'
}

View File

@@ -4,6 +4,7 @@
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
@@ -12,6 +13,7 @@
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
@@ -34,6 +36,8 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="com.example.action.APP_ACTION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<meta-data
@@ -50,16 +54,23 @@
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
<!-- <service
android:name=".LocationUpdatesService"
android:exported="false" /> -->
<service
android:name=".LocationUpdatesService"
android:exported="false" />
android:foregroundServiceType="location"
android:exported="false"> <!-- or false, depending on whether it should be accessible by other
apps -->
</service>
<receiver
android:name=".YourBroadcastReceiver"
android:exported="false">
<intent-filter>
android:exported="false"> <!-- or false, depending on whether it should be accessible by other
apps -->
<!-- <intent-filter>
<action android:name="com.example.ACTION" />
</intent-filter>
</intent-filter> -->
</receiver>
</application>
</manifest>

View File

@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.9.10'
ext.kotlin_version = '1.9.22'
repositories {
google()
mavenCentral()

View File

@@ -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();
}
}

View File

@@ -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

View File

@@ -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,
// ),
// ),
// ),
],
)),
);

View File

@@ -76,10 +76,11 @@ packages:
background_location:
dependency: "direct main"
description:
name: background_location
sha256: fbb83ceb8cefcc6793f0a362f12773c28fc290a5e2c76cb593ee592ec7b6cb32
url: "https://pub.dev"
source: hosted
path: "."
ref: master
resolved-ref: f90f62aad5481677a832486432ccbf84da3b6861
url: "https://github.com/dharmik-dalwadi-seaflux/background_location.git"
source: git
version: "0.13.0"
boolean_selector:
dependency: transitive

View File

@@ -56,7 +56,12 @@ dependencies:
# google_generative_ai: ^0.0.1-dev
vibration: ^1.8.4
wakelock_plus:
background_location: ^0.13.0
# background_location: ^0.13.0
background_location:
git:
url: https://github.com/dharmik-dalwadi-seaflux/background_location.git
ref: master
record: ^5.0.5
dio: ^5.4.3+1
webview_flutter: ^4.7.0