【问题标题】:Problem with openWeatherMap API in flutterFlutter中openWeatherMap API的问题
【发布时间】:2022-08-06 01:18:34
【问题描述】:

我有一个问题,我不知道它是否在 API 的订阅中,但它只在我的应用程序中工作一次,当我关闭我的项目并再次重新打开它时,它不会获取任何数据.尽管在关闭项目并再次重新打开它之前它工作得很好。我尝试了 post() 而不是 get() ,但它仍然不起作用。问题是什么?

  • 分享你的代码。
  • import \'dart:convert\'; import \'package:http/http.dart\' as http; import \'package:weatherly/models/weather_model.dart\'; class WeatherApiClient{ Future<Weather?> getCurrentWeather(String? location) async{ var endPoint = Uri.parse(\'https://api.openweathermap.org/data/2.5/weather?q=$location&appid=82ce0fb9f3a113ade7e13e201316c934&units=metric\'); var response = await http.get(endPoint); var body = jsonDecode(response.body); Weather weather = Weather.fromJson(body); print(Weather.fromJson(body).cityName); return weather; } }
  • 问题不在代码中,因为在我关闭项目之前它工作正常
  • 你如何将位置传递给这个api?
  • ``` WeatherApiClient 客户端 = WeatherApiClient();天气?数据 = 天气(); @override void initState() { super.initState(); client.getCurrentWeather(\"开罗\"); } Future<void> getData()async{ data = await client.getCurrentWeather(\"Cairo\"); }```

标签: flutter api android-studio dart openweathermap


【解决方案1】:

我更新了 android studio,现在可以正常工作了

【讨论】:

    猜你喜欢
    • 2017-04-02
    • 2016-06-22
    • 2017-12-05
    • 1970-01-01
    • 2018-10-05
    • 1970-01-01
    • 2020-03-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多