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 { android {
namespace "com.sefer_driver" namespace "com.sefer_driver"
compileSdkVersion 34 compileSdk 34
ndkVersion flutter.ndkVersion ndkVersion flutter.ndkVersion
compileOptions { compileOptions {
@@ -47,19 +47,29 @@ android {
sourceSets { sourceSets {
main.java.srcDirs += 'src/main/kotlin' main.java.srcDirs += 'src/main/kotlin'
} }
defaultConfig { defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). // 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. // 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. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion 23 minSdk = 23
targetSdkVersion 34 targetSdk = flutter.targetSdkVersion
versionCode 63 versionCode = 64
versionName '1.5.63' versionName = '1.5.64'
// manifestPlaceholders = [mapsApiKey: 'android/app/src/main/AndroidManifest.xml']
} }
// 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 { signingConfigs {
release { release {
keyAlias keystoreProperties['keyAlias'] keyAlias keystoreProperties['keyAlias']
@@ -84,5 +94,6 @@ flutter {
dependencies { dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// implementation platform('com.google.firebase:firebase-bom:32.1.1') // 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_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_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" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
<uses-permission android:name="android.permission.USE_BIOMETRIC" /> <uses-permission android:name="android.permission.USE_BIOMETRIC" />
<uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <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.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <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" />
<uses-feature android:name="android.hardware.camera.autofocus" /> <uses-feature android:name="android.hardware.camera.autofocus" />
@@ -34,6 +36,8 @@
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
<action android:name="com.example.action.APP_ACTION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter> </intent-filter>
</activity> </activity>
<meta-data <meta-data
@@ -50,16 +54,23 @@
android:screenOrientation="portrait" android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
<!-- <service
android:name=".LocationUpdatesService"
android:exported="false" /> -->
<service <service
android:name=".LocationUpdatesService" 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 <receiver
android:name=".YourBroadcastReceiver" android:name=".YourBroadcastReceiver"
android:exported="false"> android:exported="false"> <!-- or false, depending on whether it should be accessible by other
<intent-filter> apps -->
<!-- <intent-filter>
<action android:name="com.example.ACTION" /> <action android:name="com.example.ACTION" />
</intent-filter> </intent-filter> -->
</receiver> </receiver>
</application> </application>
</manifest> </manifest>

View File

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

View File

@@ -8,13 +8,19 @@ class LocationBackgroundController extends GetxController {
void onInit() { void onInit() {
super.onInit(); super.onInit();
requestLocationPermission(); requestLocationPermission();
configureBackgroundLocation();
} }
Future<void> requestLocationPermission() async { Future<void> requestLocationPermission() async {
var status = await Permission.locationAlways.status; var status = await Permission.locationAlways.status;
if (!status.isGranted) { 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", icon: "@mipmap/ic_launcher",
); );
BackgroundLocation.setAndroidConfiguration(1000); // Set the location update interval to 5 seconds
BackgroundLocation.setAndroidConfiguration(5000);
BackgroundLocation.startLocationService(); BackgroundLocation.startLocationService();
BackgroundLocation.getLocationUpdates((location) { BackgroundLocation.getLocationUpdates((location) {
// Handle location updates here // 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 { Future<void> getBackgroundLocation() async {
Timer.periodic(const Duration(seconds: 5), (timer) {
getBackgroundLocation();
});
}
getBackgroundLocation() async {
var status = await Permission.locationAlways.status; var status = await Permission.locationAlways.status;
if (status.isGranted) { if (status.isGranted) {
await BackgroundLocation.startLocationService( // The location service is already started in configureBackgroundLocation
distanceFilter: 20, forceAndroidLocationManager: true); // No need to call startLocationService again
BackgroundLocation.setAndroidConfiguration( BackgroundLocation.getLocationUpdates((location) {
Duration.microsecondsPerSecond); // Set interval to 5 seconds // Handle location updates here
print(
BackgroundLocation.getLocationUpdates((location1) {}); "Latitude: ${location.latitude}, Longitude: ${location.longitude}");
});
} else { } else {
// Request permission if not granted
await Permission.locationAlways.request(); await Permission.locationAlways.request();
} }
} }

View File

@@ -18,7 +18,7 @@ class SplashScreen extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
Get.put(LocationBackgroundController()); // Get.put(LocationBackgroundController());
return Scaffold( return Scaffold(
backgroundColor: backgroundColor:
AppColor.secondaryColor, // Set your desired background color AppColor.secondaryColor, // Set your desired background color

View File

@@ -161,24 +161,24 @@ GetBuilder<HomeCaptainController> leftMainMenuCaptainIcons() {
), ),
), ),
), ),
AnimatedContainer( // AnimatedContainer(
duration: const Duration(microseconds: 200), // duration: const Duration(microseconds: 200),
width: controller.widthMapTypeAndTraffic, // width: controller.widthMapTypeAndTraffic,
decoration: BoxDecoration( // decoration: BoxDecoration(
color: AppColor.secondaryColor, // color: AppColor.secondaryColor,
border: Border.all(color: AppColor.blueColor), // border: Border.all(color: AppColor.blueColor),
borderRadius: BorderRadius.circular(15)), // borderRadius: BorderRadius.circular(15)),
child: IconButton( // child: IconButton(
onPressed: () async { // onPressed: () async {
Get.to(() => EgyptCardAI()); // Get.to(() => EgyptCardAI());
}, // },
icon: const Icon( // icon: const Icon(
FontAwesome5.grin_tears, // FontAwesome5.grin_tears,
size: 29, // size: 29,
color: AppColor.blueColor, // color: AppColor.blueColor,
), // ),
), // ),
), // ),
], ],
)), )),
); );

View File

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

View File

@@ -56,7 +56,12 @@ dependencies:
# google_generative_ai: ^0.0.1-dev # google_generative_ai: ^0.0.1-dev
vibration: ^1.8.4 vibration: ^1.8.4
wakelock_plus: 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 record: ^5.0.5
dio: ^5.4.3+1 dio: ^5.4.3+1
webview_flutter: ^4.7.0 webview_flutter: ^4.7.0