我如何在 flutter http 中使用带有变量的 get 方法?

How I use get method with variables in flutter http?

我想调用 API 但我不能将纬度和经度作为变量。

基本上您会希望在 getData 方法中定义您的 uri。 示例:

getData({String latitude,String longitude})async{
..define uri. var url =Uri.https..
http.Response..

正如 griffin 所说要在 getData 函数中写入 url,照此操作并在该函数中像这样提取和传递查询参数

void getData(double latitude,double longitude) async {
    Map<String, dynamic> param = {
          'longitude': longitude,
          'latitude': latitude,
        };

    var url = Uri.https('api/openweathermap.org',
        '/data/2.5/weather',
        param);
    
    }

创建一个函数而不是变量

Uri url(double latitude, double longitude) {
    return Uri.https('api.abc.org', 'data/123/abc', {
      'lat': latitude,
      'lon': longitude,
    });
  }

Future<void> getData(double latitude, double longitude) async {
  final response = await http.get(url(latitude, longitude));
}