Skip to content

Commit

Permalink
Updated address result async task.
Browse files Browse the repository at this point in the history
  • Loading branch information
aloisdeniel committed Jul 17, 2019
1 parent 8c6a178 commit 44e9576
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 54 deletions.
44 changes: 22 additions & 22 deletions android/src/main/java/com/aloisdeniel/geocoder/GeocoderPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void, Void, Void>()
{
@Override
protected Void doInBackground(Void... params)
{
try {
plugin.assertPresent();
List<Address> addresses = geocoder.getFromLocationName(address, 20);
result.success(createAddressMapList(addresses));
new AsyncTask<Void, Void, List<Address>>() {
@Override
protected List<Address> 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<Address> 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();
}

Expand Down
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
29 changes: 0 additions & 29 deletions example/test/widget_test.dart

This file was deleted.

5 changes: 3 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
name: geocoder
description: Forward and reverse geocoding.
version: 0.1.1
version: 0.1.2
author: Aloïs Deniel<[email protected]>
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

Expand Down

0 comments on commit 44e9576

Please sign in to comment.