extended location and latlng models
This commit is contained in:
@@ -12,4 +12,18 @@ class LatLng {
|
|||||||
Map<String, double> toJson() {
|
Map<String, double> toJson() {
|
||||||
return {'lat': lat, 'lng': lng};
|
return {'lat': lat, 'lng': lng};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) {
|
||||||
|
if (other is! LatLng) return false;
|
||||||
|
return hashCode == other.hashCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => Object.hash(lat, lng);
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return '${lat.toString()}, ${lng.toString()}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-2
@@ -1,19 +1,34 @@
|
|||||||
import 'latlng.dart';
|
import 'latlng.dart';
|
||||||
|
|
||||||
class Location {
|
class Location {
|
||||||
|
final String name;
|
||||||
final LatLng coordinates;
|
final LatLng coordinates;
|
||||||
final String address;
|
final String address;
|
||||||
|
|
||||||
Location({required this.coordinates, this.address = ''});
|
Location({required this.name, required this.coordinates, this.address = ''});
|
||||||
|
|
||||||
factory Location.fromJson(Map<String, dynamic> json) {
|
factory Location.fromJson(Map<String, dynamic> json) {
|
||||||
return Location(
|
return Location(
|
||||||
|
name: json['name'] as String,
|
||||||
address: json['address'] as String,
|
address: json['address'] as String,
|
||||||
coordinates: LatLng.fromJson(json['coordinates']),
|
coordinates: LatLng.fromJson(json['coordinates']),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
return {'address': address, 'coordinates': coordinates.toJson()};
|
return {
|
||||||
|
'name': name,
|
||||||
|
'address': address,
|
||||||
|
'coordinates': coordinates.toJson(),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) {
|
||||||
|
if (other is! Location) return false;
|
||||||
|
return hashCode == other.hashCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => coordinates.hashCode;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user