英文:
Instance of 'Future<dynamic>' not giving data to string flutter
问题
我正在尝试使用Flutter地理编码库从坐标获取城市名称,但它以“Instance of 'Future
我正在尝试解决这个问题。
英文:
I'm trying to get city name from coordinates using flutter geocoding library, but it give output in form of "Instance of 'Future<dynamic>'" instead of city name. Code in the screenshot. please help me here.
i'm trying to get solution from this issue.
答案1
得分: 0
例如,您可以像这样使用await
:
String cityName = await GeocodingPlatform.instance.placemarkFromCoordinates(latitude, longitude).then((value) => value.first.locality);
或者您可以像这样使用then
:
GeocodingPlatform.instance.placemarkFromCoordinates(latitude, longitude).then((value) {
String cityName = value.first.locality;
// 使用 cityName 进行其他操作
});
英文:
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
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论