a14n / dart-google-maps

A library to use Google Maps JavaScript API v3 from Dart scripts.
Apache License 2.0
130 stars 66 forks source link

Futures instead of Callback functions #43

Closed Blackbam1337 closed 7 years ago

Blackbam1337 commented 7 years ago

In my opinion this library would be way more dart-alike if you would use Futures instead of callback functions.

Example of what I have to do:

  Future<LatLng> getLatLngFromString(String address) {
    var completer = new Completer<LatLng>();
    _geocoder.geocode(
        new GeocoderRequest()
          ..address = address,
        (results, status) => status == GeocoderStatus.OK
            ? completer.complete(results[0].geometry.location)
            : completer.completeError(
                'Geocode was not successful for the following reason: ' +
                    status.toString()));
    return completer.future;
  }

It would be better if Futures would be returned directly.

a14n commented 7 years ago

It's something I wanted to do at the start of the lib but:

  1. it was not obvious if/what status should be handle as error (re. Future). For instance see GeocoderStatus.
  2. it's more simple for someone looking at the google maps api for JS to produce a code that works.

This is something I'll change perhaps when I'll refactor the lib for Dart 2