Skip to content
Draft
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/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 5.1.0

- Raises the minimum SDK to Dart 3.12 and Flutter 3.44.

## 5.0.1

- Fixes the `locale` parameter of the `Geocoding` constructor being ignored (#324).
Expand Down
178 changes: 81 additions & 97 deletions geocoding/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,145 +40,128 @@ class _GeocodeWidgetState extends State<GeocodeWidget> {
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
const Padding(
padding: EdgeInsets.only(top: 32),
),
const Padding(padding: EdgeInsets.only(top: 32)),
Row(
children: <Widget>[
Expanded(
child: TextField(
autocorrect: false,
controller: _latitudeController,
style: Theme.of(context).textTheme.bodyMedium,
decoration: const InputDecoration(
hintText: 'Latitude',
),
decoration: const InputDecoration(hintText: 'Latitude'),
keyboardType: TextInputType.number,
),
),
const SizedBox(
width: 20,
),
const SizedBox(width: 20),
Expanded(
child: TextField(
autocorrect: false,
controller: _longitudeController,
style: Theme.of(context).textTheme.bodyMedium,
decoration: const InputDecoration(
hintText: 'Longitude',
),
decoration: const InputDecoration(hintText: 'Longitude'),
keyboardType: TextInputType.number,
),
),
],
),
const Padding(
padding: EdgeInsets.only(top: 8),
),
const Padding(padding: EdgeInsets.only(top: 8)),
Center(
child: ElevatedButton(
child: const Text('Look up address'),
onPressed: () {
final latitude = double.parse(_latitudeController.text);
final longitude = double.parse(_longitudeController.text);
child: const Text('Look up address'),
onPressed: () {
final latitude = double.parse(_latitudeController.text);
final longitude = double.parse(_longitudeController.text);

_geocoding
.placemarkFromCoordinates(
latitude,
longitude,
locale: _locale,
)
.then((placemarks) {
var output = 'No results found.';
if (placemarks.isNotEmpty) {
output = placemarks[0].toDisplayString();
}
_geocoding
.placemarkFromCoordinates(
latitude,
longitude,
locale: _locale,
)
.then((placemarks) {
var output = 'No results found.';
if (placemarks.isNotEmpty) {
output = placemarks[0].toDisplayString();
}

setState(() {
_output = output;
setState(() {
_output = output;
});
});
});
}),
),
const Padding(
padding: EdgeInsets.only(top: 32),
},
),
),
const Padding(padding: EdgeInsets.only(top: 32)),
TextField(
autocorrect: false,
controller: _addressController,
style: Theme.of(context).textTheme.bodyMedium,
decoration: const InputDecoration(
hintText: 'Address',
),
decoration: const InputDecoration(hintText: 'Address'),
keyboardType: TextInputType.text,
),
const Padding(
padding: EdgeInsets.only(top: 8),
),
const Padding(padding: EdgeInsets.only(top: 8)),
Center(
child: ElevatedButton(
child: const Text('Look up location'),
onPressed: () {
_geocoding
.locationFromAddress(
_addressController.text,
locale: _locale,
)
.then((locations) {
var output = 'No results found.';
if (locations.isNotEmpty) {
output = locations[0].toDisplayString();
}
setState(() {
_output = output;
child: const Text('Look up location'),
onPressed: () {
_geocoding
.locationFromAddress(
_addressController.text,
locale: _locale,
)
.then((locations) {
var output = 'No results found.';
if (locations.isNotEmpty) {
output = locations[0].toDisplayString();
}
setState(() {
_output = output;
});
});
});
}),
),
const Padding(
padding: EdgeInsets.only(top: 8),
},
),
),
const Padding(padding: EdgeInsets.only(top: 8)),
Center(
child: ElevatedButton(
child: const Text('is Present'),
onPressed: () {
_geocoding.isPresent().then((isPresent) {
var output = isPresent ? 'Is present' : 'Is not present';
setState(() {
_output = output;
});
child: const Text('is Present'),
onPressed: () {
_geocoding.isPresent().then((isPresent) {
var output = isPresent ? 'Is present' : 'Is not present';
setState(() {
_output = output;
});
}),
),
const Padding(
padding: EdgeInsets.only(top: 8),
});
},
),
),
const Padding(padding: EdgeInsets.only(top: 8)),
Center(
child: ElevatedButton(
child: const Text('Set locale en_US'),
onPressed: () {
setState(() => _locale = Locale('en_US'));
})),
const Padding(
padding: EdgeInsets.only(top: 8),
child: ElevatedButton(
child: const Text('Set locale en_US'),
onPressed: () {
setState(() => _locale = Locale('en_US'));
},
),
),
const Padding(padding: EdgeInsets.only(top: 8)),
Center(
child: ElevatedButton(
child: const Text('Set locale nl_NL'),
onPressed: () {
setState(() => _locale = Locale('nl_NL'));
})),
const Padding(
padding: EdgeInsets.only(top: 8),
child: ElevatedButton(
child: const Text('Set locale nl_NL'),
onPressed: () {
setState(() => _locale = Locale('nl_NL'));
},
),
),
const Padding(padding: EdgeInsets.only(top: 8)),
Expanded(
child: SingleChildScrollView(
child: SizedBox(
width: MediaQuery.of(context).size.width,
child: Text(_output),
),
),
)
),
],
),
);
Expand Down Expand Up @@ -217,14 +200,15 @@ class _GeocodingExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BaseflowPluginExample(
pluginName: 'Geocoding',
githubURL: 'https://github.com/Baseflow/flutter-geocoding',
pubDevURL: 'https://pub.dev/packages/geocoding',
pages: [
ExamplePage(
Icons.pin_drop,
(BuildContext context) => const GeocodeWidget(),
),
]);
pluginName: 'Geocoding',
githubURL: 'https://github.com/Baseflow/flutter-geocoding',
pubDevURL: 'https://pub.dev/packages/geocoding',
pages: [
ExamplePage(
Icons.pin_drop,
(BuildContext context) => const GeocodeWidget(),
),
],
);
}
}
4 changes: 2 additions & 2 deletions geocoding/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ description: Demonstrates how to use the geocoding plugin.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

