Skip to content

Commit

Permalink
Merge 50f10e1 into 8132f42
Browse files Browse the repository at this point in the history
  • Loading branch information
ikbendewilliam committed Sep 21, 2023
2 parents 8132f42 + 50f10e1 commit 51e9f21
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,6 @@
## 1.4.2 - 11-09-2023
- Added fromJson/toJson/toString/equals/copyWith methods in BackgroundLocationUpdateData

## 1.4.1 - 17-06-2023
- Updates Play Services Location library

Expand Down
2 changes: 1 addition & 1 deletion example/android/build.gradle
Expand Up @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
2 changes: 1 addition & 1 deletion example/lib/main.dart
Expand Up @@ -162,7 +162,7 @@ class _MyAppState extends State<MyApp> {
}

Future<void> _requestLocationPermission() async {
final result = await Permission.locationAlways.request();
final result = await Permission.location.request();
if (result == PermissionStatus.granted) {
print('GRANTED'); // ignore: avoid_print
} else {
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Expand Up @@ -21,7 +21,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.4.1"
version: "1.4.2"
boolean_selector:
dependency: transitive
description:
Expand Down
93 changes: 93 additions & 0 deletions lib/src/model/background_location_update_data.dart
@@ -1,3 +1,5 @@
import 'dart:convert';

/// BackgroundLocationUpdateData will contain all the data that is send when getting a background location update
///
/// latitude & longitude
Expand Down Expand Up @@ -40,4 +42,95 @@ class BackgroundLocationUpdateData {
required this.speed,
required this.speedAccuracy,
});

Map<String, dynamic> toMap() {
return {
'lat': lat,
'lon': lon,
'horizontalAccuracy': horizontalAccuracy,
'alt': alt,
'verticalAccuracy': verticalAccuracy,
'course': course,
'courseAccuracy': courseAccuracy,
'speed': speed,
'speedAccuracy': speedAccuracy,
};
}

factory BackgroundLocationUpdateData.fromMap(Map<String, dynamic> map) {
return BackgroundLocationUpdateData(
lat: map['lat']?.toDouble() ?? 0.0,
lon: map['lon']?.toDouble() ?? 0.0,
horizontalAccuracy: map['horizontalAccuracy']?.toDouble() ?? 0.0,
alt: map['alt']?.toDouble() ?? 0.0,
verticalAccuracy: map['verticalAccuracy']?.toDouble() ?? 0.0,
course: map['course']?.toDouble() ?? 0.0,
courseAccuracy: map['courseAccuracy']?.toDouble() ?? 0.0,
speed: map['speed']?.toDouble() ?? 0.0,
speedAccuracy: map['speedAccuracy']?.toDouble() ?? 0.0,
);
}

String toJson() => json.encode(toMap());

factory BackgroundLocationUpdateData.fromJson(String source) =>
BackgroundLocationUpdateData.fromMap(json.decode(source));

@override
bool operator ==(Object other) {
if (identical(this, other)) return true;

return other is BackgroundLocationUpdateData &&
other.lat == lat &&
other.lon == lon &&
other.horizontalAccuracy == horizontalAccuracy &&
other.alt == alt &&
other.verticalAccuracy == verticalAccuracy &&
other.course == course &&
other.courseAccuracy == courseAccuracy &&
other.speed == speed &&
other.speedAccuracy == speedAccuracy;
}

@override
int get hashCode {
return lat.hashCode ^
lon.hashCode ^
horizontalAccuracy.hashCode ^
alt.hashCode ^
verticalAccuracy.hashCode ^
course.hashCode ^
courseAccuracy.hashCode ^
speed.hashCode ^
speedAccuracy.hashCode;
}

@override
String toString() {
return 'BackgroundLocationUpdateData(lat: $lat, lon: $lon, horizontalAccuracy: $horizontalAccuracy, alt: $alt, verticalAccuracy: $verticalAccuracy, course: $course, courseAccuracy: $courseAccuracy, speed: $speed, speedAccuracy: $speedAccuracy)';
}

BackgroundLocationUpdateData copyWith({
double? lat,
double? lon,
double? horizontalAccuracy,
double? alt,
double? verticalAccuracy,
double? course,
double? courseAccuracy,
double? speed,
double? speedAccuracy,
}) {
return BackgroundLocationUpdateData(
lat: lat ?? this.lat,
lon: lon ?? this.lon,
horizontalAccuracy: horizontalAccuracy ?? this.horizontalAccuracy,
alt: alt ?? this.alt,
verticalAccuracy: verticalAccuracy ?? this.verticalAccuracy,
course: course ?? this.course,
courseAccuracy: courseAccuracy ?? this.courseAccuracy,
speed: speed ?? this.speed,
speedAccuracy: speedAccuracy ?? this.speedAccuracy,
);
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
@@ -1,7 +1,7 @@
name: background_location_tracker
description: A Flutter plugin that allows you to track the background location for Android & iOS
repository: https://github.com/icapps/flutter-background-location-tracker
version: 1.4.1
version: 1.4.2

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down

0 comments on commit 51e9f21

Please sign in to comment.