Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/194 expose Geocoder.isPresent Android #201

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions geocoding_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.2.0

* Exposes isPresent() call that returns true if there is a geocoder implementation present that may return results.

## 3.1.0

* Fixes deprecation build warnings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ void setLocaleIdentifier(@Nullable Locale locale) {
this.locale = locale;
}

/**
* Returns true if there is a geocoder implementation present that may return results.
* If true, there is still no guarantee that any individual geocoding attempt will succeed.
*
*/
boolean isPresent() {
return Geocoder.isPresent();
}

/**
* Returns a list of Address objects matching the supplied address string.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public void onMethodCall(
case "placemarkFromCoordinates":
onPlacemarkFromCoordinates(call, result);
break;
case "isPresent":
onIsPresent(call, result);
break;
default:
result.notImplemented();
break;
Expand Down Expand Up @@ -203,4 +206,9 @@ public void onError(String errorMessage) {
}
});
}

private void onIsPresent(final MethodCall call, final Result result) {
boolean isPresent = geocoding.isPresent();
result.success(isPresent);
}
}
17 changes: 17 additions & 0 deletions geocoding_android/example/lib/plugin_example/geocode_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,23 @@ class _GeocodeWidgetState extends State<GeocodeWidget> {
});
}),
),
const Padding(
padding: EdgeInsets.only(top: 8),
),
Center(
child: ElevatedButton(
child: Text('Is present'),
onPressed: () {
GeocodingAndroid().isPresent().then((isPresent) {
var output = isPresent
? "Geocoder is present"
: "Geocoder is not present";
setState(() {
_output = output;
});
});
}),
),
Expanded(
child: SingleChildScrollView(
child: Container(
Expand Down
15 changes: 15 additions & 0 deletions geocoding_android/lib/geocoding_android.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:ffi';

import 'package:flutter/services.dart';
import 'package:geocoding_platform_interface/geocoding_platform_interface.dart';
Expand Down Expand Up @@ -44,6 +45,20 @@ class GeocodingAndroid extends GeocodingPlatform {
}
}

@override
Future<bool> isPresent() async {
try {
final isPresent = await _channel.invokeMethod(
'isPresent',
);

return isPresent;
} on PlatformException catch (e) {
_handlePlatformException(e);
rethrow;
}
}

@override
Future<List<Placemark>> placemarkFromCoordinates(
double latitude,
Expand Down
2 changes: 1 addition & 1 deletion geocoding_android/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: geocoding_android
description: A Flutter Geocoding plugin which provides easy geocoding and reverse-geocoding features.
version: 3.1.0
version: 3.2.0
repository: https://github.com/baseflow/flutter-geocoding/tree/main/geocoding_android
issue_tracker: https://github.com/Baseflow/flutter-geocoding/issues

Expand Down
4 changes: 4 additions & 0 deletions geocoding_ios/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.3.0

* Implements `isPresent` that always returns true.

## 2.2.0

* Updates `geocoding_platform_interface` to version 3.1.0.
Expand Down
16 changes: 16 additions & 0 deletions geocoding_ios/example/lib/plugin_example/geocode_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,22 @@ class _GeocodeWidgetState extends State<GeocodeWidget> {
});
}),
),
const Padding(
padding: EdgeInsets.only(top: 8),
),
Center(
child: ElevatedButton(
child: Text('Is present'),
onPressed: () {
GeocodingIOS().isPresent().then((isPresent) {
var output = isPresent
? "Geocoder is present"
: "Geocoder is not present";
setState(() {
_output = output;
});
});
})),
Expanded(
child: SingleChildScrollView(
child: Container(
Expand Down
5 changes: 4 additions & 1 deletion geocoding_ios/ios/Classes/GeocodingPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
message:errorDescription
details:nil]);
}];
}else {
} else if ([@"isPresent" isEqualToString:call.method]) {
//There is no equal iOS implementation of the ANDROID Geocoder.isPresent. On iOS we assume that it is always present.
result(@YES);
} else {
result(FlutterMethodNotImplemented);
}
}
Expand Down
14 changes: 14 additions & 0 deletions geocoding_ios/lib/geocoding_ios.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ class GeocodingIOS extends GeocodingPlatform {
return Placemark.fromMaps(placemarks);
}

@override
Future<bool> isPresent() async {
try {
final isPresent = await _channel.invokeMethod(
'isPresent',
);

return isPresent;
} on PlatformException catch (e) {
_handlePlatformException(e);
rethrow;
}
}

void _handlePlatformException(PlatformException platformException) {
switch (platformException.code) {
case 'NOT_FOUND':
Expand Down
2 changes: 1 addition & 1 deletion geocoding_ios/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: geocoding_ios
description: A Flutter Geocoding plugin which provides easy geocoding and reverse-geocoding features.
version: 2.2.0
version: 2.3.0
repository: https://github.com/baseflow/flutter-geocoding/tree/main/geocoding_ios
issue_tracker: https://github.com/Baseflow/flutter-geocoding/issues

Expand Down
4 changes: 4 additions & 0 deletions geocoding_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.2.0

- Adds `isPresent` method to the platform interface.

## 3.1.0

- Adds `placemarkFromAddress` method to the platform interface.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ abstract class GeocodingPlatform extends PlatformInterface {
'locationFromAddress() has not been implementated.');
}

/// Returns true if there is a geocoder implementation present that may return results.
/// If true, there is still no guarantee that any individual geocoding attempt will succeed.
///
///
/// This method is only intended on Android, calling this on iOS always
/// returns [true].
Future<bool> isPresent() {
throw UnimplementedError('isPresent() has not been implementated.');
}

/// Returns a list of [Placemark] instances found for the supplied
/// coordinates.
///
Expand Down
2 changes: 1 addition & 1 deletion geocoding_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: A common platform interface for the geocoding plugin.
homepage: https://github.com/baseflow/flutter-geocoding/tree/main/geocoding_platform_interface
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 3.1.0
version: 3.2.0

dependencies:
flutter:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ void main() {
);
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of isPresent should throw unimplemented error',
() {
// Arrange
final geocodingPlatform = ExtendsGeocodingPlatform();

// Act & Assert
expect(
() => geocodingPlatform.isPresent(),
throwsUnimplementedError,
);
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of placemarkFromCoordinates should throw unimplemented error',
Expand Down
Loading