Search code examples
fluttergoogle-mapserror-handlingsyntax-errorgeocoding

Instance of 'Future<dynamic>' not giving data to string flutter


I'm trying to get city name from coordinates using flutter geocoding library, but it give output in form of "Instance of 'Future'" instead of city name. Code in the screenshot. please help me here.

Screenshot with code

i'm trying to get solution from this issue.


Solution

  • For example, you can use await like this:

    String cityName = await GeocodingPlatform.instance.placemarkFromCoordinates(latitude, longitude).then((value) => value.first.locality);
    

    Or you can use then like this:

    GeocodingPlatform.instance.placemarkFromCoordinates(latitude, longitude).then((value) {
      String cityName = value.first.locality;
      // do something with cityName
    });