【发布时间】:2020-12-07 03:11:54
【问题描述】:
我正在使用颤振制作应用程序。
我正在尝试使用地理定位器库将位置值保存到变量中,但由于以下错误,我无法打印该值。
请看下面的代码,告诉我如何将返回位置值保存在变量中。谢谢。
/* Convert to location using Geolocator */
Future<Position> _getLocation() async {
return Geolocator()
.getCurrentPosition(desiredAccuracy: LocationAccuracy.low)
.then((location) {
return location;
});
}
/* run app */
@override
Widget build(BuildContext context) {
_getUser();
print(_getLocation());
- omit below -
/* =============================== */
/* Output value when the app runs */
/* Instance of 'Future<Position>' */
/* =============================== */
【问题讨论】:
-
欢迎来到 StackOverflow!您正在尝试打印承诺而不是位置。你试过
print(await _getLocation());吗?