Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

The operator '[]' isn't defined for the type 'Future<Map<String, dynamic>>'

I am getting this error and do not know how to solve it:

  var directions = LocationService().getDirections(
                  _originController.text, _destinationController.text);
             _goToPlace(directions['start_location']['lat'], directions['start_location']['lng']);
             setPolyline(directions['polyline_decoded']);
            },

Below is the code of the _goToPlace() method:

Future<void> _goToPlace(double lat, double lng) async {

    final GoogleMapController controller = await _controllerGoogleMap.future;
    controller.animateCamera(
      CameraUpdate.newCameraPosition(
        CameraPosition(
          target: LatLng(lat, lng),
          zoom: 12,
        ),
      ),
    );
  }

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Mark your function as async and put an await before your getDirections

await LocationService().getDirections(
                  _originController.text, _destinationController.text);

Your getDirections returns a Future, so you have await it.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading