diff --git a/geocoding_android/CHANGELOG.md b/geocoding_android/CHANGELOG.md index 457a4ab..0c99193 100644 --- a/geocoding_android/CHANGELOG.md +++ b/geocoding_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.1.1 + +- Runs the deprecated pre-API 33 `Geocoder.getFromLocation` and `Geocoder.getFromLocationName` lookups on a background thread instead of the platform main thread, preventing ANRs on Android 12 and lower when the geocoding service is slow. + ## 5.1.0 - Updates minimum supported SDK version to Flutter 3.44/Dart 3.12. diff --git a/geocoding_android/android/src/main/kotlin/com/baseflow/geocoding/AndroidGeocoderLibrary.g.kt b/geocoding_android/android/src/main/kotlin/com/baseflow/geocoding/AndroidGeocoderLibrary.g.kt index 1716fb0..5020455 100644 --- a/geocoding_android/android/src/main/kotlin/com/baseflow/geocoding/AndroidGeocoderLibrary.g.kt +++ b/geocoding_android/android/src/main/kotlin/com/baseflow/geocoding/AndroidGeocoderLibrary.g.kt @@ -402,12 +402,6 @@ abstract class AndroidGeocoderLibraryPigeonProxyApiRegistrar(val binaryMessenger */ abstract fun getPigeonApiAddress(): PigeonApiAddress - /** - * An implementation of [PigeonApiGeographicBounds] used to add a new Dart instance of - * `GeographicBounds` to the Dart `InstanceManager`. - */ - abstract fun getPigeonApiGeographicBounds(): PigeonApiGeographicBounds - /** * An implementation of [PigeonApiBuild] used to add a new Dart instance of * `Build` to the Dart `InstanceManager`. @@ -426,6 +420,12 @@ abstract class AndroidGeocoderLibraryPigeonProxyApiRegistrar(val binaryMessenger */ abstract fun getPigeonApiGeocoder(): PigeonApiGeocoder + /** + * An implementation of [PigeonApiGeographicBounds] used to add a new Dart instance of + * `GeographicBounds` to the Dart `InstanceManager`. + */ + abstract fun getPigeonApiGeographicBounds(): PigeonApiGeographicBounds + /** * An implementation of [PigeonApiLocale] used to add a new Dart instance of * `Locale` to the Dart `InstanceManager`. @@ -435,19 +435,19 @@ abstract class AndroidGeocoderLibraryPigeonProxyApiRegistrar(val binaryMessenger fun setUp() { AndroidGeocoderLibraryPigeonInstanceManagerApi.setUpMessageHandlers(binaryMessenger, instanceManager) PigeonApiAddress.setUpMessageHandlers(binaryMessenger, getPigeonApiAddress()) - PigeonApiGeographicBounds.setUpMessageHandlers(binaryMessenger, getPigeonApiGeographicBounds()) PigeonApiBuild.setUpMessageHandlers(binaryMessenger, getPigeonApiBuild()) PigeonApiGeocodeListener.setUpMessageHandlers(binaryMessenger, getPigeonApiGeocodeListener()) PigeonApiGeocoder.setUpMessageHandlers(binaryMessenger, getPigeonApiGeocoder()) + PigeonApiGeographicBounds.setUpMessageHandlers(binaryMessenger, getPigeonApiGeographicBounds()) PigeonApiLocale.setUpMessageHandlers(binaryMessenger, getPigeonApiLocale()) } fun tearDown() { AndroidGeocoderLibraryPigeonInstanceManagerApi.setUpMessageHandlers(binaryMessenger, null) PigeonApiAddress.setUpMessageHandlers(binaryMessenger, null) - PigeonApiGeographicBounds.setUpMessageHandlers(binaryMessenger, null) PigeonApiBuild.setUpMessageHandlers(binaryMessenger, null) PigeonApiGeocodeListener.setUpMessageHandlers(binaryMessenger, null) PigeonApiGeocoder.setUpMessageHandlers(binaryMessenger, null) + PigeonApiGeographicBounds.setUpMessageHandlers(binaryMessenger, null) PigeonApiLocale.setUpMessageHandlers(binaryMessenger, null) } } @@ -488,13 +488,6 @@ private class AndroidGeocoderLibraryPigeonProxyApiBaseCodec(val registrar: Andro logNewInstanceFailure("Address", value, it.exceptionOrNull()) } } - } - else if (value is GeographicBounds) { - registrar.getPigeonApiGeographicBounds().pigeon_newInstance(value) { - if (it.isFailure) { - logNewInstanceFailure("GeographicBounds", value, it.exceptionOrNull()) - } - } } else if (value is android.os.Build) { registrar.getPigeonApiBuild().pigeon_newInstance(value) { @@ -516,6 +509,13 @@ private class AndroidGeocoderLibraryPigeonProxyApiBaseCodec(val registrar: Andro logNewInstanceFailure("Geocoder", value, it.exceptionOrNull()) } } + } + else if (value is GeographicBounds) { + registrar.getPigeonApiGeographicBounds().pigeon_newInstance(value) { + if (it.isFailure) { + logNewInstanceFailure("GeographicBounds", value, it.exceptionOrNull()) + } + } } else if (value is java.util.Locale) { registrar.getPigeonApiLocale().pigeon_newInstance(value) { @@ -1025,83 +1025,6 @@ abstract class PigeonApiAddress(open val pigeonRegistrar: AndroidGeocoderLibrary } } -} -/** Geographical bounds describing a geographic box. */ -@Suppress("UNCHECKED_CAST") -abstract class PigeonApiGeographicBounds(open val pigeonRegistrar: AndroidGeocoderLibraryPigeonProxyApiRegistrar) { - abstract fun pigeon_defaultConstructor(lowerLeftLatitude: Double, lowerLeftLongitude: Double, upperRightLatitude: Double, upperRightLongitude: Double): GeographicBounds - - abstract fun lowerLeftLatitude(pigeon_instance: GeographicBounds): Double - - abstract fun lowerLeftLongitude(pigeon_instance: GeographicBounds): Double - - abstract fun upperRightLatitude(pigeon_instance: GeographicBounds): Double - - abstract fun upperRightLongitude(pigeon_instance: GeographicBounds): Double - - companion object { - @Suppress("LocalVariableName") - fun setUpMessageHandlers(binaryMessenger: BinaryMessenger, api: PigeonApiGeographicBounds?) { - val codec = api?.pigeonRegistrar?.codec ?: AndroidGeocoderLibraryPigeonCodec() - run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.geocoding_android.GeographicBounds.pigeon_defaultConstructor", codec) - if (api != null) { - channel.setMessageHandler { message, reply -> - val args = message as List - val pigeon_identifierArg = args[0] as Long - val lowerLeftLatitudeArg = args[1] as Double - val lowerLeftLongitudeArg = args[2] as Double - val upperRightLatitudeArg = args[3] as Double - val upperRightLongitudeArg = args[4] as Double - val wrapped: List = try { - api.pigeonRegistrar.instanceManager.addDartCreatedInstance(api.pigeon_defaultConstructor(lowerLeftLatitudeArg,lowerLeftLongitudeArg,upperRightLatitudeArg,upperRightLongitudeArg), pigeon_identifierArg) - listOf(null) - } catch (exception: Throwable) { - AndroidGeocoderLibraryPigeonUtils.wrapError(exception) - } - reply.reply(wrapped) - } - } else { - channel.setMessageHandler(null) - } - } - } - } - - @Suppress("LocalVariableName", "FunctionName") - /** Creates a Dart instance of GeographicBounds and attaches it to [pigeon_instanceArg]. */ - fun pigeon_newInstance(pigeon_instanceArg: GeographicBounds, callback: (Result) -> Unit) -{ - if (pigeonRegistrar.ignoreCallsToDart) { - callback( - Result.failure( - AndroidGeocoderError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) - } else if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) { - callback(Result.success(Unit)) - } else { - val pigeon_identifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg) - val lowerLeftLatitudeArg = lowerLeftLatitude(pigeon_instanceArg) - val lowerLeftLongitudeArg = lowerLeftLongitude(pigeon_instanceArg) - val upperRightLatitudeArg = upperRightLatitude(pigeon_instanceArg) - val upperRightLongitudeArg = upperRightLongitude(pigeon_instanceArg) - val binaryMessenger = pigeonRegistrar.binaryMessenger - val codec = pigeonRegistrar.codec - val channelName = "dev.flutter.pigeon.geocoding_android.GeographicBounds.pigeon_newInstance" - val channel = BasicMessageChannel(binaryMessenger, channelName, codec) - channel.send(listOf(pigeon_identifierArg, lowerLeftLatitudeArg, lowerLeftLongitudeArg, upperRightLatitudeArg, upperRightLongitudeArg)) { - if (it is List<*>) { - if (it.size > 1) { - callback(Result.failure(AndroidGeocoderError(it[0] as String, it[1] as String, it[2] as String?))) - } else { - callback(Result.success(Unit)) - } - } else { - callback(Result.failure(AndroidGeocoderLibraryPigeonUtils.createConnectionError(channelName))) - } - } - } - } - } /** Information about the current Android build, extracted from system properties. */ @Suppress("UNCHECKED_CAST") @@ -1313,7 +1236,7 @@ abstract class PigeonApiGeocoder(open val pigeonRegistrar: AndroidGeocoderLibrar * in blocking the main thread. On Android devices running API 33 or higher * please use the [Geocoder.getFromLocation] method. */ - abstract fun getFromLocationPreAndroidApi33(pigeon_instance: android.location.Geocoder, latitude: Double, longitude: Double, maxResults: Long): List? + abstract fun getFromLocationPreAndroidApi33(pigeon_instance: android.location.Geocoder, latitude: Double, longitude: Double, maxResults: Long, callback: (Result?>) -> Unit) /** * Returns an array of Addresses that attempt to describe the named location, @@ -1340,7 +1263,7 @@ abstract class PigeonApiGeocoder(open val pigeonRegistrar: AndroidGeocoderLibrar * in blocking the main thread. On Android devices running API 33 or higher * please use the [Geocoder.getFromLocation] method. */ - abstract fun getFromLocationNamePreAndroidApi33(pigeon_instance: android.location.Geocoder, locationName: String, maxResults: Long, bounds: GeographicBounds?): List? + abstract fun getFromLocationNamePreAndroidApi33(pigeon_instance: android.location.Geocoder, locationName: String, maxResults: Long, bounds: GeographicBounds?, callback: (Result?>) -> Unit) /** * Returns true if there is a geocoder implementation present on the device @@ -1419,12 +1342,15 @@ abstract class PigeonApiGeocoder(open val pigeonRegistrar: AndroidGeocoderLibrar val latitudeArg = args[1] as Double val longitudeArg = args[2] as Double val maxResultsArg = args[3] as Long - val wrapped: List = try { - listOf(api.getFromLocationPreAndroidApi33(pigeon_instanceArg, latitudeArg, longitudeArg, maxResultsArg)) - } catch (exception: Throwable) { - AndroidGeocoderLibraryPigeonUtils.wrapError(exception) + api.getFromLocationPreAndroidApi33(pigeon_instanceArg, latitudeArg, longitudeArg, maxResultsArg) { result: Result?> -> + val error = result.exceptionOrNull() + if (error != null) { + reply.reply(AndroidGeocoderLibraryPigeonUtils.wrapError(error)) + } else { + val data = result.getOrNull() + reply.reply(AndroidGeocoderLibraryPigeonUtils.wrapResult(data)) + } } - reply.reply(wrapped) } } else { channel.setMessageHandler(null) @@ -1478,12 +1404,15 @@ abstract class PigeonApiGeocoder(open val pigeonRegistrar: AndroidGeocoderLibrar val locationNameArg = args[1] as String val maxResultsArg = args[2] as Long val boundsArg = args[3] as GeographicBounds? - val wrapped: List = try { - listOf(api.getFromLocationNamePreAndroidApi33(pigeon_instanceArg, locationNameArg, maxResultsArg, boundsArg)) - } catch (exception: Throwable) { - AndroidGeocoderLibraryPigeonUtils.wrapError(exception) + api.getFromLocationNamePreAndroidApi33(pigeon_instanceArg, locationNameArg, maxResultsArg, boundsArg) { result: Result?> -> + val error = result.exceptionOrNull() + if (error != null) { + reply.reply(AndroidGeocoderLibraryPigeonUtils.wrapError(error)) + } else { + val data = result.getOrNull() + reply.reply(AndroidGeocoderLibraryPigeonUtils.wrapResult(data)) + } } - reply.reply(wrapped) } } else { channel.setMessageHandler(null) @@ -1537,6 +1466,83 @@ abstract class PigeonApiGeocoder(open val pigeonRegistrar: AndroidGeocoderLibrar } } +} +/** Geographical bounds describing a geographic box. */ +@Suppress("UNCHECKED_CAST") +abstract class PigeonApiGeographicBounds(open val pigeonRegistrar: AndroidGeocoderLibraryPigeonProxyApiRegistrar) { + abstract fun pigeon_defaultConstructor(lowerLeftLatitude: Double, lowerLeftLongitude: Double, upperRightLatitude: Double, upperRightLongitude: Double): GeographicBounds + + abstract fun lowerLeftLatitude(pigeon_instance: GeographicBounds): Double + + abstract fun lowerLeftLongitude(pigeon_instance: GeographicBounds): Double + + abstract fun upperRightLatitude(pigeon_instance: GeographicBounds): Double + + abstract fun upperRightLongitude(pigeon_instance: GeographicBounds): Double + + companion object { + @Suppress("LocalVariableName") + fun setUpMessageHandlers(binaryMessenger: BinaryMessenger, api: PigeonApiGeographicBounds?) { + val codec = api?.pigeonRegistrar?.codec ?: AndroidGeocoderLibraryPigeonCodec() + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.geocoding_android.GeographicBounds.pigeon_defaultConstructor", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_identifierArg = args[0] as Long + val lowerLeftLatitudeArg = args[1] as Double + val lowerLeftLongitudeArg = args[2] as Double + val upperRightLatitudeArg = args[3] as Double + val upperRightLongitudeArg = args[4] as Double + val wrapped: List = try { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance(api.pigeon_defaultConstructor(lowerLeftLatitudeArg,lowerLeftLongitudeArg,upperRightLatitudeArg,upperRightLongitudeArg), pigeon_identifierArg) + listOf(null) + } catch (exception: Throwable) { + AndroidGeocoderLibraryPigeonUtils.wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + } + } + + @Suppress("LocalVariableName", "FunctionName") + /** Creates a Dart instance of GeographicBounds and attaches it to [pigeon_instanceArg]. */ + fun pigeon_newInstance(pigeon_instanceArg: GeographicBounds, callback: (Result) -> Unit) +{ + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidGeocoderError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + } else if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) { + callback(Result.success(Unit)) + } else { + val pigeon_identifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg) + val lowerLeftLatitudeArg = lowerLeftLatitude(pigeon_instanceArg) + val lowerLeftLongitudeArg = lowerLeftLongitude(pigeon_instanceArg) + val upperRightLatitudeArg = upperRightLatitude(pigeon_instanceArg) + val upperRightLongitudeArg = upperRightLongitude(pigeon_instanceArg) + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = "dev.flutter.pigeon.geocoding_android.GeographicBounds.pigeon_newInstance" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_identifierArg, lowerLeftLatitudeArg, lowerLeftLongitudeArg, upperRightLatitudeArg, upperRightLongitudeArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback(Result.failure(AndroidGeocoderError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(AndroidGeocoderLibraryPigeonUtils.createConnectionError(channelName))) + } + } + } + } + } /** * A `Locale` object represents a specific geographical, political, or cultural diff --git a/geocoding_android/android/src/main/kotlin/com/baseflow/geocoding/proxies/GeocoderProxyApi.kt b/geocoding_android/android/src/main/kotlin/com/baseflow/geocoding/proxies/GeocoderProxyApi.kt index 9f4dd45..2e6c6eb 100644 --- a/geocoding_android/android/src/main/kotlin/com/baseflow/geocoding/proxies/GeocoderProxyApi.kt +++ b/geocoding_android/android/src/main/kotlin/com/baseflow/geocoding/proxies/GeocoderProxyApi.kt @@ -10,6 +10,8 @@ import com.baseflow.geocoding.GeographicBounds import com.baseflow.geocoding.PigeonApiGeocoder import com.baseflow.geocoding.ProxyApiRegistrar import java.util.Locale +import java.util.concurrent.ExecutorService +import java.util.concurrent.Executors /** * ProxyApi implementation for {@link Geocoder}. This class may handle instantiating native @@ -18,6 +20,10 @@ import java.util.Locale */ class GeocoderProxyApi(pigeonRegistrar: AndroidGeocoderLibraryPigeonProxyApiRegistrar) : PigeonApiGeocoder(pigeonRegistrar) { + companion object { + private val executor: ExecutorService = Executors.newSingleThreadExecutor() + } + override fun pigeon_defaultConstructor(locale: Locale?): Geocoder { check(pigeonRegistrar is ProxyApiRegistrar) { "The pigeonRegistrar is not an instance of ProxyApiRegistrar." } @@ -43,9 +49,12 @@ class GeocoderProxyApi(pigeonRegistrar: AndroidGeocoderLibraryPigeonProxyApiRegi pigeon_instance: Geocoder, latitude: Double, longitude: Double, - maxResults: Long - ): List? { - return pigeon_instance.getFromLocation(latitude, longitude, maxResults.toInt()); + maxResults: Long, + callback: (Result?>) -> Unit + ) { + runInBackground(callback) { + pigeon_instance.getFromLocation(latitude, longitude, maxResults.toInt()) + } } @RequiresApi(Build.VERSION_CODES.TIRAMISU) @@ -70,13 +79,33 @@ class GeocoderProxyApi(pigeonRegistrar: AndroidGeocoderLibraryPigeonProxyApiRegi pigeon_instance: Geocoder, locationName: String, maxResults: Long, - bounds: GeographicBounds? - ): List? { - if (bounds != null) { - return pigeon_instance.getFromLocationName(locationName, maxResults.toInt(), bounds.lowerLeftLatitude, bounds.lowerLeftLongitude, bounds.upperRightLatitude, bounds.upperRightLongitude) + bounds: GeographicBounds?, + callback: (Result?>) -> Unit + ) { + runInBackground(callback) { + if (bounds != null) { + pigeon_instance.getFromLocationName(locationName, maxResults.toInt(), bounds.lowerLeftLatitude, bounds.lowerLeftLongitude, bounds.upperRightLatitude, bounds.upperRightLongitude) + } else { + pigeon_instance.getFromLocationName(locationName, maxResults.toInt()) + } } + } + + /** + * Runs a blocking [Geocoder] lookup on a background thread and delivers the result on the main + * thread, so that the pre-API 33 synchronous methods never block the UI thread. + */ + private fun runInBackground( + callback: (Result?>) -> Unit, + lookup: () -> List? + ) { + check(pigeonRegistrar is ProxyApiRegistrar) { "The pigeonRegistrar is not an instance of ProxyApiRegistrar." } + val registrar = pigeonRegistrar as ProxyApiRegistrar - return pigeon_instance.getFromLocationName(locationName, maxResults.toInt()) + executor.execute { + val result = runCatching(lookup) + registrar.runOnMainThread { callback(result) } + } } override fun isPresent(): Boolean { diff --git a/geocoding_android/lib/src/geocoder/geocoder.g.dart b/geocoding_android/lib/src/geocoder/geocoder.g.dart index a7f3722..8c9ea20 100644 --- a/geocoding_android/lib/src/geocoder/geocoder.g.dart +++ b/geocoding_android/lib/src/geocoder/geocoder.g.dart @@ -41,15 +41,6 @@ List wrapResponse({ /// See [PigeonOverrides.pigeon_reset] to set all overrides back to null. @visibleForTesting class PigeonOverrides { - /// Overrides [GeographicBounds.new]. - static GeographicBounds Function({ - required double lowerLeftLatitude, - required double lowerLeftLongitude, - required double upperRightLatitude, - required double upperRightLongitude, - })? - geographicBounds_new; - /// Overrides [GeocodeListener.new]. static GeocodeListener Function({ required void Function( @@ -68,6 +59,15 @@ class PigeonOverrides { /// Overrides [Geocoder.new]. static Geocoder Function({Locale? locale})? geocoder_new; + /// Overrides [GeographicBounds.new]. + static GeographicBounds Function({ + required double lowerLeftLatitude, + required double lowerLeftLongitude, + required double upperRightLatitude, + required double upperRightLongitude, + })? + geographicBounds_new; + /// Overrides [Locale.new]. static Locale Function({required String identifier})? locale_new; @@ -79,11 +79,11 @@ class PigeonOverrides { /// Sets all overridden ProxyApi class members to null. static void pigeon_reset() { - geographicBounds_new = null; build_getSdkVersion = null; geocodeListener_new = null; geocoder_new = null; geocoder_isPresent = null; + geographicBounds_new = null; locale_new = null; } } @@ -201,9 +201,6 @@ class PigeonInstanceManager { Address.pigeon_setUpMessageHandlers( pigeon_instanceManager: instanceManager, ); - GeographicBounds.pigeon_setUpMessageHandlers( - pigeon_instanceManager: instanceManager, - ); Build.pigeon_setUpMessageHandlers(pigeon_instanceManager: instanceManager); GeocodeListener.pigeon_setUpMessageHandlers( pigeon_instanceManager: instanceManager, @@ -211,6 +208,9 @@ class PigeonInstanceManager { Geocoder.pigeon_setUpMessageHandlers( pigeon_instanceManager: instanceManager, ); + GeographicBounds.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager, + ); Locale.pigeon_setUpMessageHandlers(pigeon_instanceManager: instanceManager); return instanceManager; } @@ -1245,209 +1245,6 @@ class Address extends PigeonInternalProxyApiBaseClass { } } -/// Geographical bounds describing a geographic box. -class GeographicBounds extends PigeonInternalProxyApiBaseClass { - factory GeographicBounds({ - BinaryMessenger? pigeon_binaryMessenger, - PigeonInstanceManager? pigeon_instanceManager, - required double lowerLeftLatitude, - required double lowerLeftLongitude, - required double upperRightLatitude, - required double upperRightLongitude, - }) { - if (PigeonOverrides.geographicBounds_new != null) { - return PigeonOverrides.geographicBounds_new!( - lowerLeftLatitude: lowerLeftLatitude, - lowerLeftLongitude: lowerLeftLongitude, - upperRightLatitude: upperRightLatitude, - upperRightLongitude: upperRightLongitude, - ); - } - return GeographicBounds.pigeon_new( - pigeon_binaryMessenger: pigeon_binaryMessenger, - pigeon_instanceManager: pigeon_instanceManager, - lowerLeftLatitude: lowerLeftLatitude, - lowerLeftLongitude: lowerLeftLongitude, - upperRightLatitude: upperRightLatitude, - upperRightLongitude: upperRightLongitude, - ); - } - - @protected - GeographicBounds.pigeon_new({ - super.pigeon_binaryMessenger, - super.pigeon_instanceManager, - required this.lowerLeftLatitude, - required this.lowerLeftLongitude, - required this.upperRightLatitude, - required this.upperRightLongitude, - }) { - final int pigeonVar_instanceIdentifier = pigeon_instanceManager - .addDartCreatedInstance(this); - final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = - _pigeonVar_codecGeographicBounds; - final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; - const String pigeonVar_channelName = - 'dev.flutter.pigeon.geocoding_android.GeographicBounds.pigeon_defaultConstructor'; - final BasicMessageChannel pigeonVar_channel = - BasicMessageChannel( - pigeonVar_channelName, - pigeonChannelCodec, - binaryMessenger: pigeonVar_binaryMessenger, - ); - final Future pigeonVar_sendFuture = pigeonVar_channel - .send([ - pigeonVar_instanceIdentifier, - lowerLeftLatitude, - lowerLeftLongitude, - upperRightLatitude, - upperRightLongitude, - ]); - () async { - final List? pigeonVar_replyList = - await pigeonVar_sendFuture as List?; - if (pigeonVar_replyList == null) { - throw _createConnectionError(pigeonVar_channelName); - } else if (pigeonVar_replyList.length > 1) { - throw PlatformException( - code: pigeonVar_replyList[0]! as String, - message: pigeonVar_replyList[1] as String?, - details: pigeonVar_replyList[2], - ); - } else { - return; - } - }(); - } - - /// Constructs [GeographicBounds] without creating the associated native object. - /// - /// This should only be used by subclasses created by this library or to - /// create copies for an [PigeonInstanceManager]. - @protected - GeographicBounds.pigeon_detached({ - super.pigeon_binaryMessenger, - super.pigeon_instanceManager, - required this.lowerLeftLatitude, - required this.lowerLeftLongitude, - required this.upperRightLatitude, - required this.upperRightLongitude, - }); - - late final _PigeonInternalProxyApiBaseCodec _pigeonVar_codecGeographicBounds = - _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); - - final double lowerLeftLatitude; - - final double lowerLeftLongitude; - - final double upperRightLatitude; - - final double upperRightLongitude; - - static void pigeon_setUpMessageHandlers({ - bool pigeon_clearHandlers = false, - BinaryMessenger? pigeon_binaryMessenger, - PigeonInstanceManager? pigeon_instanceManager, - GeographicBounds Function( - double lowerLeftLatitude, - double lowerLeftLongitude, - double upperRightLatitude, - double upperRightLongitude, - )? - pigeon_newInstance, - }) { - final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = - _PigeonInternalProxyApiBaseCodec( - pigeon_instanceManager ?? PigeonInstanceManager.instance, - ); - final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.geocoding_android.GeographicBounds.pigeon_newInstance', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (pigeon_clearHandlers) { - pigeonVar_channel.setMessageHandler(null); - } else { - pigeonVar_channel.setMessageHandler((Object? message) async { - assert( - message != null, - 'Argument for dev.flutter.pigeon.geocoding_android.GeographicBounds.pigeon_newInstance was null.', - ); - final List args = (message as List?)!; - final int? arg_pigeon_instanceIdentifier = (args[0] as int?); - assert( - arg_pigeon_instanceIdentifier != null, - 'Argument for dev.flutter.pigeon.geocoding_android.GeographicBounds.pigeon_newInstance was null, expected non-null int.', - ); - final double? arg_lowerLeftLatitude = (args[1] as double?); - assert( - arg_lowerLeftLatitude != null, - 'Argument for dev.flutter.pigeon.geocoding_android.GeographicBounds.pigeon_newInstance was null, expected non-null double.', - ); - final double? arg_lowerLeftLongitude = (args[2] as double?); - assert( - arg_lowerLeftLongitude != null, - 'Argument for dev.flutter.pigeon.geocoding_android.GeographicBounds.pigeon_newInstance was null, expected non-null double.', - ); - final double? arg_upperRightLatitude = (args[3] as double?); - assert( - arg_upperRightLatitude != null, - 'Argument for dev.flutter.pigeon.geocoding_android.GeographicBounds.pigeon_newInstance was null, expected non-null double.', - ); - final double? arg_upperRightLongitude = (args[4] as double?); - assert( - arg_upperRightLongitude != null, - 'Argument for dev.flutter.pigeon.geocoding_android.GeographicBounds.pigeon_newInstance was null, expected non-null double.', - ); - try { - (pigeon_instanceManager ?? PigeonInstanceManager.instance) - .addHostCreatedInstance( - pigeon_newInstance?.call( - arg_lowerLeftLatitude!, - arg_lowerLeftLongitude!, - arg_upperRightLatitude!, - arg_upperRightLongitude!, - ) ?? - GeographicBounds.pigeon_detached( - pigeon_binaryMessenger: pigeon_binaryMessenger, - pigeon_instanceManager: pigeon_instanceManager, - lowerLeftLatitude: arg_lowerLeftLatitude!, - lowerLeftLongitude: arg_lowerLeftLongitude!, - upperRightLatitude: arg_upperRightLatitude!, - upperRightLongitude: arg_upperRightLongitude!, - ), - arg_pigeon_instanceIdentifier!, - ); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString()), - ); - } - }); - } - } - } - - @override - GeographicBounds pigeon_copy() { - return GeographicBounds.pigeon_detached( - pigeon_binaryMessenger: pigeon_binaryMessenger, - pigeon_instanceManager: pigeon_instanceManager, - lowerLeftLatitude: lowerLeftLatitude, - lowerLeftLongitude: lowerLeftLongitude, - upperRightLatitude: upperRightLatitude, - upperRightLongitude: upperRightLongitude, - ); - } -} - /// Information about the current Android build, extracted from system properties. class Build extends PigeonInternalProxyApiBaseClass { /// Constructs [Build] without creating the associated native object. @@ -2158,6 +1955,209 @@ class Geocoder extends PigeonInternalProxyApiBaseClass { } } +/// Geographical bounds describing a geographic box. +class GeographicBounds extends PigeonInternalProxyApiBaseClass { + factory GeographicBounds({ + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + required double lowerLeftLatitude, + required double lowerLeftLongitude, + required double upperRightLatitude, + required double upperRightLongitude, + }) { + if (PigeonOverrides.geographicBounds_new != null) { + return PigeonOverrides.geographicBounds_new!( + lowerLeftLatitude: lowerLeftLatitude, + lowerLeftLongitude: lowerLeftLongitude, + upperRightLatitude: upperRightLatitude, + upperRightLongitude: upperRightLongitude, + ); + } + return GeographicBounds.pigeon_new( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + lowerLeftLatitude: lowerLeftLatitude, + lowerLeftLongitude: lowerLeftLongitude, + upperRightLatitude: upperRightLatitude, + upperRightLongitude: upperRightLongitude, + ); + } + + @protected + GeographicBounds.pigeon_new({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + required this.lowerLeftLatitude, + required this.lowerLeftLongitude, + required this.upperRightLatitude, + required this.upperRightLongitude, + }) { + final int pigeonVar_instanceIdentifier = pigeon_instanceManager + .addDartCreatedInstance(this); + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecGeographicBounds; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.geocoding_android.GeographicBounds.pigeon_defaultConstructor'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final Future pigeonVar_sendFuture = pigeonVar_channel + .send([ + pigeonVar_instanceIdentifier, + lowerLeftLatitude, + lowerLeftLongitude, + upperRightLatitude, + upperRightLongitude, + ]); + () async { + final List? pigeonVar_replyList = + await pigeonVar_sendFuture as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + }(); + } + + /// Constructs [GeographicBounds] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + GeographicBounds.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + required this.lowerLeftLatitude, + required this.lowerLeftLongitude, + required this.upperRightLatitude, + required this.upperRightLongitude, + }); + + late final _PigeonInternalProxyApiBaseCodec _pigeonVar_codecGeographicBounds = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + final double lowerLeftLatitude; + + final double lowerLeftLongitude; + + final double upperRightLatitude; + + final double upperRightLongitude; + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + GeographicBounds Function( + double lowerLeftLatitude, + double lowerLeftLongitude, + double upperRightLatitude, + double upperRightLongitude, + )? + pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance, + ); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel + pigeonVar_channel = BasicMessageChannel( + 'dev.flutter.pigeon.geocoding_android.GeographicBounds.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger, + ); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert( + message != null, + 'Argument for dev.flutter.pigeon.geocoding_android.GeographicBounds.pigeon_newInstance was null.', + ); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert( + arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.geocoding_android.GeographicBounds.pigeon_newInstance was null, expected non-null int.', + ); + final double? arg_lowerLeftLatitude = (args[1] as double?); + assert( + arg_lowerLeftLatitude != null, + 'Argument for dev.flutter.pigeon.geocoding_android.GeographicBounds.pigeon_newInstance was null, expected non-null double.', + ); + final double? arg_lowerLeftLongitude = (args[2] as double?); + assert( + arg_lowerLeftLongitude != null, + 'Argument for dev.flutter.pigeon.geocoding_android.GeographicBounds.pigeon_newInstance was null, expected non-null double.', + ); + final double? arg_upperRightLatitude = (args[3] as double?); + assert( + arg_upperRightLatitude != null, + 'Argument for dev.flutter.pigeon.geocoding_android.GeographicBounds.pigeon_newInstance was null, expected non-null double.', + ); + final double? arg_upperRightLongitude = (args[4] as double?); + assert( + arg_upperRightLongitude != null, + 'Argument for dev.flutter.pigeon.geocoding_android.GeographicBounds.pigeon_newInstance was null, expected non-null double.', + ); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call( + arg_lowerLeftLatitude!, + arg_lowerLeftLongitude!, + arg_upperRightLatitude!, + arg_upperRightLongitude!, + ) ?? + GeographicBounds.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + lowerLeftLatitude: arg_lowerLeftLatitude!, + lowerLeftLongitude: arg_lowerLeftLongitude!, + upperRightLatitude: arg_upperRightLatitude!, + upperRightLongitude: arg_upperRightLongitude!, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString()), + ); + } + }); + } + } + } + + @override + GeographicBounds pigeon_copy() { + return GeographicBounds.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + lowerLeftLatitude: lowerLeftLatitude, + lowerLeftLongitude: lowerLeftLongitude, + upperRightLatitude: upperRightLatitude, + upperRightLongitude: upperRightLongitude, + ); + } +} + /// A `Locale` object represents a specific geographical, political, or cultural /// region. /// diff --git a/geocoding_android/pigeons/geocoder.dart b/geocoding_android/pigeons/geocoder.dart index d713dd1..d0cef00 100644 --- a/geocoding_android/pigeons/geocoder.dart +++ b/geocoding_android/pigeons/geocoder.dart @@ -156,6 +156,7 @@ abstract class Geocoder { @Deprecated( 'This method was deprecated in Android API level 33. Use `getFromLocation` instead.', ) + @async List? getFromLocationPreAndroidApi33( double latitude, double longitude, @@ -190,6 +191,7 @@ abstract class Geocoder { @Deprecated( 'This method was deprecated in Android API level 33. Use `getFromLocationName` instead.', ) + @async List? getFromLocationNamePreAndroidApi33( String locationName, int maxResults, { diff --git a/geocoding_android/pubspec.yaml b/geocoding_android/pubspec.yaml index 57fcde1..7b14143 100644 --- a/geocoding_android/pubspec.yaml +++ b/geocoding_android/pubspec.yaml @@ -1,6 +1,6 @@ name: geocoding_android description: A Flutter Geocoding plugin which provides easy geocoding and reverse-geocoding features. -version: 5.1.0 +version: 5.1.1 repository: https://github.com/baseflow/flutter-geocoding/tree/main/geocoding_android issue_tracker: https://github.com/Baseflow/flutter-geocoding/issues