From 9aaf07661f461e001395bf717d8ff2de63a1c9c1 Mon Sep 17 00:00:00 2001 From: Mohamed dawood Date: Mon, 13 Jun 2022 12:55:18 +0200 Subject: [PATCH] 0.1.2 --- example/pubspec.lock | 2 +- lib/src/location_model.dart | 84 ++++++++++++++++---- lib/src/location_model.freezed.dart | 118 +++++++++++++--------------- pubspec.yaml | 2 +- 4 files changed, 123 insertions(+), 83 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index ecd0995..4f9b8e2 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -265,7 +265,7 @@ packages: path: ".." relative: true source: path - version: "0.1.1" + version: "0.1.2" path: dependency: transitive description: diff --git a/lib/src/location_model.dart b/lib/src/location_model.dart index 8d3eb7b..21facf8 100644 --- a/lib/src/location_model.dart +++ b/lib/src/location_model.dart @@ -13,55 +13,56 @@ class FormattedLocation with _$FormattedLocation { const FormattedLocation._(); const factory FormattedLocation({ ///reference to the Nominatim internal database ID - @Default('') String placeId, + required String placeId, /// latitude of the centroid of the object required double lat, /// longitude of the centroid of the object required double lon, - @Default('') String licence, + required String licence, ///reference to the OSM object - @Default('') String osmType, + required String osmType, String? icon, /// reference to the OSM object - int? osmId, + required int osmId, /// search rank of the object - int? placeRank, + required int placeRank, ///key of the main OSM tag - @Default('') String category, + required String category, /// value of the main OSM tag - @Default('') String type, + required String type, /// computed importance rank - double? importance, - @Default('') String addressType, - @Default('') String name, + required double importance, + required String addressType, + required String name, ///full comma-separated address - @Default('') String displayName, + required String displayName, /// dictionary of address details - @Default(Address()) Address address, + required Address address, /// dictionary with additional useful tags like website or max speed - @Default({}) Map extratags, + required Map extratags, /// dictionary with full list of available names including ref etc - @Default({}) Map namedetails, + required Map namedetails, ///area of corner coordinates - LatLngBounds? boundingBox, + required LatLngBounds? boundingBox, /// GeoBounds of object required GeoGeometry geojson, - @Default({}) Map names, + required Map names, }) = _FormattedLocation; + String get identifier => "$category-$osmId-$osmType"; @override String toString() { @@ -113,6 +114,57 @@ class FormattedLocation with _$FormattedLocation { }; } + static FormattedLocation fromLatLng({ + required double lat, + required double lon, + String placeId = '', + String addressType = '', + String category = '', + String licence = '', + String type = '', + String name = '', + String osmType = '', + String? displayName, + String? icon, + Address address = const Address(), + Map names = const {}, + Map extratags = const {}, + Map namedetails = const {}, + LatLngBounds? boundingBox, + GeoGeometry? geojson, + double importance = 0, + int placeRank = 0, + int osmId = 0, + }) { + return FormattedLocation( + placeId: placeId, + address: address, + names: names, + lat: lat, + lon: lon, + addressType: addressType, + boundingBox: boundingBox, + category: category, + displayName: displayName ?? '$lat, $lon', + extratags: extratags, + geojson: geojson ?? + GeoGeometry.point( + LatLng(lon, lat), + Color((math.Random().nextDouble() * 0xFFFFFF).toInt()) + .withOpacity(1.0), + ), + importance: importance, + licence: licence, + name: name, + namedetails: namedetails, + osmId: osmId, + osmType: osmType, + placeRank: placeRank, + type: type, + icon: icon, + ); + } + static FormattedLocation fromJson(Map json) { if (json["error"] != null) { throw Exception(json["error"]); diff --git a/lib/src/location_model.freezed.dart b/lib/src/location_model.freezed.dart index b64ddf2..e09175f 100644 --- a/lib/src/location_model.freezed.dart +++ b/lib/src/location_model.freezed.dart @@ -31,10 +31,10 @@ mixin _$FormattedLocation { String? get icon => throw _privateConstructorUsedError; /// reference to the OSM object - int? get osmId => throw _privateConstructorUsedError; + int get osmId => throw _privateConstructorUsedError; /// search rank of the object - int? get placeRank => throw _privateConstructorUsedError; + int get placeRank => throw _privateConstructorUsedError; ///key of the main OSM tag String get category => throw _privateConstructorUsedError; @@ -43,7 +43,7 @@ mixin _$FormattedLocation { String get type => throw _privateConstructorUsedError; /// computed importance rank - double? get importance => throw _privateConstructorUsedError; + double get importance => throw _privateConstructorUsedError; String get addressType => throw _privateConstructorUsedError; String get name => throw _privateConstructorUsedError; @@ -83,11 +83,11 @@ abstract class $FormattedLocationCopyWith<$Res> { String licence, String osmType, String? icon, - int? osmId, - int? placeRank, + int osmId, + int placeRank, String category, String type, - double? importance, + double importance, String addressType, String name, String displayName, @@ -161,11 +161,11 @@ class _$FormattedLocationCopyWithImpl<$Res> osmId: osmId == freezed ? _value.osmId : osmId // ignore: cast_nullable_to_non_nullable - as int?, + as int, placeRank: placeRank == freezed ? _value.placeRank : placeRank // ignore: cast_nullable_to_non_nullable - as int?, + as int, category: category == freezed ? _value.category : category // ignore: cast_nullable_to_non_nullable @@ -177,7 +177,7 @@ class _$FormattedLocationCopyWithImpl<$Res> importance: importance == freezed ? _value.importance : importance // ignore: cast_nullable_to_non_nullable - as double?, + as double, addressType: addressType == freezed ? _value.addressType : addressType // ignore: cast_nullable_to_non_nullable @@ -239,11 +239,11 @@ abstract class _$$_FormattedLocationCopyWith<$Res> String licence, String osmType, String? icon, - int? osmId, - int? placeRank, + int osmId, + int placeRank, String category, String type, - double? importance, + double importance, String addressType, String name, String displayName, @@ -320,11 +320,11 @@ class __$$_FormattedLocationCopyWithImpl<$Res> osmId: osmId == freezed ? _value.osmId : osmId // ignore: cast_nullable_to_non_nullable - as int?, + as int, placeRank: placeRank == freezed ? _value.placeRank : placeRank // ignore: cast_nullable_to_non_nullable - as int?, + as int, category: category == freezed ? _value.category : category // ignore: cast_nullable_to_non_nullable @@ -336,7 +336,7 @@ class __$$_FormattedLocationCopyWithImpl<$Res> importance: importance == freezed ? _value.importance : importance // ignore: cast_nullable_to_non_nullable - as double?, + as double, addressType: addressType == freezed ? _value.addressType : addressType // ignore: cast_nullable_to_non_nullable @@ -381,26 +381,26 @@ class __$$_FormattedLocationCopyWithImpl<$Res> class _$_FormattedLocation extends _FormattedLocation { const _$_FormattedLocation( - {this.placeId = '', + {required this.placeId, required this.lat, required this.lon, - this.licence = '', - this.osmType = '', + required this.licence, + required this.osmType, this.icon, - this.osmId, - this.placeRank, - this.category = '', - this.type = '', - this.importance, - this.addressType = '', - this.name = '', - this.displayName = '', - this.address = const Address(), - final Map extratags = const {}, - final Map namedetails = const {}, - this.boundingBox, + required this.osmId, + required this.placeRank, + required this.category, + required this.type, + required this.importance, + required this.addressType, + required this.name, + required this.displayName, + required this.address, + required final Map extratags, + required final Map namedetails, + required this.boundingBox, required this.geojson, - final Map names = const {}}) + required final Map names}) : _extratags = extratags, _namedetails = namedetails, _names = names, @@ -408,7 +408,6 @@ class _$_FormattedLocation extends _FormattedLocation { ///reference to the Nominatim internal database ID @override - @JsonKey() final String placeId; /// latitude of the centroid of the object @@ -419,52 +418,44 @@ class _$_FormattedLocation extends _FormattedLocation { @override final double lon; @override - @JsonKey() final String licence; ///reference to the OSM object @override - @JsonKey() final String osmType; @override final String? icon; /// reference to the OSM object @override - final int? osmId; + final int osmId; /// search rank of the object @override - final int? placeRank; + final int placeRank; ///key of the main OSM tag @override - @JsonKey() final String category; /// value of the main OSM tag @override - @JsonKey() final String type; /// computed importance rank @override - final double? importance; + final double importance; @override - @JsonKey() final String addressType; @override - @JsonKey() final String name; ///full comma-separated address @override - @JsonKey() final String displayName; /// dictionary of address details @override - @JsonKey() final Address address; /// dictionary with additional useful tags like website or max speed @@ -472,7 +463,6 @@ class _$_FormattedLocation extends _FormattedLocation { /// dictionary with additional useful tags like website or max speed @override - @JsonKey() Map get extratags { // ignore: implicit_dynamic_type return EqualUnmodifiableMapView(_extratags); @@ -483,7 +473,6 @@ class _$_FormattedLocation extends _FormattedLocation { /// dictionary with full list of available names including ref etc @override - @JsonKey() Map get namedetails { // ignore: implicit_dynamic_type return EqualUnmodifiableMapView(_namedetails); @@ -498,7 +487,6 @@ class _$_FormattedLocation extends _FormattedLocation { final GeoGeometry geojson; final Map _names; @override - @JsonKey() Map get names { // ignore: implicit_dynamic_type return EqualUnmodifiableMapView(_names); @@ -571,26 +559,26 @@ class _$_FormattedLocation extends _FormattedLocation { abstract class _FormattedLocation extends FormattedLocation { const factory _FormattedLocation( - {final String placeId, + {required final String placeId, required final double lat, required final double lon, - final String licence, - final String osmType, + required final String licence, + required final String osmType, final String? icon, - final int? osmId, - final int? placeRank, - final String category, - final String type, - final double? importance, - final String addressType, - final String name, - final String displayName, - final Address address, - final Map extratags, - final Map namedetails, - final LatLngBounds? boundingBox, + required final int osmId, + required final int placeRank, + required final String category, + required final String type, + required final double importance, + required final String addressType, + required final String name, + required final String displayName, + required final Address address, + required final Map extratags, + required final Map namedetails, + required final LatLngBounds? boundingBox, required final GeoGeometry geojson, - final Map names}) = _$_FormattedLocation; + required final Map names}) = _$_FormattedLocation; const _FormattedLocation._() : super._(); @override @@ -616,11 +604,11 @@ abstract class _FormattedLocation extends FormattedLocation { @override /// reference to the OSM object - int? get osmId => throw _privateConstructorUsedError; + int get osmId => throw _privateConstructorUsedError; @override /// search rank of the object - int? get placeRank => throw _privateConstructorUsedError; + int get placeRank => throw _privateConstructorUsedError; @override ///key of the main OSM tag @@ -632,7 +620,7 @@ abstract class _FormattedLocation extends FormattedLocation { @override /// computed importance rank - double? get importance => throw _privateConstructorUsedError; + double get importance => throw _privateConstructorUsedError; @override String get addressType => throw _privateConstructorUsedError; @override diff --git a/pubspec.yaml b/pubspec.yaml index 9a54294..352bfd2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: open_location_picker description: FormField to pick one or more locations from open street map -version: 0.1.1 +version: 0.1.2 homepage: https://github.com/mo-ah-dawood/open_location_picker environment: