Skip to content

Commit c4d3cce

Browse files
committed
Updates the platform interface for improved extendability.
- Releases new interface making the Geocoding plugin easier to extend and implement on different platforms. - Moves the old interface into the `legacy` folder. This interface will remain available but will no longer be maintained. To import the old interface use `import 'package:geocoding_platform_interface/legacy/geocoding_platform_interface.dart`.
1 parent b8b2e2b commit c4d3cce

24 files changed

+1254
-695
lines changed

geocoding_platform_interface/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## 4.0.0
2+
3+
- **BREAKING CHANGES:**
4+
- Releases new interface making the Geocoding plugin easier to extend and
5+
implement on different platforms.
6+
- Moves the old interface into the `legacy` folder. This interface will
7+
remain available but will no longer be maintained. To import the old
8+
interface use `import 'package:geocoding_platform_interface/legacy/geocoding_platform_interface.dart`.
9+
110
## 3.2.1
211

312
- Fixed analysis warnings from `flutter analyse`.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export 'src/errors/errors.dart';
2-
export 'src/geocoding_platform_interface.dart';
3-
export 'src/models/models.dart';
1+
export 'src/geocoding.dart';
2+
export 'src/geocoding_platform_factory.dart';
3+
export 'src/types/types.dart';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export 'src/errors/errors.dart';
2+
export 'src/geocoding_platform_interface.dart';
3+
export 'src/models/models.dart';

geocoding_platform_interface/lib/src/geocoding_platform_interface.dart renamed to geocoding_platform_interface/lib/legacy/src/geocoding_platform_interface.dart

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,10 @@ abstract class GeocodingPlatform extends PlatformInterface {
3838
///
3939
/// The `localeIdentifier` should be formatted using the syntax:
4040
/// [languageCode]_[countryCode] (eg. en_US or nl_NL).
41-
Future<void> setLocaleIdentifier(
42-
String localeIdentifier,
43-
) {
41+
Future<void> setLocaleIdentifier(String localeIdentifier) {
4442
throw UnimplementedError(
45-
'setLocaleIdentifier() has not been implementated.');
43+
'setLocaleIdentifier() has not been implementated.',
44+
);
4645
}
4746

4847
/// Returns a list of [Location] instances found for the supplied address.
@@ -51,11 +50,10 @@ abstract class GeocodingPlatform extends PlatformInterface {
5150
/// However in some situations where the supplied address could not be
5251
/// resolved into a single [Location], multiple [Location] instances may be
5352
/// returned.
54-
Future<List<Location>> locationFromAddress(
55-
String address,
56-
) {
53+
Future<List<Location>> locationFromAddress(String address) {
5754
throw UnimplementedError(
58-
'locationFromAddress() has not been implementated.');
55+
'locationFromAddress() has not been implementated.',
56+
);
5957
}
6058

6159
/// Returns true if there is a geocoder implementation present that may return results.
@@ -80,7 +78,8 @@ abstract class GeocodingPlatform extends PlatformInterface {
8078
double longitude,
8179
) {
8280
throw UnimplementedError(
83-
'placemarkFromCoordinates() has not been implementated.');
81+
'placemarkFromCoordinates() has not been implementated.',
82+
);
8483
}
8584

8685
/// Returns a list of [Placemark] instances found for the supplied address.
@@ -89,10 +88,9 @@ abstract class GeocodingPlatform extends PlatformInterface {
8988
/// However in some situations where the supplied address could not be
9089
/// resolved into a single [Placemark], multiple [Placemark] instances may be
9190
/// returned.
92-
Future<List<Placemark>> placemarkFromAddress(
93-
String address,
94-
) {
91+
Future<List<Placemark>> placemarkFromAddress(String address) {
9592
throw UnimplementedError(
96-
'placemarkFromAddress() has not been implementated.');
93+
'placemarkFromAddress() has not been implementated.',
94+
);
9795
}
9896
}

geocoding_platform_interface/lib/src/models/location.dart renamed to geocoding_platform_interface/lib/legacy/src/models/location.dart

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,14 @@ class Location {
5656

5757
final Map<dynamic, dynamic> locationMap = message;
5858
final timestamp = DateTime.fromMillisecondsSinceEpoch(
59-
locationMap['timestamp'].toInt(),
60-
isUtc: true);
59+
locationMap['timestamp'].toInt(),
60+
isUtc: true,
61+
);
6162

6263
if (locationMap['latitude'] == null || locationMap['longitude'] == null) {
6364
throw ArgumentError(
64-
'The parameters latitude and longitude should not be null.');
65+
'The parameters latitude and longitude should not be null.',
66+
);
6567
}
6668

