Skip to content

Commit ac97cfd

Browse files
Added fromJson/toJson/toString/equals/copyWith methods in BackgroundLocationUpdateData
1 parent b7b8ee1 commit ac97cfd

File tree

3 files changed

+96
-1
lines changed

3 files changed

+96
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 1.4.2 - 11-09-2023
2+
- Added fromJson/toJson/toString/equals/copyWith methods in BackgroundLocationUpdateData
3+
14
## 1.4.1 - 17-06-2023
25
- Updates Play Services Location library
36

lib/src/model/background_location_update_data.dart

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:convert';
2+
13
/// BackgroundLocationUpdateData will contain all the data that is send when getting a background location update
24
///
35
/// latitude & longitude
@@ -40,4 +42,94 @@ class BackgroundLocationUpdateData {
4042
required this.speed,
4143
required this.speedAccuracy,
4244
});
45+
46+
Map<String, dynamic> toMap() {
47+
return {
48+
'lat': lat,
49+
'lon': lon,
50+
'horizontalAccuracy': horizontalAccuracy,
51+
'alt': alt,
52+
'verticalAccuracy': verticalAccuracy,
53+
'course': course,
54+
'courseAccuracy': courseAccuracy,
55+
'speed': speed,
56+
'speedAccuracy': speedAccuracy,
57+
};
58+
}
59+
60+
factory BackgroundLocationUpdateData.fromMap(Map<String, dynamic> map) {
61+
return BackgroundLocationUpdateData(
62+
lat: map['lat']?.toDouble() ?? 0.0,
63+
lon: map['lon']?.toDouble() ?? 0.0,
64+
horizontalAccuracy: map['horizontalAccuracy']?.toDouble() ?? 0.0,
65+
alt: map['alt']?.toDouble() ?? 0.0,
66+
verticalAccuracy: map['verticalAccuracy']?.toDouble() ?? 0.0,
67+
course: map['course']?.toDouble() ?? 0.0,
68+
courseAccuracy: map['courseAccuracy']?.toDouble() ?? 0.0,
69+
speed: map['speed']?.toDouble() ?? 0.0,
70+
speedAccuracy: map['speedAccuracy']?.toDouble() ?? 0.0,
71+
);
72+
}
73+
74+
String toJson() => json.encode(toMap());
75+
76+
factory BackgroundLocationUpdateData.fromJson(String source) => BackgroundLocationUpdateData.fromMap(json.decode(source));
77+
78+
@override
79+
bool operator ==(Object other) {
80+
if (identical(this, other)) return true;
81+
82+
return other is BackgroundLocationUpdateData &&
83+
other.lat == lat &&
84+
other.lon == lon &&
85+
other.horizontalAccuracy == horizontalAccuracy &&
86+
other.alt == alt &&
87+
other.verticalAccuracy == verticalAccuracy &&
88+
other.course == course &&
89+
other.courseAccuracy == courseAccuracy &&
90+
other.speed == speed &&
91+
other.speedAccuracy == speedAccuracy;
92+
}
93+
94+
@override
95+
int get hashCode {
96+
return lat.hashCode ^
97+
lon.hashCode ^
98+
horizontalAccuracy.hashCode ^
99+
alt.hashCode ^
100+
verticalAccuracy.hashCode ^
101+
course.hashCode ^
102+
courseAccuracy.hashCode ^
103+
speed.hashCode ^
104+
speedAccuracy.hashCode;
105+
}
106+
107+
@override
108+
String toString() {
109+
return 'BackgroundLocationUpdateData(lat: $lat, lon: $lon, horizontalAccuracy: $horizontalAccuracy, alt: $alt, verticalAccuracy: $verticalAccuracy, course: $course, courseAccuracy: $courseAccuracy, speed: $speed, speedAccuracy: $speedAccuracy)';
110+
}
111+
112+
BackgroundLocationUpdateData copyWith({
113+
double? lat,
114+
double? lon,
115+
double? horizontalAccuracy,
116+
double? alt,
117+
double? verticalAccuracy,
118+
double? course,
119+
double? courseAccuracy,
120+
double? speed,
121+
double? speedAccuracy,
122+
}) {
123+
return BackgroundLocationUpdateData(
124+
lat: lat ?? this.lat,
125+
lon: lon ?? this.lon,
126+
horizontalAccuracy: horizontalAccuracy ?? this.horizontalAccuracy,
127+
alt: alt ?? this.alt,
128+
verticalAccuracy: verticalAccuracy ?? this.verticalAccuracy,
129+
course: course ?? this.course,
130+
courseAccuracy: courseAccuracy ?? this.courseAccuracy,
131+
speed: speed ?? this.speed,
132+
speedAccuracy: speedAccuracy ?? this.speedAccuracy,
133+
);
134+
}
43135
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: background_location_tracker
22
description: A Flutter plugin that allows you to track the background location for Android & iOS
33
repository: https://github.com/icapps/flutter-background-location-tracker
4-
version: 1.4.1
4+
version: 1.4.2
55

66
environment:
77
sdk: ">=2.12.0 <3.0.0"

0 commit comments

Comments
 (0)