|
| 1 | +import 'dart:convert'; |
| 2 | + |
1 | 3 | /// BackgroundLocationUpdateData will contain all the data that is send when getting a background location update
|
2 | 4 | ///
|
3 | 5 | /// latitude & longitude
|
@@ -40,4 +42,94 @@ class BackgroundLocationUpdateData {
|
40 | 42 | required this.speed,
|
41 | 43 | required this.speedAccuracy,
|
42 | 44 | });
|
| 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 | + } |
43 | 135 | }
|
0 commit comments