Skip to content

Commit

Permalink
Implemented isPresent on Android package (#204)
Browse files Browse the repository at this point in the history
* Implemented isPresent on Android

(cherry picked from commit 472c9e7)

* fixed build
  • Loading branch information
TimHoogstrate authored Feb 16, 2024
1 parent aa902f6 commit c843c8e
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 1 deletion.
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
14 changes: 14 additions & 0 deletions geocoding_android/lib/geocoding_android.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,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

0 comments on commit c843c8e

Please sign in to comment.