Flutter 颤振中的FutureBuilder-调用API并使用映射标记的响应

Flutter 颤振中的FutureBuilder-调用API并使用映射标记的响应,flutter,dart,maps,markers,Flutter,Dart,Maps,Markers,我正在调用一个API,并利用返回的Json数据在地图上张贴标记 我有一个单独的应用程序返回ListView罚款的调用 在我在地图应用程序中实现相关FutureBuilder代码之前,我收到了这个错误 type 'Future<Stations>' is not a subtype of type 'Iterable<dynamic>' api_manager.dart class MapMarkerExample{ void showAnchoredMa

我正在调用一个API,并利用返回的Json数据在地图上张贴标记

我有一个单独的应用程序返回ListView罚款的调用

在我在地图应用程序中实现相关FutureBuilder代码之前,我收到了这个错误

type 'Future<Stations>' is not a subtype of type 'Iterable<dynamic>'
api_manager.dart

class MapMarkerExample{
 
    
 void showAnchoredMapMarkers() {
  var stations;
 
        stations = API_Call().fetchStations(); 
       for (Station stations in stations) {
           GeoCoordinates geoCoordinates = GeoCoordinates (stations.place.location.lat, stations.place.location.lng);
         
           }

           GeoCoordinates geoCoordinates = stations.coordinates;
           _addPOIMapMarker(geoCoordinates, 1);
 
    }
...
api_call.dart

class API_Call {
  
Future<Stations> fetchStations() async {
    var client = http.Client();

      final response = await client.get(
      'https://transit.hereapi.com/v8/stations?in=x,-x&return=transport&apiKey=MY_API_KEY');
   
    if (response.statusCode == 200) {
    return Stations.fromJson(jsonDecode(response.body)); 
  } else {
    throw Exception('Failed to load stations');
  }
    }
    }
类API\u调用{
Future fetchStations()异步{
var client=http.client();
最终响应=等待client.get(
'https://transit.hereapi.com/v8/stations?in=x,-x&return=transport&apiKey=MY_API_KEY');
如果(response.statusCode==200){
返回站.fromJson(jsonDecode(response.body));
}否则{
抛出异常(“加载工作站失败”);
}
}
}

对于您眼前的语法问题,您忘记了一个
wait

stations = await API_Call().fetchStations(); 

但是,这会对您的代码产生连锁反应,因为现在该函数需要是
async
,并且可能需要在其他地方等待。

谢谢。我只是试着去实施,到处都是问题。http调用上的异步不是唯一需要的吗?不,事实上,异步是“传染性”的,一个带有await的异步调用的函数本身就是异步的。现在已经阅读并更好地理解了它!关于如何将我的FutureBuilder设置为main.dart上的返回空值,您有什么建议吗?
stations = await API_Call().fetchStations();