diff --git a/example/pubspec.lock b/example/pubspec.lock index 9c3d2ec..ecd0995 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -94,7 +94,7 @@ packages: name: flutter_map url: "https://pub.dartlang.org" source: hosted - version: "0.14.0" + version: "1.0.0" flutter_test: dependency: "direct dev" description: flutter @@ -265,7 +265,7 @@ packages: path: ".." relative: true source: path - version: "0.1.0" + version: "0.1.1" path: dependency: transitive description: @@ -280,6 +280,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.2" + polylabel: + dependency: transitive + description: + name: polylabel + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" positioned_tap_detector_2: dependency: transitive description: @@ -355,13 +362,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.4.9" - transparent_image: - dependency: transitive - description: - name: transparent_image - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.0" tuple: dependency: transitive description: diff --git a/lib/src/bloc.dart b/lib/src/bloc.dart index f963508..41ba67b 100644 --- a/lib/src/bloc.dart +++ b/lib/src/bloc.dart @@ -1,5 +1,6 @@ import 'dart:convert'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:http/http.dart' as http; @@ -66,7 +67,7 @@ extension BlocExtension on OpenMapBloc { var response = await http.get(url); var parsed = jsonDecode(response.body); - return FormattedLocation.from(parsed); + return FormattedLocation.fromJson(parsed); } Future> search({ @@ -95,10 +96,12 @@ extension BlocExtension on OpenMapBloc { List resList = []; for (var loc in parsed) { try { - var res = FormattedLocation.from(loc); + var res = FormattedLocation.fromJson(loc); resList.add(res); } catch (e) { - print(e); + if (kDebugMode) { + print(e); + } } } return Future>.value(resList); diff --git a/lib/src/bloc.freezed.dart b/lib/src/bloc.freezed.dart index f21a8e5..d7d212c 100644 --- a/lib/src/bloc.freezed.dart +++ b/lib/src/bloc.freezed.dart @@ -1,5 +1,6 @@ // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint // ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target part of 'bloc.dart'; @@ -11,55 +12,11 @@ part of 'bloc.dart'; T _$identity(T value) => value; final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); - -/// @nodoc -class _$OpenMapStateTearOff { - const _$OpenMapStateTearOff(); - - _Selected selected(SelectedLocation selected) { - return _Selected( - selected, - ); - } - - _Reversing reversing(SelectedLocation selected, LatLng reversing) { - return _Reversing( - selected, - reversing, - ); - } - - _Searching searching( - {required SelectedLocation selected, - required String query, - required List oldResults}) { - return _Searching( - selected: selected, - query: query, - oldResults: oldResults, - ); - } - - _Results results( - {required SelectedLocation selected, - required String query, - required List searchResults}) { - return _Results( - selected: selected, - query: query, - searchResults: searchResults, - ); - } -} - -/// @nodoc -const $OpenMapState = _$OpenMapStateTearOff(); + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); /// @nodoc mixin _$OpenMapState { SelectedLocation get selected => throw _privateConstructorUsedError; - @optionalTypeArgs TResult when({ required TResult Function(SelectedLocation selected) selected, @@ -168,9 +125,11 @@ class _$OpenMapStateCopyWithImpl<$Res> implements $OpenMapStateCopyWith<$Res> { } /// @nodoc -abstract class _$SelectedCopyWith<$Res> implements $OpenMapStateCopyWith<$Res> { - factory _$SelectedCopyWith(_Selected value, $Res Function(_Selected) then) = - __$SelectedCopyWithImpl<$Res>; +abstract class _$$_SelectedCopyWith<$Res> + implements $OpenMapStateCopyWith<$Res> { + factory _$$_SelectedCopyWith( + _$_Selected value, $Res Function(_$_Selected) then) = + __$$_SelectedCopyWithImpl<$Res>; @override $Res call({SelectedLocation selected}); @@ -179,19 +138,20 @@ abstract class _$SelectedCopyWith<$Res> implements $OpenMapStateCopyWith<$Res> { } /// @nodoc -class __$SelectedCopyWithImpl<$Res> extends _$OpenMapStateCopyWithImpl<$Res> - implements _$SelectedCopyWith<$Res> { - __$SelectedCopyWithImpl(_Selected _value, $Res Function(_Selected) _then) - : super(_value, (v) => _then(v as _Selected)); +class __$$_SelectedCopyWithImpl<$Res> extends _$OpenMapStateCopyWithImpl<$Res> + implements _$$_SelectedCopyWith<$Res> { + __$$_SelectedCopyWithImpl( + _$_Selected _value, $Res Function(_$_Selected) _then) + : super(_value, (v) => _then(v as _$_Selected)); @override - _Selected get _value => super._value as _Selected; + _$_Selected get _value => super._value as _$_Selected; @override $Res call({ Object? selected = freezed, }) { - return _then(_Selected( + return _then(_$_Selected( selected == freezed ? _value.selected : selected // ignore: cast_nullable_to_non_nullable @@ -202,22 +162,30 @@ class __$SelectedCopyWithImpl<$Res> extends _$OpenMapStateCopyWithImpl<$Res> /// @nodoc -class _$_Selected implements _Selected { +class _$_Selected with DiagnosticableTreeMixin implements _Selected { const _$_Selected(this.selected); @override final SelectedLocation selected; @override - String toString() { + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { return 'OpenMapState.selected(selected: $selected)'; } + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..add(DiagnosticsProperty('type', 'OpenMapState.selected')) + ..add(DiagnosticsProperty('selected', selected)); + } + @override bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _Selected && + other is _$_Selected && const DeepCollectionEquality().equals(other.selected, selected)); } @@ -227,8 +195,8 @@ class _$_Selected implements _Selected { @JsonKey(ignore: true) @override - _$SelectedCopyWith<_Selected> get copyWith => - __$SelectedCopyWithImpl<_Selected>(this, _$identity); + _$$_SelectedCopyWith<_$_Selected> get copyWith => + __$$_SelectedCopyWithImpl<_$_Selected>(this, _$identity); @override @optionalTypeArgs @@ -319,22 +287,22 @@ class _$_Selected implements _Selected { } abstract class _Selected implements OpenMapState { - const factory _Selected(SelectedLocation selected) = _$_Selected; + const factory _Selected(final SelectedLocation selected) = _$_Selected; @override - SelectedLocation get selected; + SelectedLocation get selected => throw _privateConstructorUsedError; @override @JsonKey(ignore: true) - _$SelectedCopyWith<_Selected> get copyWith => + _$$_SelectedCopyWith<_$_Selected> get copyWith => throw _privateConstructorUsedError; } /// @nodoc -abstract class _$ReversingCopyWith<$Res> +abstract class _$$_ReversingCopyWith<$Res> implements $OpenMapStateCopyWith<$Res> { - factory _$ReversingCopyWith( - _Reversing value, $Res Function(_Reversing) then) = - __$ReversingCopyWithImpl<$Res>; + factory _$$_ReversingCopyWith( + _$_Reversing value, $Res Function(_$_Reversing) then) = + __$$_ReversingCopyWithImpl<$Res>; @override $Res call({SelectedLocation selected, LatLng reversing}); @@ -343,20 +311,21 @@ abstract class _$ReversingCopyWith<$Res> } /// @nodoc -class __$ReversingCopyWithImpl<$Res> extends _$OpenMapStateCopyWithImpl<$Res> - implements _$ReversingCopyWith<$Res> { - __$ReversingCopyWithImpl(_Reversing _value, $Res Function(_Reversing) _then) - : super(_value, (v) => _then(v as _Reversing)); +class __$$_ReversingCopyWithImpl<$Res> extends _$OpenMapStateCopyWithImpl<$Res> + implements _$$_ReversingCopyWith<$Res> { + __$$_ReversingCopyWithImpl( + _$_Reversing _value, $Res Function(_$_Reversing) _then) + : super(_value, (v) => _then(v as _$_Reversing)); @override - _Reversing get _value => super._value as _Reversing; + _$_Reversing get _value => super._value as _$_Reversing; @override $Res call({ Object? selected = freezed, Object? reversing = freezed, }) { - return _then(_Reversing( + return _then(_$_Reversing( selected == freezed ? _value.selected : selected // ignore: cast_nullable_to_non_nullable @@ -371,7 +340,7 @@ class __$ReversingCopyWithImpl<$Res> extends _$OpenMapStateCopyWithImpl<$Res> /// @nodoc -class _$_Reversing implements _Reversing { +class _$_Reversing with DiagnosticableTreeMixin implements _Reversing { const _$_Reversing(this.selected, this.reversing); @override @@ -380,15 +349,24 @@ class _$_Reversing implements _Reversing { final LatLng reversing; @override - String toString() { + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { return 'OpenMapState.reversing(selected: $selected, reversing: $reversing)'; } + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..add(DiagnosticsProperty('type', 'OpenMapState.reversing')) + ..add(DiagnosticsProperty('selected', selected)) + ..add(DiagnosticsProperty('reversing', reversing)); + } + @override bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _Reversing && + other is _$_Reversing && const DeepCollectionEquality().equals(other.selected, selected) && const DeepCollectionEquality().equals(other.reversing, reversing)); } @@ -401,8 +379,8 @@ class _$_Reversing implements _Reversing { @JsonKey(ignore: true) @override - _$ReversingCopyWith<_Reversing> get copyWith => - __$ReversingCopyWithImpl<_Reversing>(this, _$identity); + _$$_ReversingCopyWith<_$_Reversing> get copyWith => + __$$_ReversingCopyWithImpl<_$_Reversing>(this, _$identity); @override @optionalTypeArgs @@ -493,24 +471,24 @@ class _$_Reversing implements _Reversing { } abstract class _Reversing implements OpenMapState { - const factory _Reversing(SelectedLocation selected, LatLng reversing) = - _$_Reversing; + const factory _Reversing( + final SelectedLocation selected, final LatLng reversing) = _$_Reversing; @override - SelectedLocation get selected; - LatLng get reversing; + SelectedLocation get selected => throw _privateConstructorUsedError; + LatLng get reversing => throw _privateConstructorUsedError; @override @JsonKey(ignore: true) - _$ReversingCopyWith<_Reversing> get copyWith => + _$$_ReversingCopyWith<_$_Reversing> get copyWith => throw _privateConstructorUsedError; } /// @nodoc -abstract class _$SearchingCopyWith<$Res> +abstract class _$$_SearchingCopyWith<$Res> implements $OpenMapStateCopyWith<$Res> { - factory _$SearchingCopyWith( - _Searching value, $Res Function(_Searching) then) = - __$SearchingCopyWithImpl<$Res>; + factory _$$_SearchingCopyWith( + _$_Searching value, $Res Function(_$_Searching) then) = + __$$_SearchingCopyWithImpl<$Res>; @override $Res call( {SelectedLocation selected, @@ -522,13 +500,14 @@ abstract class _$SearchingCopyWith<$Res> } /// @nodoc -class __$SearchingCopyWithImpl<$Res> extends _$OpenMapStateCopyWithImpl<$Res> - implements _$SearchingCopyWith<$Res> { - __$SearchingCopyWithImpl(_Searching _value, $Res Function(_Searching) _then) - : super(_value, (v) => _then(v as _Searching)); +class __$$_SearchingCopyWithImpl<$Res> extends _$OpenMapStateCopyWithImpl<$Res> + implements _$$_SearchingCopyWith<$Res> { + __$$_SearchingCopyWithImpl( + _$_Searching _value, $Res Function(_$_Searching) _then) + : super(_value, (v) => _then(v as _$_Searching)); @override - _Searching get _value => super._value as _Searching; + _$_Searching get _value => super._value as _$_Searching; @override $Res call({ @@ -536,7 +515,7 @@ class __$SearchingCopyWithImpl<$Res> extends _$OpenMapStateCopyWithImpl<$Res> Object? query = freezed, Object? oldResults = freezed, }) { - return _then(_Searching( + return _then(_$_Searching( selected: selected == freezed ? _value.selected : selected // ignore: cast_nullable_to_non_nullable @@ -546,7 +525,7 @@ class __$SearchingCopyWithImpl<$Res> extends _$OpenMapStateCopyWithImpl<$Res> : query // ignore: cast_nullable_to_non_nullable as String, oldResults: oldResults == freezed - ? _value.oldResults + ? _value._oldResults : oldResults // ignore: cast_nullable_to_non_nullable as List, )); @@ -555,31 +534,48 @@ class __$SearchingCopyWithImpl<$Res> extends _$OpenMapStateCopyWithImpl<$Res> /// @nodoc -class _$_Searching implements _Searching { +class _$_Searching with DiagnosticableTreeMixin implements _Searching { const _$_Searching( - {required this.selected, required this.query, required this.oldResults}); + {required this.selected, + required this.query, + required final List oldResults}) + : _oldResults = oldResults; @override final SelectedLocation selected; @override final String query; + final List _oldResults; @override - final List oldResults; + List get oldResults { + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_oldResults); + } @override - String toString() { + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { return 'OpenMapState.searching(selected: $selected, query: $query, oldResults: $oldResults)'; } + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..add(DiagnosticsProperty('type', 'OpenMapState.searching')) + ..add(DiagnosticsProperty('selected', selected)) + ..add(DiagnosticsProperty('query', query)) + ..add(DiagnosticsProperty('oldResults', oldResults)); + } + @override bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _Searching && + other is _$_Searching && const DeepCollectionEquality().equals(other.selected, selected) && const DeepCollectionEquality().equals(other.query, query) && const DeepCollectionEquality() - .equals(other.oldResults, oldResults)); + .equals(other._oldResults, _oldResults)); } @override @@ -587,12 +583,12 @@ class _$_Searching implements _Searching { runtimeType, const DeepCollectionEquality().hash(selected), const DeepCollectionEquality().hash(query), - const DeepCollectionEquality().hash(oldResults)); + const DeepCollectionEquality().hash(_oldResults)); @JsonKey(ignore: true) @override - _$SearchingCopyWith<_Searching> get copyWith => - __$SearchingCopyWithImpl<_Searching>(this, _$identity); + _$$_SearchingCopyWith<_$_Searching> get copyWith => + __$$_SearchingCopyWithImpl<_$_Searching>(this, _$identity); @override @optionalTypeArgs @@ -684,24 +680,26 @@ class _$_Searching implements _Searching { abstract class _Searching implements OpenMapState { const factory _Searching( - {required SelectedLocation selected, - required String query, - required List oldResults}) = _$_Searching; + {required final SelectedLocation selected, + required final String query, + required final List oldResults}) = _$_Searching; @override - SelectedLocation get selected; - String get query; - List get oldResults; + SelectedLocation get selected => throw _privateConstructorUsedError; + String get query => throw _privateConstructorUsedError; + List get oldResults => throw _privateConstructorUsedError; @override @JsonKey(ignore: true) - _$SearchingCopyWith<_Searching> get copyWith => + _$$_SearchingCopyWith<_$_Searching> get copyWith => throw _privateConstructorUsedError; } /// @nodoc -abstract class _$ResultsCopyWith<$Res> implements $OpenMapStateCopyWith<$Res> { - factory _$ResultsCopyWith(_Results value, $Res Function(_Results) then) = - __$ResultsCopyWithImpl<$Res>; +abstract class _$$_ResultsCopyWith<$Res> + implements $OpenMapStateCopyWith<$Res> { + factory _$$_ResultsCopyWith( + _$_Results value, $Res Function(_$_Results) then) = + __$$_ResultsCopyWithImpl<$Res>; @override $Res call( {SelectedLocation selected, @@ -713,13 +711,13 @@ abstract class _$ResultsCopyWith<$Res> implements $OpenMapStateCopyWith<$Res> { } /// @nodoc -class __$ResultsCopyWithImpl<$Res> extends _$OpenMapStateCopyWithImpl<$Res> - implements _$ResultsCopyWith<$Res> { - __$ResultsCopyWithImpl(_Results _value, $Res Function(_Results) _then) - : super(_value, (v) => _then(v as _Results)); +class __$$_ResultsCopyWithImpl<$Res> extends _$OpenMapStateCopyWithImpl<$Res> + implements _$$_ResultsCopyWith<$Res> { + __$$_ResultsCopyWithImpl(_$_Results _value, $Res Function(_$_Results) _then) + : super(_value, (v) => _then(v as _$_Results)); @override - _Results get _value => super._value as _Results; + _$_Results get _value => super._value as _$_Results; @override $Res call({ @@ -727,7 +725,7 @@ class __$ResultsCopyWithImpl<$Res> extends _$OpenMapStateCopyWithImpl<$Res> Object? query = freezed, Object? searchResults = freezed, }) { - return _then(_Results( + return _then(_$_Results( selected: selected == freezed ? _value.selected : selected // ignore: cast_nullable_to_non_nullable @@ -737,7 +735,7 @@ class __$ResultsCopyWithImpl<$Res> extends _$OpenMapStateCopyWithImpl<$Res> : query // ignore: cast_nullable_to_non_nullable as String, searchResults: searchResults == freezed - ? _value.searchResults + ? _value._searchResults : searchResults // ignore: cast_nullable_to_non_nullable as List, )); @@ -746,33 +744,48 @@ class __$ResultsCopyWithImpl<$Res> extends _$OpenMapStateCopyWithImpl<$Res> /// @nodoc -class _$_Results implements _Results { +class _$_Results with DiagnosticableTreeMixin implements _Results { const _$_Results( {required this.selected, required this.query, - required this.searchResults}); + required final List searchResults}) + : _searchResults = searchResults; @override final SelectedLocation selected; @override final String query; + final List _searchResults; @override - final List searchResults; + List get searchResults { + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_searchResults); + } @override - String toString() { + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { return 'OpenMapState.results(selected: $selected, query: $query, searchResults: $searchResults)'; } + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..add(DiagnosticsProperty('type', 'OpenMapState.results')) + ..add(DiagnosticsProperty('selected', selected)) + ..add(DiagnosticsProperty('query', query)) + ..add(DiagnosticsProperty('searchResults', searchResults)); + } + @override bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _Results && + other is _$_Results && const DeepCollectionEquality().equals(other.selected, selected) && const DeepCollectionEquality().equals(other.query, query) && const DeepCollectionEquality() - .equals(other.searchResults, searchResults)); + .equals(other._searchResults, _searchResults)); } @override @@ -780,12 +793,12 @@ class _$_Results implements _Results { runtimeType, const DeepCollectionEquality().hash(selected), const DeepCollectionEquality().hash(query), - const DeepCollectionEquality().hash(searchResults)); + const DeepCollectionEquality().hash(_searchResults)); @JsonKey(ignore: true) @override - _$ResultsCopyWith<_Results> get copyWith => - __$ResultsCopyWithImpl<_Results>(this, _$identity); + _$$_ResultsCopyWith<_$_Results> get copyWith => + __$$_ResultsCopyWithImpl<_$_Results>(this, _$identity); @override @optionalTypeArgs @@ -877,40 +890,21 @@ class _$_Results implements _Results { abstract class _Results implements OpenMapState { const factory _Results( - {required SelectedLocation selected, - required String query, - required List searchResults}) = _$_Results; + {required final SelectedLocation selected, + required final String query, + required final List searchResults}) = _$_Results; @override - SelectedLocation get selected; - String get query; - List get searchResults; + SelectedLocation get selected => throw _privateConstructorUsedError; + String get query => throw _privateConstructorUsedError; + List get searchResults => + throw _privateConstructorUsedError; @override @JsonKey(ignore: true) - _$ResultsCopyWith<_Results> get copyWith => + _$$_ResultsCopyWith<_$_Results> get copyWith => throw _privateConstructorUsedError; } -/// @nodoc -class _$SelectedLocationTearOff { - const _$SelectedLocationTearOff(); - - _Single single(FormattedLocation? selected) { - return _Single( - selected, - ); - } - - _Multi multi(List selected) { - return _Multi( - selected, - ); - } -} - -/// @nodoc -const $SelectedLocation = _$SelectedLocationTearOff(); - /// @nodoc mixin _$SelectedLocation { @optionalTypeArgs @@ -971,28 +965,28 @@ class _$SelectedLocationCopyWithImpl<$Res> } /// @nodoc -abstract class _$SingleCopyWith<$Res> { - factory _$SingleCopyWith(_Single value, $Res Function(_Single) then) = - __$SingleCopyWithImpl<$Res>; +abstract class _$$_SingleCopyWith<$Res> { + factory _$$_SingleCopyWith(_$_Single value, $Res Function(_$_Single) then) = + __$$_SingleCopyWithImpl<$Res>; $Res call({FormattedLocation? selected}); $FormattedLocationCopyWith<$Res>? get selected; } /// @nodoc -class __$SingleCopyWithImpl<$Res> extends _$SelectedLocationCopyWithImpl<$Res> - implements _$SingleCopyWith<$Res> { - __$SingleCopyWithImpl(_Single _value, $Res Function(_Single) _then) - : super(_value, (v) => _then(v as _Single)); +class __$$_SingleCopyWithImpl<$Res> extends _$SelectedLocationCopyWithImpl<$Res> + implements _$$_SingleCopyWith<$Res> { + __$$_SingleCopyWithImpl(_$_Single _value, $Res Function(_$_Single) _then) + : super(_value, (v) => _then(v as _$_Single)); @override - _Single get _value => super._value as _Single; + _$_Single get _value => super._value as _$_Single; @override $Res call({ Object? selected = freezed, }) { - return _then(_Single( + return _then(_$_Single( selected == freezed ? _value.selected : selected // ignore: cast_nullable_to_non_nullable @@ -1014,22 +1008,30 @@ class __$SingleCopyWithImpl<$Res> extends _$SelectedLocationCopyWithImpl<$Res> /// @nodoc -class _$_Single implements _Single { +class _$_Single with DiagnosticableTreeMixin implements _Single { const _$_Single(this.selected); @override final FormattedLocation? selected; @override - String toString() { + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { return 'SelectedLocation.single(selected: $selected)'; } + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..add(DiagnosticsProperty('type', 'SelectedLocation.single')) + ..add(DiagnosticsProperty('selected', selected)); + } + @override bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _Single && + other is _$_Single && const DeepCollectionEquality().equals(other.selected, selected)); } @@ -1039,8 +1041,8 @@ class _$_Single implements _Single { @JsonKey(ignore: true) @override - _$SingleCopyWith<_Single> get copyWith => - __$SingleCopyWithImpl<_Single>(this, _$identity); + _$$_SingleCopyWith<_$_Single> get copyWith => + __$$_SingleCopyWithImpl<_$_Single>(this, _$identity); @override @optionalTypeArgs @@ -1106,36 +1108,37 @@ class _$_Single implements _Single { } abstract class _Single implements SelectedLocation { - const factory _Single(FormattedLocation? selected) = _$_Single; + const factory _Single(final FormattedLocation? selected) = _$_Single; - FormattedLocation? get selected; + FormattedLocation? get selected => throw _privateConstructorUsedError; @JsonKey(ignore: true) - _$SingleCopyWith<_Single> get copyWith => throw _privateConstructorUsedError; + _$$_SingleCopyWith<_$_Single> get copyWith => + throw _privateConstructorUsedError; } /// @nodoc -abstract class _$MultiCopyWith<$Res> { - factory _$MultiCopyWith(_Multi value, $Res Function(_Multi) then) = - __$MultiCopyWithImpl<$Res>; +abstract class _$$_MultiCopyWith<$Res> { + factory _$$_MultiCopyWith(_$_Multi value, $Res Function(_$_Multi) then) = + __$$_MultiCopyWithImpl<$Res>; $Res call({List selected}); } /// @nodoc -class __$MultiCopyWithImpl<$Res> extends _$SelectedLocationCopyWithImpl<$Res> - implements _$MultiCopyWith<$Res> { - __$MultiCopyWithImpl(_Multi _value, $Res Function(_Multi) _then) - : super(_value, (v) => _then(v as _Multi)); +class __$$_MultiCopyWithImpl<$Res> extends _$SelectedLocationCopyWithImpl<$Res> + implements _$$_MultiCopyWith<$Res> { + __$$_MultiCopyWithImpl(_$_Multi _value, $Res Function(_$_Multi) _then) + : super(_value, (v) => _then(v as _$_Multi)); @override - _Multi get _value => super._value as _Multi; + _$_Multi get _value => super._value as _$_Multi; @override $Res call({ Object? selected = freezed, }) { - return _then(_Multi( + return _then(_$_Multi( selected == freezed - ? _value.selected + ? _value._selected : selected // ignore: cast_nullable_to_non_nullable as List, )); @@ -1144,33 +1147,45 @@ class __$MultiCopyWithImpl<$Res> extends _$SelectedLocationCopyWithImpl<$Res> /// @nodoc -class _$_Multi implements _Multi { - const _$_Multi(this.selected); +class _$_Multi with DiagnosticableTreeMixin implements _Multi { + const _$_Multi(final List selected) : _selected = selected; + final List _selected; @override - final List selected; + List get selected { + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_selected); + } @override - String toString() { + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { return 'SelectedLocation.multi(selected: $selected)'; } + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..add(DiagnosticsProperty('type', 'SelectedLocation.multi')) + ..add(DiagnosticsProperty('selected', selected)); + } + @override bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _Multi && - const DeepCollectionEquality().equals(other.selected, selected)); + other is _$_Multi && + const DeepCollectionEquality().equals(other._selected, _selected)); } @override int get hashCode => - Object.hash(runtimeType, const DeepCollectionEquality().hash(selected)); + Object.hash(runtimeType, const DeepCollectionEquality().hash(_selected)); @JsonKey(ignore: true) @override - _$MultiCopyWith<_Multi> get copyWith => - __$MultiCopyWithImpl<_Multi>(this, _$identity); + _$$_MultiCopyWith<_$_Multi> get copyWith => + __$$_MultiCopyWithImpl<_$_Multi>(this, _$identity); @override @optionalTypeArgs @@ -1236,9 +1251,10 @@ class _$_Multi implements _Multi { } abstract class _Multi implements SelectedLocation { - const factory _Multi(List selected) = _$_Multi; + const factory _Multi(final List selected) = _$_Multi; - List get selected; + List get selected => throw _privateConstructorUsedError; @JsonKey(ignore: true) - _$MultiCopyWith<_Multi> get copyWith => throw _privateConstructorUsedError; + _$$_MultiCopyWith<_$_Multi> get copyWith => + throw _privateConstructorUsedError; } diff --git a/lib/src/location_model.dart b/lib/src/location_model.dart index 855cb6b..8d3eb7b 100644 --- a/lib/src/location_model.dart +++ b/lib/src/location_model.dart @@ -20,43 +20,43 @@ class FormattedLocation with _$FormattedLocation { /// longitude of the centroid of the object required double lon, - required String licence, + @Default('') String licence, ///reference to the OSM object - required String osmType, - required String? icon, + @Default('') String osmType, + String? icon, /// reference to the OSM object - required int osmId, + int? osmId, /// search rank of the object - required int placeRank, + int? placeRank, ///key of the main OSM tag - required String category, + @Default('') String category, /// value of the main OSM tag - required String type, + @Default('') String type, /// computed importance rank - required double importance, - required String addressType, - required String name, + double? importance, + @Default('') String addressType, + @Default('') String name, ///full comma-separated address - required String displayName, + @Default('') String displayName, /// dictionary of address details - required Address address, + @Default(Address()) Address address, /// dictionary with additional useful tags like website or max speed - required Map extratags, + @Default({}) Map extratags, /// dictionary with full list of available names including ref etc - required Map namedetails, + @Default({}) Map namedetails, ///area of corner coordinates - required LatLngBounds boundingBox, + LatLngBounds? boundingBox, /// GeoBounds of object required GeoGeometry geojson, @@ -89,12 +89,13 @@ class FormattedLocation with _$FormattedLocation { "address": address.toJson(), "extratags": extratags, "namedetails": namedetails, - "boundingbox": [ - boundingBox.southWest?.latitude, - boundingBox.northEast?.latitude, - boundingBox.southWest?.longitude, - boundingBox.northEast?.longitude - ], + if (boundingBox != null) + "boundingbox": [ + boundingBox!.southWest?.latitude, + boundingBox!.northEast?.latitude, + boundingBox!.southWest?.longitude, + boundingBox!.northEast?.longitude + ], "geojson": geojson.when( point: (latlng, _) => { "type": "Point", @@ -112,7 +113,7 @@ class FormattedLocation with _$FormattedLocation { }; } - static FormattedLocation from(Map json) { + static FormattedLocation fromJson(Map json) { if (json["error"] != null) { throw Exception(json["error"]); } @@ -128,10 +129,14 @@ class FormattedLocation with _$FormattedLocation { lon: lon, addressType: json["addresstype"] ?? '', boundingBox: LatLngBounds.fromPoints([ - LatLng(double.parse(boundingBox[0].toString()), - double.parse(boundingBox[2].toString())), - LatLng(double.parse(boundingBox[1].toString()), - double.parse(boundingBox[3].toString())), + LatLng( + double.parse(boundingBox[0].toString()), + double.parse(boundingBox[2].toString()), + ), + LatLng( + double.parse(boundingBox[1].toString()), + double.parse(boundingBox[3].toString()), + ), ]), category: json["category"] ?? '', displayName: json["display_name"] ?? '', @@ -161,15 +166,15 @@ extension LatLngExt on LatLng { } class Address { - Address({ - required this.highway, - required this.road, - required this.city, - required this.stateDistrict, - required this.state, - required this.postcode, - required this.country, - required this.countryCode, + const Address({ + this.highway = "", + this.road = "", + this.city = "", + this.stateDistrict = "", + this.state = "", + this.postcode = "", + this.country = "", + this.countryCode = "", }); final String highway; diff --git a/lib/src/location_model.freezed.dart b/lib/src/location_model.freezed.dart index 899c1c0..b64ddf2 100644 --- a/lib/src/location_model.freezed.dart +++ b/lib/src/location_model.freezed.dart @@ -1,5 +1,6 @@ // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint // ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target part of 'location_model.dart'; @@ -11,60 +12,7 @@ part of 'location_model.dart'; T _$identity(T value) => value; final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); - -/// @nodoc -class _$FormattedLocationTearOff { - const _$FormattedLocationTearOff(); - - _FormattedLocation call( - {String placeId = '', - required double lat, - required double lon, - required String licence, - required String osmType, - required String? icon, - required int osmId, - required int placeRank, - required String category, - required String type, - required double importance, - required String addressType, - required String name, - required String displayName, - required Address address, - required Map extratags, - required Map namedetails, - required LatLngBounds boundingBox, - required GeoGeometry geojson, - Map names = const {}}) { - return _FormattedLocation( - placeId: placeId, - lat: lat, - lon: lon, - licence: licence, - osmType: osmType, - icon: icon, - osmId: osmId, - placeRank: placeRank, - category: category, - type: type, - importance: importance, - addressType: addressType, - name: name, - displayName: displayName, - address: address, - extratags: extratags, - namedetails: namedetails, - boundingBox: boundingBox, - geojson: geojson, - names: names, - ); - } -} - -/// @nodoc -const $FormattedLocation = _$FormattedLocationTearOff(); + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); /// @nodoc mixin _$FormattedLocation { @@ -83,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; @@ -95,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; @@ -112,7 +60,7 @@ mixin _$FormattedLocation { Map get namedetails => throw _privateConstructorUsedError; ///area of corner coordinates - LatLngBounds get boundingBox => throw _privateConstructorUsedError; + LatLngBounds? get boundingBox => throw _privateConstructorUsedError; /// GeoBounds of object GeoGeometry get geojson => throw _privateConstructorUsedError; @@ -135,18 +83,18 @@ 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, Address address, Map extratags, Map namedetails, - LatLngBounds boundingBox, + LatLngBounds? boundingBox, GeoGeometry geojson, Map names}); @@ -213,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 @@ -229,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 @@ -257,7 +205,7 @@ class _$FormattedLocationCopyWithImpl<$Res> boundingBox: boundingBox == freezed ? _value.boundingBox : boundingBox // ignore: cast_nullable_to_non_nullable - as LatLngBounds, + as LatLngBounds?, geojson: geojson == freezed ? _value.geojson : geojson // ignore: cast_nullable_to_non_nullable @@ -278,11 +226,11 @@ class _$FormattedLocationCopyWithImpl<$Res> } /// @nodoc -abstract class _$FormattedLocationCopyWith<$Res> +abstract class _$$_FormattedLocationCopyWith<$Res> implements $FormattedLocationCopyWith<$Res> { - factory _$FormattedLocationCopyWith( - _FormattedLocation value, $Res Function(_FormattedLocation) then) = - __$FormattedLocationCopyWithImpl<$Res>; + factory _$$_FormattedLocationCopyWith(_$_FormattedLocation value, + $Res Function(_$_FormattedLocation) then) = + __$$_FormattedLocationCopyWithImpl<$Res>; @override $Res call( {String placeId, @@ -291,18 +239,18 @@ 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, Address address, Map extratags, Map namedetails, - LatLngBounds boundingBox, + LatLngBounds? boundingBox, GeoGeometry geojson, Map names}); @@ -311,15 +259,15 @@ abstract class _$FormattedLocationCopyWith<$Res> } /// @nodoc -class __$FormattedLocationCopyWithImpl<$Res> +class __$$_FormattedLocationCopyWithImpl<$Res> extends _$FormattedLocationCopyWithImpl<$Res> - implements _$FormattedLocationCopyWith<$Res> { - __$FormattedLocationCopyWithImpl( - _FormattedLocation _value, $Res Function(_FormattedLocation) _then) - : super(_value, (v) => _then(v as _FormattedLocation)); + implements _$$_FormattedLocationCopyWith<$Res> { + __$$_FormattedLocationCopyWithImpl( + _$_FormattedLocation _value, $Res Function(_$_FormattedLocation) _then) + : super(_value, (v) => _then(v as _$_FormattedLocation)); @override - _FormattedLocation get _value => super._value as _FormattedLocation; + _$_FormattedLocation get _value => super._value as _$_FormattedLocation; @override $Res call({ @@ -344,7 +292,7 @@ class __$FormattedLocationCopyWithImpl<$Res> Object? geojson = freezed, Object? names = freezed, }) { - return _then(_FormattedLocation( + return _then(_$_FormattedLocation( placeId: placeId == freezed ? _value.placeId : placeId // ignore: cast_nullable_to_non_nullable @@ -372,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 @@ -388,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 @@ -406,23 +354,23 @@ class __$FormattedLocationCopyWithImpl<$Res> : address // ignore: cast_nullable_to_non_nullable as Address, extratags: extratags == freezed - ? _value.extratags + ? _value._extratags : extratags // ignore: cast_nullable_to_non_nullable as Map, namedetails: namedetails == freezed - ? _value.namedetails + ? _value._namedetails : namedetails // ignore: cast_nullable_to_non_nullable as Map, boundingBox: boundingBox == freezed ? _value.boundingBox : boundingBox // ignore: cast_nullable_to_non_nullable - as LatLngBounds, + as LatLngBounds?, geojson: geojson == freezed ? _value.geojson : geojson // ignore: cast_nullable_to_non_nullable as GeoGeometry, names: names == freezed - ? _value.names + ? _value._names : names // ignore: cast_nullable_to_non_nullable as Map, )); @@ -436,103 +384,131 @@ class _$_FormattedLocation extends _FormattedLocation { {this.placeId = '', required this.lat, required this.lon, - required this.licence, - required this.osmType, - required this.icon, - 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 this.extratags, - required this.namedetails, - required this.boundingBox, + this.licence = '', + 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.geojson, - this.names = const {}}) - : super._(); - - @JsonKey() - @override + final Map names = const {}}) + : _extratags = extratags, + _namedetails = namedetails, + _names = names, + super._(); ///reference to the Nominatim internal database ID - final String placeId; @override + @JsonKey() + final String placeId; /// latitude of the centroid of the object - final double lat; @override + final double lat; /// longitude of the centroid of the object + @override final double lon; @override + @JsonKey() final String licence; - @override ///reference to the OSM object + @override + @JsonKey() final String osmType; @override final String? icon; - @override /// reference to the OSM object - final int osmId; @override + final int? osmId; /// search rank of the object - final int placeRank; @override + final int? placeRank; ///key of the main OSM tag - final String category; @override + @JsonKey() + final String category; /// value of the main OSM tag - final String type; @override + @JsonKey() + final String type; /// computed importance rank - final double importance; @override + final double? importance; + @override + @JsonKey() final String addressType; @override + @JsonKey() final String name; - @override ///full comma-separated address - final String displayName; @override + @JsonKey() + final String displayName; /// dictionary of address details - final Address address; @override + @JsonKey() + final Address address; + + /// dictionary with additional useful tags like website or max speed + final Map _extratags; /// dictionary with additional useful tags like website or max speed - final Map extratags; @override + @JsonKey() + Map get extratags { + // ignore: implicit_dynamic_type + return EqualUnmodifiableMapView(_extratags); + } + + /// dictionary with full list of available names including ref etc + final Map _namedetails; /// dictionary with full list of available names including ref etc - final Map namedetails; @override + @JsonKey() + Map get namedetails { + // ignore: implicit_dynamic_type + return EqualUnmodifiableMapView(_namedetails); + } ///area of corner coordinates - final LatLngBounds boundingBox; @override + final LatLngBounds? boundingBox; /// GeoBounds of object + @override final GeoGeometry geojson; - @JsonKey() + final Map _names; @override - final Map names; + @JsonKey() + Map get names { + // ignore: implicit_dynamic_type + return EqualUnmodifiableMapView(_names); + } @override bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _FormattedLocation && + other is _$_FormattedLocation && const DeepCollectionEquality().equals(other.placeId, placeId) && const DeepCollectionEquality().equals(other.lat, lat) && const DeepCollectionEquality().equals(other.lon, lon) && @@ -551,13 +527,14 @@ class _$_FormattedLocation extends _FormattedLocation { const DeepCollectionEquality() .equals(other.displayName, displayName) && const DeepCollectionEquality().equals(other.address, address) && - const DeepCollectionEquality().equals(other.extratags, extratags) && const DeepCollectionEquality() - .equals(other.namedetails, namedetails) && + .equals(other._extratags, _extratags) && + const DeepCollectionEquality() + .equals(other._namedetails, _namedetails) && const DeepCollectionEquality() .equals(other.boundingBox, boundingBox) && const DeepCollectionEquality().equals(other.geojson, geojson) && - const DeepCollectionEquality().equals(other.names, names)); + const DeepCollectionEquality().equals(other._names, _names)); } @override @@ -578,152 +555,123 @@ class _$_FormattedLocation extends _FormattedLocation { const DeepCollectionEquality().hash(name), const DeepCollectionEquality().hash(displayName), const DeepCollectionEquality().hash(address), - const DeepCollectionEquality().hash(extratags), - const DeepCollectionEquality().hash(namedetails), + const DeepCollectionEquality().hash(_extratags), + const DeepCollectionEquality().hash(_namedetails), const DeepCollectionEquality().hash(boundingBox), const DeepCollectionEquality().hash(geojson), - const DeepCollectionEquality().hash(names) + const DeepCollectionEquality().hash(_names) ]); @JsonKey(ignore: true) @override - _$FormattedLocationCopyWith<_FormattedLocation> get copyWith => - __$FormattedLocationCopyWithImpl<_FormattedLocation>(this, _$identity); + _$$_FormattedLocationCopyWith<_$_FormattedLocation> get copyWith => + __$$_FormattedLocationCopyWithImpl<_$_FormattedLocation>( + this, _$identity); } abstract class _FormattedLocation extends FormattedLocation { const factory _FormattedLocation( - {String placeId, - required double lat, - required double lon, - required String licence, - required String osmType, - required String? icon, - required int osmId, - required int placeRank, - required String category, - required String type, - required double importance, - required String addressType, - required String name, - required String displayName, - required Address address, - required Map extratags, - required Map namedetails, - required LatLngBounds boundingBox, - required GeoGeometry geojson, - Map names}) = _$_FormattedLocation; + {final String placeId, + required final double lat, + required final double lon, + final String licence, + 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 GeoGeometry geojson, + final Map names}) = _$_FormattedLocation; const _FormattedLocation._() : super._(); @override ///reference to the Nominatim internal database ID - String get placeId; + String get placeId => throw _privateConstructorUsedError; @override /// latitude of the centroid of the object - double get lat; + double get lat => throw _privateConstructorUsedError; @override /// longitude of the centroid of the object - double get lon; + double get lon => throw _privateConstructorUsedError; @override - String get licence; + String get licence => throw _privateConstructorUsedError; @override ///reference to the OSM object - String get osmType; + String get osmType => throw _privateConstructorUsedError; @override - String? get icon; + String? get icon => throw _privateConstructorUsedError; @override /// reference to the OSM object - int get osmId; + int? get osmId => throw _privateConstructorUsedError; @override /// search rank of the object - int get placeRank; + int? get placeRank => throw _privateConstructorUsedError; @override ///key of the main OSM tag - String get category; + String get category => throw _privateConstructorUsedError; @override /// value of the main OSM tag - String get type; + String get type => throw _privateConstructorUsedError; @override /// computed importance rank - double get importance; + double? get importance => throw _privateConstructorUsedError; @override - String get addressType; + String get addressType => throw _privateConstructorUsedError; @override - String get name; + String get name => throw _privateConstructorUsedError; @override ///full comma-separated address - String get displayName; + String get displayName => throw _privateConstructorUsedError; @override /// dictionary of address details - Address get address; + Address get address => throw _privateConstructorUsedError; @override /// dictionary with additional useful tags like website or max speed - Map get extratags; + Map get extratags => throw _privateConstructorUsedError; @override /// dictionary with full list of available names including ref etc - Map get namedetails; + Map get namedetails => throw _privateConstructorUsedError; @override ///area of corner coordinates - LatLngBounds get boundingBox; + LatLngBounds? get boundingBox => throw _privateConstructorUsedError; @override /// GeoBounds of object - GeoGeometry get geojson; + GeoGeometry get geojson => throw _privateConstructorUsedError; @override - Map get names; + Map get names => throw _privateConstructorUsedError; @override @JsonKey(ignore: true) - _$FormattedLocationCopyWith<_FormattedLocation> get copyWith => + _$$_FormattedLocationCopyWith<_$_FormattedLocation> get copyWith => throw _privateConstructorUsedError; } -/// @nodoc -class _$GeoGeometryTearOff { - const _$GeoGeometryTearOff(); - - GeoPoint point(LatLng point, Color randomColor) { - return GeoPoint( - point, - randomColor, - ); - } - - GeoLinestring linestring(List points, Color randomColor) { - return GeoLinestring( - points, - randomColor, - ); - } - - GeoPolygon polygon(List points, Color randomColor) { - return GeoPolygon( - points, - randomColor, - ); - } -} - -/// @nodoc -const $GeoGeometry = _$GeoGeometryTearOff(); - /// @nodoc mixin _$GeoGeometry { Color get randomColor => throw _privateConstructorUsedError; - @optionalTypeArgs TResult when({ required TResult Function(LatLng point, Color randomColor) point, @@ -805,28 +753,29 @@ class _$GeoGeometryCopyWithImpl<$Res> implements $GeoGeometryCopyWith<$Res> { } /// @nodoc -abstract class $GeoPointCopyWith<$Res> implements $GeoGeometryCopyWith<$Res> { - factory $GeoPointCopyWith(GeoPoint value, $Res Function(GeoPoint) then) = - _$GeoPointCopyWithImpl<$Res>; +abstract class _$$GeoPointCopyWith<$Res> implements $GeoGeometryCopyWith<$Res> { + factory _$$GeoPointCopyWith( + _$GeoPoint value, $Res Function(_$GeoPoint) then) = + __$$GeoPointCopyWithImpl<$Res>; @override $Res call({LatLng point, Color randomColor}); } /// @nodoc -class _$GeoPointCopyWithImpl<$Res> extends _$GeoGeometryCopyWithImpl<$Res> - implements $GeoPointCopyWith<$Res> { - _$GeoPointCopyWithImpl(GeoPoint _value, $Res Function(GeoPoint) _then) - : super(_value, (v) => _then(v as GeoPoint)); +class __$$GeoPointCopyWithImpl<$Res> extends _$GeoGeometryCopyWithImpl<$Res> + implements _$$GeoPointCopyWith<$Res> { + __$$GeoPointCopyWithImpl(_$GeoPoint _value, $Res Function(_$GeoPoint) _then) + : super(_value, (v) => _then(v as _$GeoPoint)); @override - GeoPoint get _value => super._value as GeoPoint; + _$GeoPoint get _value => super._value as _$GeoPoint; @override $Res call({ Object? point = freezed, Object? randomColor = freezed, }) { - return _then(GeoPoint( + return _then(_$GeoPoint( point == freezed ? _value.point : point // ignore: cast_nullable_to_non_nullable @@ -858,7 +807,7 @@ class _$GeoPoint extends GeoPoint { bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is GeoPoint && + other is _$GeoPoint && const DeepCollectionEquality().equals(other.point, point) && const DeepCollectionEquality() .equals(other.randomColor, randomColor)); @@ -872,8 +821,8 @@ class _$GeoPoint extends GeoPoint { @JsonKey(ignore: true) @override - $GeoPointCopyWith get copyWith => - _$GeoPointCopyWithImpl(this, _$identity); + _$$GeoPointCopyWith<_$GeoPoint> get copyWith => + __$$GeoPointCopyWithImpl<_$GeoPoint>(this, _$identity); @override @optionalTypeArgs @@ -946,46 +895,47 @@ class _$GeoPoint extends GeoPoint { } abstract class GeoPoint extends GeoGeometry { - factory GeoPoint(LatLng point, Color randomColor) = _$GeoPoint; + factory GeoPoint(final LatLng point, final Color randomColor) = _$GeoPoint; GeoPoint._() : super._(); - LatLng get point; + LatLng get point => throw _privateConstructorUsedError; @override - Color get randomColor; + Color get randomColor => throw _privateConstructorUsedError; @override @JsonKey(ignore: true) - $GeoPointCopyWith get copyWith => + _$$GeoPointCopyWith<_$GeoPoint> get copyWith => throw _privateConstructorUsedError; } /// @nodoc -abstract class $GeoLinestringCopyWith<$Res> +abstract class _$$GeoLinestringCopyWith<$Res> implements $GeoGeometryCopyWith<$Res> { - factory $GeoLinestringCopyWith( - GeoLinestring value, $Res Function(GeoLinestring) then) = - _$GeoLinestringCopyWithImpl<$Res>; + factory _$$GeoLinestringCopyWith( + _$GeoLinestring value, $Res Function(_$GeoLinestring) then) = + __$$GeoLinestringCopyWithImpl<$Res>; @override $Res call({List points, Color randomColor}); } /// @nodoc -class _$GeoLinestringCopyWithImpl<$Res> extends _$GeoGeometryCopyWithImpl<$Res> - implements $GeoLinestringCopyWith<$Res> { - _$GeoLinestringCopyWithImpl( - GeoLinestring _value, $Res Function(GeoLinestring) _then) - : super(_value, (v) => _then(v as GeoLinestring)); +class __$$GeoLinestringCopyWithImpl<$Res> + extends _$GeoGeometryCopyWithImpl<$Res> + implements _$$GeoLinestringCopyWith<$Res> { + __$$GeoLinestringCopyWithImpl( + _$GeoLinestring _value, $Res Function(_$GeoLinestring) _then) + : super(_value, (v) => _then(v as _$GeoLinestring)); @override - GeoLinestring get _value => super._value as GeoLinestring; + _$GeoLinestring get _value => super._value as _$GeoLinestring; @override $Res call({ Object? points = freezed, Object? randomColor = freezed, }) { - return _then(GeoLinestring( + return _then(_$GeoLinestring( points == freezed - ? _value.points + ? _value._points : points // ignore: cast_nullable_to_non_nullable as List, randomColor == freezed @@ -999,10 +949,17 @@ class _$GeoLinestringCopyWithImpl<$Res> extends _$GeoGeometryCopyWithImpl<$Res> /// @nodoc class _$GeoLinestring extends GeoLinestring { - _$GeoLinestring(this.points, this.randomColor) : super._(); + _$GeoLinestring(final List points, this.randomColor) + : _points = points, + super._(); + final List _points; @override - final List points; + List get points { + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_points); + } + @override final Color randomColor; @@ -1015,8 +972,8 @@ class _$GeoLinestring extends GeoLinestring { bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is GeoLinestring && - const DeepCollectionEquality().equals(other.points, points) && + other is _$GeoLinestring && + const DeepCollectionEquality().equals(other._points, _points) && const DeepCollectionEquality() .equals(other.randomColor, randomColor)); } @@ -1024,13 +981,13 @@ class _$GeoLinestring extends GeoLinestring { @override int get hashCode => Object.hash( runtimeType, - const DeepCollectionEquality().hash(points), + const DeepCollectionEquality().hash(_points), const DeepCollectionEquality().hash(randomColor)); @JsonKey(ignore: true) @override - $GeoLinestringCopyWith get copyWith => - _$GeoLinestringCopyWithImpl(this, _$identity); + _$$GeoLinestringCopyWith<_$GeoLinestring> get copyWith => + __$$GeoLinestringCopyWithImpl<_$GeoLinestring>(this, _$identity); @override @optionalTypeArgs @@ -1103,45 +1060,47 @@ class _$GeoLinestring extends GeoLinestring { } abstract class GeoLinestring extends GeoGeometry { - factory GeoLinestring(List points, Color randomColor) = + factory GeoLinestring(final List points, final Color randomColor) = _$GeoLinestring; GeoLinestring._() : super._(); - List get points; + List get points => throw _privateConstructorUsedError; @override - Color get randomColor; + Color get randomColor => throw _privateConstructorUsedError; @override @JsonKey(ignore: true) - $GeoLinestringCopyWith get copyWith => + _$$GeoLinestringCopyWith<_$GeoLinestring> get copyWith => throw _privateConstructorUsedError; } /// @nodoc -abstract class $GeoPolygonCopyWith<$Res> implements $GeoGeometryCopyWith<$Res> { - factory $GeoPolygonCopyWith( - GeoPolygon value, $Res Function(GeoPolygon) then) = - _$GeoPolygonCopyWithImpl<$Res>; +abstract class _$$GeoPolygonCopyWith<$Res> + implements $GeoGeometryCopyWith<$Res> { + factory _$$GeoPolygonCopyWith( + _$GeoPolygon value, $Res Function(_$GeoPolygon) then) = + __$$GeoPolygonCopyWithImpl<$Res>; @override $Res call({List points, Color randomColor}); } /// @nodoc -class _$GeoPolygonCopyWithImpl<$Res> extends _$GeoGeometryCopyWithImpl<$Res> - implements $GeoPolygonCopyWith<$Res> { - _$GeoPolygonCopyWithImpl(GeoPolygon _value, $Res Function(GeoPolygon) _then) - : super(_value, (v) => _then(v as GeoPolygon)); +class __$$GeoPolygonCopyWithImpl<$Res> extends _$GeoGeometryCopyWithImpl<$Res> + implements _$$GeoPolygonCopyWith<$Res> { + __$$GeoPolygonCopyWithImpl( + _$GeoPolygon _value, $Res Function(_$GeoPolygon) _then) + : super(_value, (v) => _then(v as _$GeoPolygon)); @override - GeoPolygon get _value => super._value as GeoPolygon; + _$GeoPolygon get _value => super._value as _$GeoPolygon; @override $Res call({ Object? points = freezed, Object? randomColor = freezed, }) { - return _then(GeoPolygon( + return _then(_$GeoPolygon( points == freezed - ? _value.points + ? _value._points : points // ignore: cast_nullable_to_non_nullable as List, randomColor == freezed @@ -1155,10 +1114,17 @@ class _$GeoPolygonCopyWithImpl<$Res> extends _$GeoGeometryCopyWithImpl<$Res> /// @nodoc class _$GeoPolygon extends GeoPolygon { - _$GeoPolygon(this.points, this.randomColor) : super._(); + _$GeoPolygon(final List points, this.randomColor) + : _points = points, + super._(); + final List _points; @override - final List points; + List get points { + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_points); + } + @override final Color randomColor; @@ -1171,8 +1137,8 @@ class _$GeoPolygon extends GeoPolygon { bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is GeoPolygon && - const DeepCollectionEquality().equals(other.points, points) && + other is _$GeoPolygon && + const DeepCollectionEquality().equals(other._points, _points) && const DeepCollectionEquality() .equals(other.randomColor, randomColor)); } @@ -1180,13 +1146,13 @@ class _$GeoPolygon extends GeoPolygon { @override int get hashCode => Object.hash( runtimeType, - const DeepCollectionEquality().hash(points), + const DeepCollectionEquality().hash(_points), const DeepCollectionEquality().hash(randomColor)); @JsonKey(ignore: true) @override - $GeoPolygonCopyWith get copyWith => - _$GeoPolygonCopyWithImpl(this, _$identity); + _$$GeoPolygonCopyWith<_$GeoPolygon> get copyWith => + __$$GeoPolygonCopyWithImpl<_$GeoPolygon>(this, _$identity); @override @optionalTypeArgs @@ -1259,14 +1225,15 @@ class _$GeoPolygon extends GeoPolygon { } abstract class GeoPolygon extends GeoGeometry { - factory GeoPolygon(List points, Color randomColor) = _$GeoPolygon; + factory GeoPolygon(final List points, final Color randomColor) = + _$GeoPolygon; GeoPolygon._() : super._(); - List get points; + List get points => throw _privateConstructorUsedError; @override - Color get randomColor; + Color get randomColor => throw _privateConstructorUsedError; @override @JsonKey(ignore: true) - $GeoPolygonCopyWith get copyWith => + _$$GeoPolygonCopyWith<_$GeoPolygon> get copyWith => throw _privateConstructorUsedError; } diff --git a/lib/src/location_picker_field.dart b/lib/src/location_picker_field.dart index 24ebdbb..95ed6e8 100644 --- a/lib/src/location_picker_field.dart +++ b/lib/src/location_picker_field.dart @@ -103,12 +103,12 @@ class __BaseFormFieldState extends State<_BaseFormField> { var effectiveDecoration = widget.decoration .applyDefaults(Theme.of(context).inputDecorationTheme); var removeIcon = widget.removeIcon; - var _showRemove = !widget.isEmpty(field.value) && removeIcon != null; + var showRemove = !widget.isEmpty(field.value) && removeIcon != null; effectiveDecoration = effectiveDecoration.copyWith( errorText: field.errorText, prefixIcon: effectiveDecoration.prefixIcon ?? const Icon(Icons.my_location_rounded), - suffixIcon: _showRemove + suffixIcon: showRemove ? IconButton( onPressed: () { widget.onRemove(field); @@ -151,14 +151,14 @@ class __BaseFormFieldState extends State<_BaseFormField> { void _pick(FormFieldState field) async { var context = field.context; - var _bloc = _OpenMapBloc(widget.state(field.value)); + var bloc = _OpenMapBloc(widget.state(field.value)); try { await Navigator.push( context, MaterialPageRoute( builder: (_) => OpenStreetMaps( options: widget.options(field.value), - bloc: _bloc, + bloc: bloc, onDone: (value) { widget.onDone.call(field, value); Navigator.of(_).pop(); @@ -166,12 +166,12 @@ class __BaseFormFieldState extends State<_BaseFormField> { ), ), ); - _bloc.close(); + bloc.close(); } catch (e) { if (mounted) { OpenMapSettings.of(context)?.onError?.call(context, e); } - _bloc.close(); + bloc.close(); } } } @@ -221,11 +221,11 @@ class OpenMapPicker extends StatelessWidget { focusNode: focusNode, initialValue: initialValue, options: (FormattedLocation? value) { - if (value == null) { + if (value == null || value.boundingBox == null) { return options ?? OpenMapOptions(); } else { - return options?.copyWithBounds(bounds: value.boundingBox) ?? - OpenMapOptions.bounds(bounds: value.boundingBox); + return options?.copyWithBounds(bounds: value.boundingBox!) ?? + OpenMapOptions.bounds(bounds: value.boundingBox!); } }, onDone: (field, value) { diff --git a/lib/src/map_app_bar.dart b/lib/src/map_app_bar.dart index 7e1a561..1b220fb 100644 --- a/lib/src/map_app_bar.dart +++ b/lib/src/map_app_bar.dart @@ -47,7 +47,7 @@ class _MapAppBarState extends State { widget.bloc.emit(OpenMapState.selected(state.selected)); return; } - var _q = q; + var query = q; timer = Timer(const Duration(milliseconds: 700), () async { var oldResults = state.maybeWhen( @@ -59,7 +59,7 @@ class _MapAppBarState extends State { try { widget.bloc.emit(OpenMapState.searching( selected: state.selected, - query: _q, + query: query, oldResults: oldResults, )); Locale locale = Localizations.localeOf(context); @@ -67,11 +67,11 @@ class _MapAppBarState extends State { var results = await widget.bloc.search( locale: locale, searchFilters: widget.searchFilters, - query: _q, + query: query, ); widget.bloc.emit(OpenMapState.results( selected: state.selected, - query: _q, + query: query, searchResults: results, )); } catch (e) { diff --git a/lib/src/map_view.dart b/lib/src/map_view.dart index bfed0e9..7c12eef 100644 --- a/lib/src/map_view.dart +++ b/lib/src/map_view.dart @@ -78,7 +78,7 @@ class OpenStreetMaps extends StatefulWidget { }) : super(key: key); @override - _OpenStreetMapsState createState() => _OpenStreetMapsState(); + State createState() => _OpenStreetMapsState(); } class _OpenStreetMapsState extends State @@ -95,10 +95,10 @@ class _OpenStreetMapsState extends State void _onTap(LatLng latLng) async { var bloc = widget.bloc; if (bloc != null) { - var _oldState = bloc.state; - var _reversing = OpenMapState.reversing(bloc.state.selected, latLng); + var oldState = bloc.state; + var reversing = OpenMapState.reversing(bloc.state.selected, latLng); try { - bloc.emit(_reversing); + bloc.emit(reversing); var settings = OpenMapSettings.of(context); Locale locale = Localizations.localeOf(context); var zoom = (widget.reverseZoom ?? settings?.reverseZoom); @@ -107,27 +107,29 @@ class _OpenStreetMapsState extends State location: latLng, zoom: zoom, ); - _reversing.selected.when( + reversing.selected.when( single: (sub) { bloc.emit(OpenMapState.selected(SelectedLocation.single(result))); }, multi: (old) { var exists = old.any((element) => element.identifier == result.identifier); - var _new = exists + var newList = exists ? old .map((e) => e.identifier == result.identifier ? result : e) .toList() : [result, ...old]; - bloc.emit(OpenMapState.selected(SelectedLocation.multi(_new))); + bloc.emit(OpenMapState.selected(SelectedLocation.multi(newList))); }, ); - fitBounds(result.boundingBox); + if (result.boundingBox != null) { + fitBounds(result.boundingBox!); + } } catch (e) { if (mounted) { OpenMapSettings.of(context)?.onError?.call(context, e); } - bloc.emit(_oldState); + bloc.emit(oldState); } } } @@ -154,15 +156,15 @@ class _OpenStreetMapsState extends State void moveTo(LatLng destLocation, [double destZoom = 13]) { try { - final _latTween = Tween( + final latTween = Tween( begin: _controller.center.latitude, end: destLocation.latitude, ); - final _lngTween = Tween( + final lngTween = Tween( begin: _controller.center.longitude, end: destLocation.longitude, ); - final _zoomTween = Tween( + final zoomTween = Tween( begin: _controller.zoom, end: destZoom, ); @@ -175,9 +177,8 @@ class _OpenStreetMapsState extends State _animationController.addListener(() { if (mounted) { _controller.move( - LatLng( - _latTween.evaluate(animation), _lngTween.evaluate(animation)), - _zoomTween.evaluate(animation), + LatLng(latTween.evaluate(animation), lngTween.evaluate(animation)), + zoomTween.evaluate(animation), ); } }); @@ -215,10 +216,10 @@ class _OpenStreetMapsState extends State @override Widget build(BuildContext context) { var settings = OpenMapSettings.of(context); - Widget? _myCurrentLocation = widget.myLocationButton?.call(moveTo); - _myCurrentLocation ??= settings?.myLocationButton?.call(moveTo); - if (_myCurrentLocation == null && settings?.getCurrentLocation != null) { - _myCurrentLocation = MyLocationButton( + Widget? myCurrentLocation = widget.myLocationButton?.call(moveTo); + myCurrentLocation ??= settings?.myLocationButton?.call(moveTo); + if (myCurrentLocation == null && settings?.getCurrentLocation != null) { + myCurrentLocation = MyLocationButton( moveTo: moveTo, selectCurrentLocationIcon: settings?.mapViewConfig?.selectCurrentLocationIcon, @@ -250,9 +251,12 @@ class _OpenStreetMapsState extends State settings?.searchHint?.call(context) ?? 'Search here', ), - bottomNavigationBar: - SelectedLocationView(bloc: bloc, fitBounds: fitBounds), - floatingActionButton: _myCurrentLocation, + bottomNavigationBar: SelectedLocationView( + bloc: bloc, + fitBounds: fitBounds, + moveTo: moveTo, + ), + floatingActionButton: myCurrentLocation, resizeToAvoidBottomInset: false, body: _buildMap(options, settings), ), @@ -263,6 +267,7 @@ class _OpenStreetMapsState extends State child: SearchResults( bloc: widget.bloc!, fitBounds: fitBounds, + moveTo: moveTo, ), ) ], @@ -272,13 +277,13 @@ class _OpenStreetMapsState extends State FlutterMap _buildMap(MapOptions options, OpenMapSettings? settings) { var background = Theme.of(context).scaffoldBackgroundColor; var isDark = Theme.of(context).brightness == Brightness.dark; - var _layerOptions = settings?.getMapTileOptions ?? _getLayerOptions; + var layerOptions = settings?.getMapTileOptions ?? _getLayerOptions; return FlutterMap( options: options, mapController: _controller, children: [ TileLayerWidget( - options: _layerOptions( + options: layerOptions( isDark, background, widget.tileProvider ?? diff --git a/lib/src/markers.dart b/lib/src/markers.dart index e4d3d91..ed8bee5 100644 --- a/lib/src/markers.dart +++ b/lib/src/markers.dart @@ -13,7 +13,7 @@ class MyCurrentLocationMarker extends StatefulWidget { const MyCurrentLocationMarker({Key? key}) : super(key: key); @override - _MyCurrentLocationMarkerState createState() => + State createState() => _MyCurrentLocationMarkerState(); } diff --git a/lib/src/search_results.dart b/lib/src/search_results.dart index ba60832..f4a09a3 100644 --- a/lib/src/search_results.dart +++ b/lib/src/search_results.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; +import 'package:latlong2/latlong.dart'; import './location_model.dart'; import 'bloc.dart'; @@ -9,8 +10,13 @@ import 'bloc.dart'; class SearchResults extends StatelessWidget { final OpenMapBloc bloc; final ValueChanged fitBounds; - const SearchResults({Key? key, required this.bloc, required this.fitBounds}) - : super(key: key); + final ValueChanged moveTo; + const SearchResults({ + Key? key, + required this.bloc, + required this.fitBounds, + required this.moveTo, + }) : super(key: key); @override Widget build(BuildContext context) { @@ -62,16 +68,20 @@ class SearchResults extends StatelessWidget { multi: (old) { var exists = old .any((element) => element.identifier == loc.identifier); - var _new = exists + var newList = exists ? old .map((e) => e.identifier == loc.identifier ? loc : e) .toList() : [loc, ...old]; bloc.emit( - OpenMapState.selected(SelectedLocation.multi(_new))); + OpenMapState.selected(SelectedLocation.multi(newList))); }, ); - fitBounds(loc.boundingBox); + if (loc.boundingBox != null) { + fitBounds(loc.boundingBox!); + } else { + moveTo(LatLng(loc.lat, loc.lon)); + } }, title: Text(loc.toString()), leading: loc.icon == null diff --git a/lib/src/selected_location_view.dart b/lib/src/selected_location_view.dart index a80ce33..110b2a9 100644 --- a/lib/src/selected_location_view.dart +++ b/lib/src/selected_location_view.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; +import 'package:latlong2/latlong.dart'; import 'bloc.dart'; import 'location_model.dart'; @@ -9,10 +10,14 @@ import 'location_model.dart'; class SelectedLocationView extends StatelessWidget { final OpenMapBloc bloc; final ValueChanged fitBounds; + final ValueChanged moveTo; - const SelectedLocationView( - {Key? key, required this.bloc, required this.fitBounds}) - : super(key: key); + const SelectedLocationView({ + Key? key, + required this.bloc, + required this.fitBounds, + required this.moveTo, + }) : super(key: key); @override Widget build(BuildContext context) { @@ -83,7 +88,11 @@ class SelectedLocationView extends StatelessWidget { color: Theme.of(context).errorColor, ), onTap: () { - fitBounds(e.boundingBox); + if (e.boundingBox != null) { + fitBounds(e.boundingBox!); + } else { + moveTo(LatLng(e.lat, e.lon)); + } }, ); } diff --git a/pubspec.yaml b/pubspec.yaml index 885ac5e..9a54294 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.0 +version: 0.1.1 homepage: https://github.com/mo-ah-dawood/open_location_picker environment: @@ -10,7 +10,7 @@ environment: dependencies: flutter: sdk: flutter - flutter_map: ^0.14.0 + flutter_map: ^1.0.0 freezed_annotation: ^2.0.3 http: ^0.13.4 latlong2: ^0.8.1