|
| 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 = |
| 27 | + GeocodingPlatformFactory.instance!.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( |
| 51 | + String address, { |
| 52 | + Locale? locale, |
| 53 | + }) { |
| 54 | + throw UnimplementedError( |
| 55 | + 'locationFromAddress() has not been implementated.'); |
| 56 | + } |
| 57 | + |
| 58 | + /// Returns true if there is a geocoder implementation present that may return results. |
| 59 | + /// If true, there is still no guarantee that any individual geocoding attempt will succeed. |
| 60 | + /// |
| 61 | + /// |
| 62 | + /// This method is only implemented on Android, calling this on iOS always |
| 63 | + /// returns [true]. |
| 64 | + Future<bool> isPresent() { |
| 65 | + throw UnimplementedError('isPresent() has not been implementated.'); |
| 66 | + } |
| 67 | + |
| 68 | + /// Returns a list of [Placemark] instances found for the supplied |
| 69 | + /// coordinates. |
| 70 | + /// |
| 71 | + /// In most situations the returned list should only contain one entry. |
| 72 | + /// However in some situations where the supplied coordinates could not be |
| 73 | + /// resolved into a single [Placemark], multiple [Placemark] instances may be |
| 74 | + /// returned. |
| 75 | + Future<List<Placemark>> placemarkFromCoordinates( |
| 76 | + double latitude, |
| 77 | + double longitude, { |
| 78 | + Locale? locale, |
| 79 | + }) { |
| 80 | + throw UnimplementedError( |
| 81 | + 'placemarkFromCoordinates() has not been implementated.'); |
| 82 | + } |
| 83 | + |
| 84 | + /// Returns a list of [Placemark] instances found for the supplied address. |
| 85 | + /// |
| 86 | + /// In most situations the returned list should only contain one entry. |
| 87 | + /// However in some situations where the supplied address could not be |
| 88 | + /// resolved into a single [Placemark], multiple [Placemark] instances may be |
| 89 | + /// returned. |
| 90 | + Future<List<Placemark>> placemarkFromAddress( |
| 91 | + String address, { |
| 92 | + Locale? locale, |
| 93 | + }) { |
| 94 | + throw UnimplementedError( |
| 95 | + 'placemarkFromAddress() has not been implementated.'); |
| 96 | + } |
| 97 | +} |
0 commit comments