From a2fb326a03b7d17fb64eccf4c4524b6a19d937a6 Mon Sep 17 00:00:00 2001 From: tim Hoogstrate Date: Fri, 16 Feb 2024 09:39:49 +0100 Subject: [PATCH 1/9] updated main package and implemented isPresent in example project --- geocoding/example/lib/main.dart | 19 +++++++++++++++++-- geocoding/lib/geocoding.dart | 26 ++++++++++++++++++++------ geocoding/pubspec.yaml | 6 +++--- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/geocoding/example/lib/main.dart b/geocoding/example/lib/main.dart index f93aefa..d9dc508 100644 --- a/geocoding/example/lib/main.dart +++ b/geocoding/example/lib/main.dart @@ -78,7 +78,7 @@ class _GeocodeWidgetState extends State { final longitude = double.parse(_longitudeController.text); placemarkFromCoordinates(latitude, longitude) - .then((placemarks) { + ?.then((placemarks) { var output = 'No results found.'; if (placemarks.isNotEmpty) { output = placemarks[0].toString(); @@ -110,7 +110,7 @@ class _GeocodeWidgetState extends State { child: Text('Look up location'), onPressed: () { locationFromAddress(_addressController.text) - .then((locations) { + ?.then((locations) { var output = 'No results found.'; if (locations.isNotEmpty) { output = locations[0].toString(); @@ -122,6 +122,21 @@ class _GeocodeWidgetState extends State { }); }), ), + const Padding( + padding: EdgeInsets.only(top: 8), + ), + Center( + child: ElevatedButton( + child: Text('is Present'), + onPressed: () { + isPresent()?.then((isPresent) { + var output = isPresent ? 'Is present' : 'Is not present'; + setState(() { + _output = output; + }); + }); + }), + ), Expanded( child: SingleChildScrollView( child: Container( diff --git a/geocoding/lib/geocoding.dart b/geocoding/lib/geocoding.dart index eec7c4b..383947e 100644 --- a/geocoding/lib/geocoding.dart +++ b/geocoding/lib/geocoding.dart @@ -15,13 +15,12 @@ export 'package:geocoding_platform_interface/geocoding_platform_interface.dart'; /// When not supplied the currently active locale of the device will be used. /// The `localeIdentifier` should be formatted using the syntax: /// [languageCode]_[countryCode] (eg. en_US or nl_NL). -Future> locationFromAddress( +Future>? locationFromAddress( String address, { String? localeIdentifier, }) => - GeocodingPlatform.instance.locationFromAddress( + GeocodingPlatform.instance?.locationFromAddress( address, - localeIdentifier: localeIdentifier, ); /// Returns a list of [Placemark] instances found for the supplied @@ -36,13 +35,28 @@ Future> locationFromAddress( /// When not supplied the currently active locale of the device will be used. /// The `localeIdentifier` should be formatted using the syntax: /// [languageCode]_[countryCode] (eg. en_US or nl_NL). -Future> placemarkFromCoordinates( +Future>? placemarkFromCoordinates( double latitude, double longitude, { String? localeIdentifier, }) => - GeocodingPlatform.instance.placemarkFromCoordinates( + GeocodingPlatform.instance?.placemarkFromCoordinates( latitude, longitude, - localeIdentifier: localeIdentifier, ); + +/// Returns a list of [Location] instances found for the supplied address. +/// +/// In most situations the returned list should only contain one entry. +/// However in some situations where the supplied address could not be +/// resolved into a single [Location], multiple [Location] instances may be +/// returned. +/// +/// Optionally you can specify a locale in which the results are returned. +/// When not supplied the currently active locale of the device will be used. +/// The `localeIdentifier` should be formatted using the syntax: +/// [languageCode]_[countryCode] (eg. en_US or nl_NL). +Future? isPresent({ + String? localeIdentifier, +}) => + GeocodingPlatform.instance?.isPresent(); diff --git a/geocoding/pubspec.yaml b/geocoding/pubspec.yaml index ce02e39..9ac24f7 100644 --- a/geocoding/pubspec.yaml +++ b/geocoding/pubspec.yaml @@ -12,9 +12,9 @@ dependencies: flutter: sdk: flutter - geocoding_platform_interface: ^2.0.0 - geocoding_android: ^2.1.0 - geocoding_ios: ^2.1.0 + geocoding_platform_interface: ^3.0.0 + geocoding_android: ^3.0.0 + geocoding_ios: ^2.0.0 dev_dependencies: flutter_test: From 30b3f033e9346863e7e8ec4541a25799eaad7f9e Mon Sep 17 00:00:00 2001 From: tim Hoogstrate Date: Fri, 16 Feb 2024 09:48:18 +0100 Subject: [PATCH 2/9] updated tests --- geocoding/test/geocoding_test.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/geocoding/test/geocoding_test.dart b/geocoding/test/geocoding_test.dart index 752892a..9ace918 100644 --- a/geocoding/test/geocoding_test.dart +++ b/geocoding/test/geocoding_test.dart @@ -9,7 +9,7 @@ final mockLocation = Location( timestamp: DateTime.fromMillisecondsSinceEpoch(0).toUtc(), ); -final mockPlacemark = Placemark( +const mockPlacemark = Placemark( administrativeArea: 'Overijssel', country: 'Netherlands', isoCountryCode: 'NL', @@ -30,12 +30,12 @@ void main() { test('locationFromAddress', () async { final locations = await (locationFromAddress('')); - expect(locations.single, mockLocation); + expect(locations?.single, mockLocation); }); test('placemarkFromCoordinates', () async { final placemarks = await (placemarkFromCoordinates(0, 0)); - expect(placemarks.single, mockPlacemark); + expect(placemarks?.single, mockPlacemark); }); }); } From bb824afb60018f7a1a4ee49603720f6551da81aa Mon Sep 17 00:00:00 2001 From: TimHoogstrate Date: Tue, 20 Feb 2024 08:33:33 +0100 Subject: [PATCH 3/9] Update geocoding/lib/geocoding.dart Co-authored-by: Maurits van Beusekom --- geocoding/lib/geocoding.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geocoding/lib/geocoding.dart b/geocoding/lib/geocoding.dart index 383947e..c382897 100644 --- a/geocoding/lib/geocoding.dart +++ b/geocoding/lib/geocoding.dart @@ -19,7 +19,7 @@ Future>? locationFromAddress( String address, { String? localeIdentifier, }) => - GeocodingPlatform.instance?.locationFromAddress( + GeocodingPlatform.instance!.locationFromAddress( address, ); From beb2fd36d558e476ceb5c336dc1b71283316ea99 Mon Sep 17 00:00:00 2001 From: TimHoogstrate Date: Tue, 20 Feb 2024 08:33:39 +0100 Subject: [PATCH 4/9] Update geocoding/lib/geocoding.dart Co-authored-by: Maurits van Beusekom --- geocoding/lib/geocoding.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geocoding/lib/geocoding.dart b/geocoding/lib/geocoding.dart index c382897..10f208e 100644 --- a/geocoding/lib/geocoding.dart +++ b/geocoding/lib/geocoding.dart @@ -59,4 +59,4 @@ Future>? placemarkFromCoordinates( Future? isPresent({ String? localeIdentifier, }) => - GeocodingPlatform.instance?.isPresent(); + GeocodingPlatform.instance!.isPresent(); From f2eb3dc9bcc063aa0c2239fa1b1e74a74afda7e5 Mon Sep 17 00:00:00 2001 From: TimHoogstrate Date: Tue, 20 Feb 2024 08:33:47 +0100 Subject: [PATCH 5/9] Update geocoding/lib/geocoding.dart Co-authored-by: Maurits van Beusekom --- geocoding/lib/geocoding.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geocoding/lib/geocoding.dart b/geocoding/lib/geocoding.dart index 10f208e..89472dd 100644 --- a/geocoding/lib/geocoding.dart +++ b/geocoding/lib/geocoding.dart @@ -35,7 +35,7 @@ Future>? locationFromAddress( /// When not supplied the currently active locale of the device will be used. /// The `localeIdentifier` should be formatted using the syntax: /// [languageCode]_[countryCode] (eg. en_US or nl_NL). -Future>? placemarkFromCoordinates( +Future> placemarkFromCoordinates( double latitude, double longitude, { String? localeIdentifier, From 02aa2e752515cb069ef2ed1e20ae54aec0599e22 Mon Sep 17 00:00:00 2001 From: TimHoogstrate Date: Tue, 20 Feb 2024 08:33:53 +0100 Subject: [PATCH 6/9] Update geocoding/lib/geocoding.dart Co-authored-by: Maurits van Beusekom --- geocoding/lib/geocoding.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geocoding/lib/geocoding.dart b/geocoding/lib/geocoding.dart index 89472dd..540df5c 100644 --- a/geocoding/lib/geocoding.dart +++ b/geocoding/lib/geocoding.dart @@ -40,7 +40,7 @@ Future> placemarkFromCoordinates( double longitude, { String? localeIdentifier, }) => - GeocodingPlatform.instance?.placemarkFromCoordinates( + GeocodingPlatform.instance!.placemarkFromCoordinates( latitude, longitude, ); From 16b90d57fbd46eed69c6ed2a82c105a133739c80 Mon Sep 17 00:00:00 2001 From: TimHoogstrate Date: Tue, 20 Feb 2024 08:33:59 +0100 Subject: [PATCH 7/9] Update geocoding/lib/geocoding.dart Co-authored-by: Maurits van Beusekom --- geocoding/lib/geocoding.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geocoding/lib/geocoding.dart b/geocoding/lib/geocoding.dart index 540df5c..ac0a325 100644 --- a/geocoding/lib/geocoding.dart +++ b/geocoding/lib/geocoding.dart @@ -56,7 +56,7 @@ Future> placemarkFromCoordinates( /// When not supplied the currently active locale of the device will be used. /// The `localeIdentifier` should be formatted using the syntax: /// [languageCode]_[countryCode] (eg. en_US or nl_NL). -Future? isPresent({ +Future isPresent({ String? localeIdentifier, }) => GeocodingPlatform.instance!.isPresent(); From 0bd4bf46e989e118b75d359c12d1a111f699c079 Mon Sep 17 00:00:00 2001 From: TimHoogstrate Date: Tue, 20 Feb 2024 08:34:05 +0100 Subject: [PATCH 8/9] Update geocoding/lib/geocoding.dart Co-authored-by: Maurits van Beusekom --- geocoding/lib/geocoding.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geocoding/lib/geocoding.dart b/geocoding/lib/geocoding.dart index ac0a325..df8ff63 100644 --- a/geocoding/lib/geocoding.dart +++ b/geocoding/lib/geocoding.dart @@ -15,7 +15,7 @@ export 'package:geocoding_platform_interface/geocoding_platform_interface.dart'; /// When not supplied the currently active locale of the device will be used. /// The `localeIdentifier` should be formatted using the syntax: /// [languageCode]_[countryCode] (eg. en_US or nl_NL). -Future>? locationFromAddress( +Future> locationFromAddress( String address, { String? localeIdentifier, }) => From 66889878a459b006edd45c8b3b7a24ce41e68284 Mon Sep 17 00:00:00 2001 From: tim Hoogstrate Date: Tue, 20 Feb 2024 08:51:38 +0100 Subject: [PATCH 9/9] Removed optionals --- geocoding/example/lib/main.dart | 7 +++---- geocoding/test/geocoding_test.dart | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/geocoding/example/lib/main.dart b/geocoding/example/lib/main.dart index d9dc508..20f4290 100644 --- a/geocoding/example/lib/main.dart +++ b/geocoding/example/lib/main.dart @@ -78,7 +78,7 @@ class _GeocodeWidgetState extends State { final longitude = double.parse(_longitudeController.text); placemarkFromCoordinates(latitude, longitude) - ?.then((placemarks) { + .then((placemarks) { var output = 'No results found.'; if (placemarks.isNotEmpty) { output = placemarks[0].toString(); @@ -110,12 +110,11 @@ class _GeocodeWidgetState extends State { child: Text('Look up location'), onPressed: () { locationFromAddress(_addressController.text) - ?.then((locations) { + .then((locations) { var output = 'No results found.'; if (locations.isNotEmpty) { output = locations[0].toString(); } - setState(() { _output = output; }); @@ -129,7 +128,7 @@ class _GeocodeWidgetState extends State { child: ElevatedButton( child: Text('is Present'), onPressed: () { - isPresent()?.then((isPresent) { + isPresent().then((isPresent) { var output = isPresent ? 'Is present' : 'Is not present'; setState(() { _output = output; diff --git a/geocoding/test/geocoding_test.dart b/geocoding/test/geocoding_test.dart index 9ace918..38f2637 100644 --- a/geocoding/test/geocoding_test.dart +++ b/geocoding/test/geocoding_test.dart @@ -30,12 +30,12 @@ void main() { test('locationFromAddress', () async { final locations = await (locationFromAddress('')); - expect(locations?.single, mockLocation); + expect(locations.single, mockLocation); }); test('placemarkFromCoordinates', () async { final placemarks = await (placemarkFromCoordinates(0, 0)); - expect(placemarks?.single, mockPlacemark); + expect(placemarks.single, mockPlacemark); }); }); }