Skip to content

Commit c843c8e

Browse files
Implemented isPresent on Android package (Baseflow#204)
* Implemented isPresent on Android (cherry picked from commit 472c9e7) * fixed build
1 parent aa902f6 commit c843c8e

File tree

6 files changed

+53
-1
lines changed

6 files changed

+53
-1
lines changed

Diff for: geocoding_android/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.2.0
2+
3+
* Exposes isPresent() call that returns true if there is a geocoder implementation present that may return results.
4+
15
## 3.1.0
26

37
* Fixes deprecation build warnings.

Diff for: geocoding_android/android/src/main/java/com/baseflow/geocoding/Geocoding.java

+9
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ void setLocaleIdentifier(@Nullable Locale locale) {
3636
this.locale = locale;
3737
}
3838

39+
/**
40+
* Returns true if there is a geocoder implementation present that may return results.
41+
* If true, there is still no guarantee that any individual geocoding attempt will succeed.
42+
*
43+
*/
44+
boolean isPresent() {
45+
return Geocoder.isPresent();
46+
}
47+
3948
/**
4049
* Returns a list of Address objects matching the supplied address string.
4150
*

Diff for: geocoding_android/android/src/main/java/com/baseflow/geocoding/MethodCallHandlerImpl.java

+8
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ public void onMethodCall(
5555
case "placemarkFromCoordinates":
5656
onPlacemarkFromCoordinates(call, result);
5757
break;
58+
case "isPresent":
59+
onIsPresent(call, result);
60+
break;
5861
default:
5962
result.notImplemented();
6063
break;
@@ -203,4 +206,9 @@ public void onError(String errorMessage) {
203206
}
204207
});
205208
}
209+
210+
private void onIsPresent(final MethodCall call, final Result result) {
211+
boolean isPresent = geocoding.isPresent();
212+
result.success(isPresent);
213+
}
206214
}

Diff for: geocoding_android/example/lib/plugin_example/geocode_page.dart

+17
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,23 @@ class _GeocodeWidgetState extends State<GeocodeWidget> {
154154
});
155155
}),
156156
),
157+
const Padding(
158+
padding: EdgeInsets.only(top: 8),
159+
),
160+
Center(
161+
child: ElevatedButton(
162+
child: Text('Is present'),
163+
onPressed: () {
164+
GeocodingAndroid().isPresent().then((isPresent) {
165+
var output = isPresent
166+
? "Geocoder is present"
167+
: "Geocoder is not present";
168+
setState(() {
169+
_output = output;
170+
});
171+
});
172+
}),
173+
),
157174
Expanded(
158175
child: SingleChildScrollView(
159176
child: Container(

Diff for: geocoding_android/lib/geocoding_android.dart

+14
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ class GeocodingAndroid extends GeocodingPlatform {
4444
}
4545
}
4646

47+
@override
48+
Future<bool> isPresent() async {
49+
try {
50+
final isPresent = await _channel.invokeMethod(
51+
'isPresent',
52+
);
53+
54+
return isPresent;
55+
} on PlatformException catch (e) {
56+
_handlePlatformException(e);
57+
rethrow;
58+
}
59+
}
60+
4761
@override
4862
Future<List<Placemark>> placemarkFromCoordinates(
4963
double latitude,

Diff for: geocoding_android/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: geocoding_android
22
description: A Flutter Geocoding plugin which provides easy geocoding and reverse-geocoding features.
3-
version: 3.1.0
3+
version: 3.2.0
44
repository: https://github.com/baseflow/flutter-geocoding/tree/main/geocoding_android
55
issue_tracker: https://github.com/Baseflow/flutter-geocoding/issues
66

0 commit comments

Comments
 (0)