6769
return Location._(
@@ -74,10 +76,10 @@ class Location {
7476
/// Converts the [Location] instance into a [Map] instance that can be
7577
/// serialized to JSON.
7678
Map<String, dynamic> toJson() => {
77-
'latitude': latitude,
78-
'longitude': longitude,
79-
'timestamp': timestamp.millisecondsSinceEpoch,
80-
};
79+
'latitude': latitude,
80+
'longitude': longitude,
81+
'timestamp': timestamp.millisecondsSinceEpoch,
82+
};
8183

8284
@override
8385
String toString() {

geocoding_platform_interface/lib/src/models/placemark.dart renamed to geocoding_platform_interface/lib/legacy/src/models/placemark.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,18 @@ class Placemark {
132132
/// Converts the [Placemark] instance into a [Map] instance that can be
133133
/// serialized to JSON.
134134
Map<String, dynamic> toJson() => {
135-
'name': name,
136-
'street': street,
137-
'isoCountryCode': isoCountryCode,
138-
'country': country,
139-
'postalCode': postalCode,
140-
'administrativeArea': administrativeArea,
141-
'subAdministrativeArea': subAdministrativeArea,
142-
'locality': locality,
143-
'subLocality': subLocality,
144-
'thoroughfare': thoroughfare,
145-
'subThoroughfare': subThoroughfare,
146-
};
135+
'name': name,
136+
'street': street,
137+
'isoCountryCode': isoCountryCode,
138+
'country': country,
139+
'postalCode': postalCode,
140+
'administrativeArea': administrativeArea,
141+
'subAdministrativeArea': subAdministrativeArea,
142+
'locality': locality,
143+
'subLocality': subLocality,
144+
'thoroughfare': thoroughfare,
145+
'subThoroughfare': subThoroughfare,
146+
};
147147

148148
@override
149149
String toString() {
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import 'package:flutter/widgets.dart';
2+
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
3+
4+
import 'geocoding_platform_factory.dart';
5+
import 'types/types.dart';
6+
7+
/// Interface for a platform implementation of a [Geocoding] instance.
8+
///
9+
/// Platform implementations should extend this class rather than implement it
10+
/// as `geocoding` package does not consider newly added methods to be breaking
11+
/// changes. Extending this class (using `extends`) ensures that the subclass
12+
/// will get the default implementation, while platform implementations that
13+
/// `implements` this interface will be broken by newly added
14+
/// [Geocoding] methods.
15+
abstract class Geocoding extends PlatformInterface {
16+
/// Creates a new [PlatformWebViewController]
17+
factory Geocoding(GeocodingCreationParams params) {
18+
assert(
19+
GeocodingPlatformFactory.instance != null,
20+
'A platform implementation for `geocoding` has not been set. Please '
21+
'ensure that an implementation of `GeocodingPlatformFactory` has been '
22+
'set te `GeocodingPlatformFactory.instance` before use. For unit '
23+
'testing, `GeocodingPlatformFactory.instance` can be set with your own '
24+
'test implementation.',
25+
);
26+
final Geocoding geocoding = GeocodingPlatformFactory.instance!
27+
.createGeocoding(params);
28+
PlatformInterface.verify(geocoding, _token);
29+
return geocoding;
30+
}
31+
32+
/// Used by the platform implementation to create a new [Geocoding].
33+
///
34+
/// Should only be used by platform implementations because they can't extend
35+
/// a class that only contains a factory constructor.
36+
@protected
37+
Geocoding.implementation(this.params) : super(token: _token);
38+
39+
static final Object _token = Object();
40+
41+
/// The parameters used to initialize the [Geocoding] instance.
42+
final GeocodingCreationParams params;
43+
44+
/// Returns a list of [Location] instances found for the supplied address.
45+
///
46+
/// In most situations the returned list should only contain one entry.
47+
/// However in some situations where the supplied address could not be
48+
/// resolved into a single [Location], multiple [Location] instances may be
49+
/// returned.
50+
Future<List<Location>> locationFromAddress(String address, {Locale? locale}) {
51+
throw UnimplementedError(
52+
'locationFromAddress() has not been implementated.',
53+
);
54+
}
55+
56+
/// Returns true if there is a geocoder implementation present that may return results.
57+
/// If true, there is still no guarantee that any individual geocoding attempt will succeed.
58+
///
59+
///
60+
/// This method is only implemented on Android, calling this on iOS always
61+
/// returns [true].
62+
Future<bool> isPresent() {
63+
throw UnimplementedError('isPresent() has not been implementated.');
64+
}
65+
66+
/// Returns a list of [Placemark] instances found for the supplied
67+
/// coordinates.
68+
///
69+
/// In most situations the returned list should only contain one entry.
70+
/// However in some situations where the supplied coordinates could not be
71+
/// resolved into a single [Placemark], multiple [Placemark] instances may be
72+
/// returned.
73+
Future<List<Placemark>> placemarkFromCoordinates(
74+
double latitude,
75+
double longitude, {
76+
Locale? locale,
77+
}) {
78+
throw UnimplementedError(
79+
'placemarkFromCoordinates() has not been implementated.',
80+
);
81+
}
82+
83+
/// Returns a list of [Placemark] instances found for the supplied address.
84+
///
85+
/// In most situations the returned list should only contain one entry.
86+
/// However in some situations where the supplied address could not be
87+
/// resolved into a single [Placemark], multiple [Placemark] instances may be
88+
/// returned.
89+
Future<List<Placemark>> placemarkFromAddress(
90+
String address, {
91+
Locale? locale,
92+
}) {
93+
throw UnimplementedError(
94+
'placemarkFromAddress() has not been implementated.',
95+
);
96+
}
97+
}

0 commit comments

Comments
 (0)