此方法不返回任何数据
Future getProposals(String address,String id) async { await _getProposals(address,id); }
更改为
Future getProposals(String address,String id) { return _getProposals(address,id); }
这也将工作,但在这里async和await是redunant
Future getProposals(String address,String id) async { return await _getProposals(address,id); }
对于_getProposals你可以使用Completer
```
Future _getProposals(String address,String id) async {
if(address != “”) {
Completer completer = new Completer();
autocompleteService.getPlacePredictions( new AutocompletionRequest() ..input = address , (predictions,status) { List<String> result = []; if(status == PlacesServiceStatus.OK) { predictions.forEach( (AutocompletePrediction prediction) => result.add(prediction.description) ); } // HERE is the problem: How do I return this result from the callback as a result of the getProposals method? completer.complete(result); } ); return completer.future;}return null;
}
```
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)