Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asynchronous 我如何在dart(flatter)中使用Future和.then()转换这个简单的异步等待格式的代码?_Asynchronous_Flutter_Dart_Async Await - Fatal编程技术网

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()
转换这样简单的示例?我正在学习这两种方法。我在做实验,试着把一个转化成另一个。啊哈,祝你学习顺利;-)谢谢你,伙计。有很多东西要学:-)