environment:
sdk: ">=3.3.0 <4.0.0"
flutter: ">=3.0.0"
sdk: ^3.12.0
flutter: ">=3.44.0"

dependencies:
baseflow_plugin_template: ^2.1.2
Expand Down
46 changes: 20 additions & 26 deletions geocoding/lib/geocoding.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';

import 'package:flutter/widgets.dart' as flt show Locale;
import 'package:flutter/widgets.dart';

Expand All @@ -12,18 +13,19 @@ export 'package:geocoding_platform_interface/geocoding_platform_interface.dart';
class Geocoding {
/// Constructs a [Geocoding] instance.
Geocoding({Locale? locale})
: this._fromPlatformCreationParams(
pi.GeocodingCreationParams(),
locale: locale,
);
: this._fromPlatformCreationParams(
pi.GeocodingCreationParams(),
locale: locale,
);

/// Constructs a [Geocoding] instance from creation params for a specific
/// platform.
Geocoding._fromPlatformCreationParams(pi.GeocodingCreationParams params,
{Locale? locale})
: _locale = locale,
_geocoding =
pi.GeocodingPlatformFactory.instance!.createGeocoding(params);
Geocoding._fromPlatformCreationParams(
pi.GeocodingCreationParams params, {
this._locale,
}) : _geocoding = pi.GeocodingPlatformFactory.instance!.createGeocoding(
params,
);

final pi.Geocoding _geocoding;
Locale? _locale;
Expand All @@ -37,11 +39,7 @@ class Geocoding {
Future<List<pi.Location>> locationFromAddress(
String address, {
flt.Locale? locale,
}) =>
_geocoding.locationFromAddress(
address,
locale: locale ?? _locale,
);
}) => _geocoding.locationFromAddress(address, locale: locale ?? _locale);

/// Returns a list of [Placemark] instances found for the supplied address.
///
Expand All @@ -52,11 +50,7 @@ class Geocoding {
Future<List<pi.Placemark>> placemarkFromAddress(
String address, {
flt.Locale? locale,
}) =>
_geocoding.placemarkFromAddress(
address,
locale: locale ?? _locale,
);
}) => _geocoding.placemarkFromAddress(address, locale: locale ?? _locale);

/// Returns a list of [Placemark] instances found for the supplied
/// coordinates.
Expand All @@ -71,12 +65,11 @@ class Geocoding {
double latitude,
double longitude, {
flt.Locale? locale,
}) =>
_geocoding.placemarkFromCoordinates(
latitude,
longitude,
locale: locale ?? _locale,
);
}) => _geocoding.placemarkFromCoordinates(
latitude,
longitude,
locale: 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.
Expand All @@ -92,7 +85,8 @@ class Geocoding {
/// current active locale of the device will be used. The localeIdentifier should
/// be formatted using the syntax: languageCode_countryCode (eg. en_US or nl_NL).
@Deprecated(
'Use the optional constructor parameter instead, or pass in a locale with any of the methods.')
'Use the optional constructor parameter instead, or pass in a locale with any of the methods.',
)
void setLocaleIdentifier(String localeIdentifier) =>
_locale = Locale(localeIdentifier);
}
6 changes: 3 additions & 3 deletions geocoding/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: geocoding
description: A Flutter Geocoding plugin which provides easy geocoding and reverse-geocoding features.
version: 5.0.1
version: 5.1.0
repository: https://github.com/baseflow/flutter-geocoding/tree/main/geocoding
issue_tracker: https://github.com/Baseflow/flutter-geocoding/issues

environment:
sdk: ">=3.3.0 <4.0.0"
flutter: ">=3.0.0"
sdk: ^3.12.0
flutter: ">=3.44.0"

dependencies:
flutter:
Expand Down
Loading
Loading