diff --git a/lib/model/latlng.dart b/lib/model/latlng.dart index bda28da..9a90e99 100644 --- a/lib/model/latlng.dart +++ b/lib/model/latlng.dart @@ -12,4 +12,18 @@ class LatLng { Map toJson() { 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()}'; + } } diff --git a/lib/model/location.dart b/lib/model/location.dart index e247aea..602e1f5 100644 --- a/lib/model/location.dart +++ b/lib/model/location.dart @@ -1,19 +1,34 @@ import 'latlng.dart'; class Location { + final String name; final LatLng coordinates; final String address; - Location({required this.coordinates, this.address = ''}); + Location({required this.name, required this.coordinates, this.address = ''}); factory Location.fromJson(Map json) { return Location( + name: json['name'] as String, address: json['address'] as String, coordinates: LatLng.fromJson(json['coordinates']), ); } Map 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; }