2021年1月28日星期四

Error: 'await' can only be used in 'async' or 'async*' methods

I am trying to add distance from user to the Location object, but this requires using an asynchronous call that I can't figure out where and how to do exactly. From there I will sort Locations by distance from user. I tried the code below bc it's where the sorted locations would be used, but I get an error saying "await" can only be used in "async" or "async*" methods even though it is being used with an async function. How do I add distance from user to a Location object given it requires an asynchronous call?

class MapWidget extends StatefulWidget {    ...    @override      _MapWidgetState createState() => _MapWidgetState();  }    class _MapWidgetState extends       State<MapWidget> {        Future <List<Location>> sortLocations() async {           return null;//function not done     }      @override    Widget build(BuildContext context) {      final List<Location> sortedLocations = await sortLocations();  ...  
https://stackoverflow.com/questions/65944597/error-await-can-only-be-used-in-async-or-async-methods January 29, 2021 at 04:17AM

没有评论:

发表评论