Asynchronous 我如何在dart(flatter)中使用Future和.then()转换这个简单的异步等待格式的代码?
下面是我所说的代码片段:Asynchronous 我如何在dart(flatter)中使用Future和.then()转换这个简单的异步等待格式的代码?,asynchronous,flutter,dart,async-await,Asynchronous,Flutter,Dart,Async Await,下面是我所说的代码片段: void getlocation() async { Position position = await Geolocator() .getCurrentPosition(desiredAccuracy: LocationAccuracy.low); print(position); } 我需要根据Dart(颤振)中的未来编写此函数 提前感谢。版本的未来,然后是方法 -用于表示将来某个时间可用的潜在值或错误 Geolocator().getCu
void getlocation() async {
Position position = await Geolocator()
.getCurrentPosition(desiredAccuracy: LocationAccuracy.low);
print(position);
}
我需要根据Dart(颤振)中的未来编写此函数
提前感谢。版本的
未来,然后是方法
-用于表示将来某个时间可用的潜在值或错误
Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.best)
.then((Position position) {
print('Latitude : ${position.latitude}');
print('Longitude : ${position.longitude}');
}).catchError((err) {
print(err);
});
注意:如果希望程序等待异步函数完成,请使用等待
或使用然后
版本的未来,然后使用
方法
-用于表示将来某个时间可用的潜在值或错误
Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.best)
.then((Position position) {
print('Latitude : ${position.latitude}');
print('Longitude : ${position.longitude}');
}).catchError((err) {
print(err);
});
注意:如果希望程序等待异步函数完成,请使用等待
或使用然后
地理定位器().getCurrentPosition(desiredAccuracy:LocationAccurance.low)。然后(打印)但是实际上async
/wait
东西有什么问题?为什么您需要用Future.then()
转换这样简单的示例?我正在学习这两种方法。我在做实验,试着把一个转化成另一个。啊哈,祝你学习顺利;-)谢谢你,伙计。有很多东西要学:-)Geolocator().getCurrentPosition(期望精度:LocationAccuracy.low)。然后(打印)但是实际上async
/wait
东西有什么问题?为什么您需要用Future.then()
转换这样简单的示例?我正在学习这两种方法。我在做实验,试着把一个转化成另一个。啊哈,祝你学习顺利;-)谢谢你,伙计。有很多东西要学:-)