diff --git a/android/src/main/java/com/aloisdeniel/geocoder/GeocoderPlugin.java b/android/src/main/java/com/aloisdeniel/geocoder/GeocoderPlugin.java index b119a7f..ddbfba9 100644 --- a/android/src/main/java/com/aloisdeniel/geocoder/GeocoderPlugin.java +++ b/android/src/main/java/com/aloisdeniel/geocoder/GeocoderPlugin.java @@ -65,33 +65,33 @@ private void assertPresent() throws NotAvailableException { } } + @SuppressLint("StaticFieldLeak") private void findAddressesFromQuery(final String address, final Result result) { final GeocoderPlugin plugin = this; - new AsyncTask() - { - @Override - protected Void doInBackground(Void... params) - { - try { - plugin.assertPresent(); - List
addresses = geocoder.getFromLocationName(address, 20); - result.success(createAddressMapList(addresses)); + new AsyncTask>() { + @Override + protected List
doInBackground(Void... params) { + try { + plugin.assertPresent(); + return geocoder.getFromLocation(latitude, longitude, 20); + } catch (IOException ex) { + return null; + } catch (NotAvailableException ex) { + return new ArrayList<>(); + } } - catch(IOException ex) { - result.error("failed", ex.toString(), null); - } - catch(NotAvailableException ex) { - result.error("not_available", ex.toString(), null); - } - return null; - } - @Override - protected void onPostExecute(Void result) - { - super.onPostExecute(result); - } + @Override + protected void onPostExecute(List
addresses) { + if (addresses != null) { + if (addresses.isEmpty()) + result.error("not_available", "Empty", null); + + else result.success(createAddressMapList(addresses)); + } + else result.error("failed", "Failed", null); + } }.execute(); } diff --git a/example/lib/main.dart b/example/lib/main.dart index 76604f3..967240c 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -3,7 +3,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:geocoder/geocoder.dart'; import 'package:geocoder/services/base.dart'; -import 'package:geocoder_example/widgets.dart'; +import 'widgets.dart'; void main() => runApp(new MyApp()); diff --git a/example/test/widget_test.dart b/example/test/widget_test.dart deleted file mode 100644 index 87cd68b..0000000 --- a/example/test/widget_test.dart +++ /dev/null @@ -1,29 +0,0 @@ -// This is a basic Flutter widget test. -// To perform an interaction with a widget in your test, use the WidgetTester utility that Flutter -// provides. For example, you can send tap and scroll gestures. You can also use WidgetTester to -// find child widgets in the widget tree, read text, and verify that the values of widget properties -// are correct. - -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'package:geocoder_example/main.dart'; - -void main() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { - // Build our app and trigger a frame. - await tester.pumpWidget(new MyApp()); - - // Verify that our counter starts at 0. - expect(find.text('0'), findsOneWidget); - expect(find.text('1'), findsNothing); - - // Tap the '+' icon and trigger a frame. - await tester.tap(find.byIcon(Icons.add)); - await tester.pump(); - - // Verify that our counter has incremented. - expect(find.text('0'), findsNothing); - expect(find.text('1'), findsOneWidget); - }); -} diff --git a/pubspec.yaml b/pubspec.yaml index 78b8c4d..f1ae6e0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,13 +1,14 @@ name: geocoder description: Forward and reverse geocoding. -version: 0.1.1 +version: 0.1.2 author: Aloïs Deniel homepage: https://github.com/aloisdeniel/flutter_geocoder environment: - sdk: ">=2.0.0-dev.40.0.flutter-f981f09760 <3.0.0" + sdk: ">=2.0.0 <3.0.0" dependencies: + meta: ^1.1.6 flutter: sdk: flutter