Skip to content

Commit b5f2483

Browse files
authored
fixes Baseflow#58: made work in a separate thread (Baseflow#103)
* fixes Baseflow#58: made work in a separate thread * chore: updated changelog.md to reflect changes * chore: updated version on pubspec.yaml * chore: updated version on pubspec.yaml * chore: removed unused line * feat: added addressLine * Revert "feat: added addressLine" This reverts commit 80590f2. * chore: code formatting and review changes * chore: revert java.home path * chore: used taskQueue * chore: fixed reviews
1 parent b3399a2 commit b5f2483

File tree

6 files changed

+26
-15
lines changed

6 files changed

+26
-15
lines changed

geocoding/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.0.5
2+
3+
- Fixed [#58](https://github.com/Baseflow/flutter-geocoding/issues/58) getting locationFromAddress freezes main thread.
4+
15
## 2.0.4
26

37
- Fixes link to the Android migration guide in README.

geocoding/android/.classpath

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
3-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-14/"/>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-18/"/>
44
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
55
<classpathentry kind="output" path="bin/default"/>
66
</classpath>

geocoding/android/.settings/org.eclipse.buildship.core.prefs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
arguments=
22
auto.sync=false
33
build.scans.enabled=false
4-
connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.3))
4+
connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(7.1.1))
55
connection.project.dir=
66
eclipse.preferences.version=1
77
gradle.user.home=

geocoding/android/build.gradle

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88
}
99

1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:3.5.0'
11+
classpath 'com.android.tools.build:gradle:4.2.2'
1212
}
1313
}
1414

@@ -31,3 +31,7 @@ android {
3131
disable 'InvalidPackage'
3232
}
3333
}
34+
35+
dependencies {
36+
implementation 'androidx.annotation:annotation:1.4.0'
37+
}

geocoding/android/src/main/java/com/baseflow/geocoding/MethodCallHandlerImpl.java

+14-11
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22

33
import android.location.Address;
44
import android.util.Log;
5+
56
import androidx.annotation.Nullable;
67

78
import com.baseflow.geocoding.utils.AddressMapper;
89
import com.baseflow.geocoding.utils.LocaleConverter;
910

11+
import java.io.IOException;
12+
import java.util.List;
13+
1014
import io.flutter.plugin.common.BinaryMessenger;
1115
import io.flutter.plugin.common.MethodCall;
1216
import io.flutter.plugin.common.MethodChannel;
1317
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
1418
import io.flutter.plugin.common.MethodChannel.Result;
15-
16-
import java.io.IOException;
17-
import java.util.List;
19+
import io.flutter.plugin.common.StandardMethodCodec;
1820

1921
/**
2022
* Translates incoming Geocoding MethodCalls into well formed Java function calls for {@link
@@ -23,15 +25,18 @@
2325
final class MethodCallHandlerImpl implements MethodCallHandler {
2426
private static final String TAG = "MethodCallHandlerImpl";
2527
private final Geocoding geocoding;
26-
@Nullable private MethodChannel channel;
28+
@Nullable
29+
private MethodChannel channel;
2730

28-
/** Forwards all incoming MethodChannel calls to the given {@code geocoding}. */
31+
/**
32+
* Forwards all incoming MethodChannel calls to the given {@code geocoding}.
33+
*/
2934
MethodCallHandlerImpl(Geocoding geocoding) {
3035
this.geocoding = geocoding;
3136
}
3237

3338
@Override
34-
public void onMethodCall(MethodCall call, Result result) {
39+
public void onMethodCall(final MethodCall call, final Result result) {
3540
switch (call.method) {
3641
case "locationFromAddress":
3742
onLocationFromAddress(call, result);
@@ -57,8 +62,8 @@ void startListening(BinaryMessenger messenger) {
5762
Log.wtf(TAG, "Setting a method call handler before the last was disposed.");
5863
stopListening();
5964
}
60-
61-
channel = new MethodChannel(messenger, "flutter.baseflow.com/geocoding");
65+
final BinaryMessenger.TaskQueue taskQueue = messenger.makeBackgroundTaskQueue();
66+
channel = new MethodChannel(messenger, "flutter.baseflow.com/geocoding", StandardMethodCodec.INSTANCE, taskQueue);
6267
channel.setMethodCallHandler(this);
6368
}
6469

@@ -111,7 +116,7 @@ private void onLocationFromAddress(MethodCall call, Result result) {
111116
}
112117
}
113118

114-
private void onPlacemarkFromCoordinates(MethodCall call, Result result) {
119+
private void onPlacemarkFromCoordinates(final MethodCall call, final Result result) {
115120
final double latitude = call.argument("latitude");
116121
final double longitude = call.argument("longitude");
117122
final String languageTag = call.argument("localeIdentifier");
@@ -121,15 +126,13 @@ private void onPlacemarkFromCoordinates(MethodCall call, Result result) {
121126
latitude,
122127
longitude,
123128
LocaleConverter.fromLanguageTag(languageTag));
124-
125129
if (addresses == null || addresses.isEmpty()) {
126130
result.error(
127131
"NOT_FOUND",
128132
String.format("No address information found for supplied coordinates (latitude: %f, longitude: %f).", latitude, longitude),
129133
null);
130134
return;
131135
}
132-
133136
result.success(AddressMapper.toAddressHashMapList(addresses));
134137
} catch (IOException ex) {
135138
result.error(

geocoding/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: geocoding
22
description: A Flutter Geocoding plugin which provides easy geocoding and reverse-geocoding features.
3-
version: 2.0.4
3+
version: 2.0.5
44
homepage: https://github.com/baseflow/flutter-geocoding/tree/master/geocoding
55

66
environment:

0 commit comments

Comments
 (0)