Skip to content

Commit

Permalink
Added iOS implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
TimHoogstrate committed Feb 15, 2024
1 parent 0dfbbc2 commit 8f8d0f5
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 3 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ abstract class GeocodingPlatform extends PlatformInterface {
/// If true, there is still no guarantee that any individual geocoding attempt will succeed.
///
///
/// This method is only implemented on Android, calling this on iOS always
/// This method is only intended on Android, calling this on iOS always
/// returns [true].
Future<bool> isPresent() {
throw UnimplementedError('isPresent() has not been implementated.');
Expand Down

0 comments on commit 8f8d0f5

Please sign in to comment.