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

Updated app facing package and implemented isPresent() in example project #205

19 changes: 17 additions & 2 deletions geocoding/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class _GeocodeWidgetState extends State<GeocodeWidget> {
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();
Expand Down Expand Up @@ -110,7 +110,7 @@ class _GeocodeWidgetState extends State<GeocodeWidget> {
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();
Expand All @@ -122,6 +122,21 @@ class _GeocodeWidgetState extends State<GeocodeWidget> {
});
}),
),
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(
Expand Down
26 changes: 20 additions & 6 deletions geocoding/lib/geocoding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<Location>> locationFromAddress(
Future<List<Location>>? locationFromAddress(
TimHoogstrate marked this conversation as resolved.
Show resolved Hide resolved
String address, {
String? localeIdentifier,
}) =>
GeocodingPlatform.instance.locationFromAddress(
GeocodingPlatform.instance?.locationFromAddress(
TimHoogstrate marked this conversation as resolved.
Show resolved Hide resolved
address,
localeIdentifier: localeIdentifier,
);

/// Returns a list of [Placemark] instances found for the supplied
Expand All @@ -36,13 +35,28 @@ Future<List<Location>> 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<List<Placemark>> placemarkFromCoordinates(
Future<List<Placemark>>? placemarkFromCoordinates(
TimHoogstrate marked this conversation as resolved.
Show resolved Hide resolved
double latitude,
double longitude, {
String? localeIdentifier,
}) =>
GeocodingPlatform.instance.placemarkFromCoordinates(
GeocodingPlatform.instance?.placemarkFromCoordinates(
TimHoogstrate marked this conversation as resolved.
Show resolved Hide resolved
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<bool>? isPresent({
TimHoogstrate marked this conversation as resolved.
Show resolved Hide resolved
String? localeIdentifier,
}) =>
GeocodingPlatform.instance?.isPresent();
TimHoogstrate marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 3 additions & 3 deletions geocoding/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions geocoding/test/geocoding_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final mockLocation = Location(
timestamp: DateTime.fromMillisecondsSinceEpoch(0).toUtc(),
);

final mockPlacemark = Placemark(
const mockPlacemark = Placemark(
administrativeArea: 'Overijssel',
country: 'Netherlands',
isoCountryCode: 'NL',
Expand All @@ -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);
});
});
}
Expand Down